Why do dogs wag their tails in a circle & when sleeping ?

I’m not a pet person but I must confess I have had the fun of my life since I got my little johnny. He is so beautiful when I come back from work, what makes me happy most is when he wags his little tail after I opens the door everyday.

I wonder why do dogs wag their tails in circle and when they’re sleeping?