There are actually a few theories on why dogs turn around three times before sleeping, including genetics, instinct, and general comfort. Like many other domesticated animals, dogs still retain many of the traits found in their undomesticated ancestors. In fact, modern dogs are believe to be 99% identical genetically to their common ancestor, the wild wolf. Wolves living in packs exhibit many of the same behaviors observed by owners of domestic dogs.
One reason dogs turn around three times before bedding down is because that's what feels right instinctively. Ancestral wolves traveled in packs for a number of reasons, primarily to hunt animals larger than any one wolf could kill on his own. When pack animals lie down to rest, they instinctively form a tight circle to take advantage of their neighbor's body heat. Perhaps dogs perform a similar action today because the practice has become ingrained after thousands of years. When wild packs of dogs do this in the wild, they may be establishing their territory and orienting themselves within the circle.
Another reason some experts believe dogs walk around before lying down is to trample down the area for comfort. A pack of wild dogs may decide to bed down on a grassy field, for instance, so the individual dogs turn around to force the tall grasses down. This may also expose any hazards or obstructions. This trampling behavior is often observed in domesticated dogs who use padded dog beds or sleep outdoors routinely.
Some suggest that the action is performed for a different form of comfort. Wolves have been observed digging up the ground as they prepare their bedding sites in the wild. This behavior is more often observed during hot weather, so some have theorized that the wolves are exposing a cooler layer of dirt to gain relief from the heat. Domestic dogs, especially larger breeds kept outdoors, may also be duplicating this behavior in an effort to cool down during hot weather.
Check out Pettable’s blog for more resources on pet care.