Dogs shake or kick their legs when you scratch them because of something known as the scratch reflex. It's a completely involuntary reaction, which explains why your dog may look as puzzled as you do when it starts to happen.

When you scratch or tickle your dog's belly, it irritates him, much the same way that the wind or a bug might. It activates nerves under his skin that are connected to his spinal cord and relays a message to his leg muscles to kick in an attempt to get rid of the irritant. Of course, you're the one both providing the "itch" and "scratching" it, so it's a completely pointless act.

More Info: www.animalplanet.com