The dreaded charley horse: No one really knows how it got its name, but up to 60% of adults experience the occasional nocturnal leg cramp, which can feel like a painful spasm, tightening, or twinge.  

Charley horses develop when the nerves that carry signals to your muscles fire off too many messages at once. This causes your muscles to contract in an uncomfortable way, says Scott Garrison, MD, PhD, director of the department of family medicine at the University of Alberta.

Sitting or lying down for a long time—like when you're sleeping—can trigger the nerve malfunction. That's why you tend to get cramps in the middle of the night.

MORE: 7 Crazy Things That Happen When You Sleep

And weirdly, charley horses are more common in warmer months, according to a new study from Garrison and his team.

It might be because you have higher levels of vitamin D in the summer, thanks to increased sun exposure. The nutrient plays a role in regulating the growth and repair of your muscle fibers, says Garrison. But more growth and repair may also send the muscle mechanism behind your cramps into overdrive, he says.

Charley horses become more common—and painful—as you age, says Garrison. After you hit 50, you start losing more of the nerve cells that send messages from your brain to your muscles. The cells that are left have to work harder, which experts speculate might cause cramping.  

(For more fitness, nutrition, health, and sex secrets to keep you fit, strong, and sharp for life, check out The Better Man Project.)

Fortunately, the spasms are usually harmless. But in rare cases, they can signal electrolyte imbalance or neuromuscular disorders like amyotrophic lateral sclerosis (ALS), known as Lou Gehrig's disease.

Stretching your calves, hamstrings, and quads before bed will stop cramps before they start. In fact, a 2012 study from the Netherlands found that older adults who suffered from charley horses experienced fewer, less severe spasms when they stretched their legs for 3 minutes prior to hitting the sack.

Target these areas with The Best Stretch for Every Body Part.

If a spasm does strike in the middle of the night, ease the pain by using the same stretches.

Your usual first line of defense—hopping out of bed and walking around for a minute—will help relieve tightness, too.

The article How to Stop a Charley Horse in the Middle of the Night originally ran on MensHealth.com.

Headshot of Marygrace Taylor for MensHealth.com
Marygrace Taylor for MensHealth.com
Marygrace Taylor is a health and wellness writer for Prevention, Parade, Women’s Health, Redbook, and others. She’s also the co-author of Prevention’s Eat Clean, Stay Lean: The Diet and Prevention’s Mediterranean Kitchen. Visit her at marygracetaylor.com.