Waking up in the middle of the night to discover one of your arms has lost all feeling is frightening.

At first, the limb is limp and flops around like a useless bag of bone before coming back to life with a flood of "pins and needles" sensations.

When this happened to me as a kid, I panicked, thinking I'd done something horrible to my body, anxious that I'd never be able to move my arm again. But the feeling in my arm always came back.

This phenomenon is really common, James Dyck, a neurology researcher with the Mayo Clinic, told me in 2016. And it's actually a cool example of how the body can protect itself even during the paralysis of sleep.

Dyck explained there's a common misconception that pins and needles and numbness are caused by a lack of blood flow to the nerves. "The more likely thing is nerve compression — nerves are being pushed on and squashed, and that causes these symptoms," he says. (It’s also true that numbness in the arm can also be a symptom of something more serious, like a heart attack.)

You have several nerves in your arm. Each serves a vital function.

The axillary nerve lifts the arm at the shoulder.

The musculocutaneous nerve bends the elbow.

The radial nerve straightens out the arm and lifts your wrist and fingers.

The ulnar nerve spreads your fingers.

Although Dyck says the exact physiology isn't completely understood, the effect of compressing any of these nerves in sleep — when you sleep on top of your arm or pin it underneath a partner — is like stepping on a garden hose. The information that flows from your extremities back to your brain is temporarily disrupted.

So why does it feel paralyzed upon waking?

Dyck suggests two reasons.

1) It is actually, temporarily, paralyzed. During REM sleep, the brain sends a signal to cause a body-wide paralysis. The purpose of this is to keep you from acting out dreams (which occur during REM). But if you wake up during one of these phases, you can be conscious before your fully regain control of your limbs. This is called sleep paralysis, and it can be a frightening situation. You're stuck somewhere in between dreaming and wakefulness, and you can't move.

2) The nerve compression has led to a temporary paralysis (perhaps because you got stuck in a compressed position during REM).

Compressing nerves can damage them. The good thing is that the body will naturally wake up as a protection mechanism when a nerve has been compressed too long. After you wake and relieve the pressure, the nerves will quickly come back online, usually first with a pins-and-needles feeling.

"The nerve structures, as they recover, tend to be irritable for a period of time," the University of Rochester Medical Center explains. "That’s because the nerves are firing spontaneously. Most of the time, the feeling of pins and needles is a good sign. It is a temporary phase that means nerves are coming back to life."

Someone who falls asleep on a limb is unlikely to do major damage to the nerves, Dyck says. But there are some cases when compressed nerves can become a greater problem.

One such case is called "Saturday night palsy," when a person falls asleep compressing a nerve while drunk. The alcohol impairs your body's ability to wake you up and protect your nerves.

"If you’re passed out drunk, you won’t move your arm," Dyck says. And when you wake up the next day, you can't extend your wrist and you can’t extend your fingers." That might last longer than a few moments (perhaps even a few days or months) as the nerve has to repair its protective coating.

And then there's hereditary neuropathy with liability to pressure palsies (HNPP), a genetic condition that makes people more susceptible to nerve compression injuries. They might want to be extra careful not to fall asleep on a limb or even cross their leg to avoid nerve compression. (Carpal tunnel may also cause tingling or numbness in limbs at night.)

Again, for most people who wake up to a dead limb, it's just a temporary annoyance. And it "probably takes less time [to recover] than you think it does, because you’re freaking out about it," Dyck says.

Late sleeper? Blame your genes.