The sight of a dog batting its tiny paws around while sleeping is irrefutably adorable, and it’s not hard to imagine that your beloved pet is dreaming of swimming, fetching a Frisbee, or bounding around the yard in pursuit of a scampering squirrel.

In truth, that’s pretty much exactly what’s going on. Dogs, like humans, dream during the REM cycle of sleep, and their twitches are responses to whatever’s happening in those dreams. Though all dogs can exhibit muscle movements while dreaming, PetMD reports that it most often affects younger and older dogs. This is because of the pons, a part of the brainstem with two “off” switches that regulate movement during the sleep cycle.

“If either or both of these ‘off’ switches is not fully developed or has grown weak due to the aging process, then the muscles are not completely turned off and during dreaming, the animal will start to move,” Stanley Coren, a neuropsychological researcher and former psychology professor at the University of British Columbia, told PetMD. “How much movement occurs depends upon how effective or ineffective these ‘off’ switches are.”

As long as your dog looks like it’s having a grand old time in its dreams, you can sit back and enjoy the show. If you think your dog might be having a nightmare, be careful about waking it up. As the American Kennel Club (AKC) explains, a dog woken abruptly from a bad dream might bite you before it realizes its distress wasn’t real.

You should, however, learn to recognize the difference between a normal dream and a seizure.

“Some [dogs] manifest dreaming with twitching, paddling, or kicks of the legs. These movements are often brief (less than 30 seconds) and intermittent,” Jerry Klein, the AKC’s chief veterinary officer, described on the AKC website. “Seizing dogs’ limbs, on the other hand, tend to be rigid and stiffer, with more violent movement.”

The seizure can also be accompanied by loss of bowel control. If that description sounds familiar, you should talk to your veterinarian.

[h/t PetMD]