The sight of your pup furiously digging away in your bed before he lays down can be a hilarious sight. If you asked him why he does this seemingly pointless behavior, he probably wouldn't be able to give you a reason, even if he could talk. The answers are rooted deep in the primal instincts of his wild ancestors that existed long before canine partnership with humankind.
Back to Nature
Wild dogs spend their sleeping hours protected from the elements in a den or other sheltered area. The canids typically scratch a shallow hole in the ground to rest their bodies in for comfort. Slipping into a shallow hole can help keep a dog's legs warmer in the winter, and summer holes are commonly dug in mud or damp leaf litter to help the animal cool down. When your pup goes to town scratching on your bed, he's instinctively preparing a comfortable place to lay, much like you might plump your pillows or straighten blankets before you lay down.