How to Get Rid of Leg Cramps at Night: Causes & Prevention

Nighttime leg cramps can usually be stopped within seconds by stretching the affected muscle, and prevented long-term with a few simple habits before bed. Most nocturnal cramps hit the calf, though they can also strike the thigh or foot. They’re extremely common, especially after age 50, and the majority are harmless, even if they’re painful enough to jolt you awake.

How to Stop a Cramp in the Moment

When a cramp seizes your calf in the middle of the night, your instinct is to tense up or grab the muscle. Instead, do the opposite: stretch it. Flex your foot by pulling your toes toward your shin. You can do this by reaching down and pulling your foot back with your hand, or by standing up and pressing the ball of your foot firmly into the floor. Hold the stretch for 20 to 30 seconds, release, and repeat if the cramp hasn’t fully let go.

If the cramp is in your thigh, straighten the leg and pull your ankle toward your backside to stretch the front of the thigh, or sit at the edge of the bed and extend the leg straight to stretch the hamstring. Walking around for a minute or two after the cramp subsides helps the muscle relax completely. Applying a warm towel or heating pad to the cramped muscle can also ease the residual soreness that sometimes lingers into the next day. Ice works too, particularly if the muscle still feels tight after stretching.

Why Cramps Happen at Night

The short answer is that no one is entirely sure. The leading theory involves nerve hyperactivity: motor neurons that control the lower leg fire spontaneously, causing the muscle to contract violently without any signal from you. This is more likely to happen when a muscle is already shortened, which is exactly the position your calf sits in while you sleep. When your foot naturally points downward under the weight of blankets, the calf muscle shortens and becomes more susceptible to involuntary contractions.

Several factors raise the odds. Muscle fatigue from an unusually active day, prolonged standing, or a new exercise routine can prime your legs for cramps later that night. Dehydration plays a role, particularly if you sweat heavily during the day and don’t replace fluids before bed. Age is the strongest risk factor: the tendons connecting muscles to bones shorten naturally over the years, which may explain why cramps become more frequent in middle age and beyond.

Preventing Cramps Before Bed

A brief stretching routine before you get under the covers is one of the most consistently recommended prevention strategies. The classic calf stretch, where you stand facing a wall with one foot behind you and press the rear heel into the floor while leaning forward, targets the muscle most prone to nighttime cramps. Hold for 30 seconds on each side and repeat two or three times. Riding a stationary bike for just a few minutes before bed can also help by gently working the leg muscles and improving blood flow without fatiguing them.

Keep your sheets and blankets loose at the foot of the bed. Tightly tucked covers push your feet into a pointed position for hours, which shortens the calf. Untucking the bottom of your sheets or sleeping with your feet hanging slightly off the mattress gives your ankles room to stay in a neutral position.

Stay hydrated throughout the day, not just at dinner. If you’re someone who limits fluids in the evening to avoid bathroom trips, try to front-load your water intake earlier. Electrolytes matter too: potassium, magnesium, and calcium all play roles in normal muscle contraction. Eating foods rich in these minerals (bananas, leafy greens, dairy, beans, sweet potatoes) is a more reliable approach than supplementation for most people.

Does Magnesium Actually Help?

Magnesium is probably the most popular supplement people try for leg cramps, but the clinical evidence is surprisingly weak. A 2020 systematic review of 11 randomized controlled trials involving 735 patients found no reduction in leg cramps from magnesium supplementation. For people with cramps of unknown cause, there was no meaningful difference between magnesium and placebo in the number of cramps per week after four weeks of treatment.

A separate 2021 trial tested 226 mg of magnesium oxide daily in patients 45 and older who experienced at least four cramp episodes per week. After 30 days, the magnesium group dropped from 5.4 cramps per week to 3.2, but the placebo group showed a nearly identical improvement, going from 6.4 to 3.6. The difference was not statistically significant. Pregnant patients fared no better: a meta-analysis of four trials found no difference between magnesium and placebo.

This doesn’t mean magnesium is useless for every individual, but the evidence doesn’t support it as a reliable treatment for most people. If you’re deficient in magnesium, correcting that deficiency can certainly help. But taking extra magnesium on top of adequate levels is unlikely to change your cramp frequency.

B Vitamins: A Lesser-Known Option

One small but notable study found that a vitamin B complex supplement (including 30 mg per day of vitamin B6) produced remission of muscle cramps in 86% of treated patients compared to placebo. These patients were not known to be vitamin B deficient, which makes the finding more interesting. The study was small, with only 28 participants, so it’s not definitive, but it’s one of the more promising results in a field where most supplements underperform.

Medications That Can Cause Cramps

If your nighttime cramps started or worsened around the time you began a new medication, the drug itself could be the trigger. Several common prescription and over-the-counter medications list leg cramps as a side effect. Diuretics (water pills) are among the most well-known culprits because they alter your body’s fluid and electrolyte balance. Statins, used widely for cholesterol, are another frequent offender. Certain antidepressants, sleep medications, anti-seizure drugs, and even some pain relievers have been linked to cramps at rates ranging from less than 1% to as high as 14% of patients.

If you suspect a medication is contributing to your cramps, bring it up with whoever prescribed it. Sometimes adjusting the dose or switching to an alternative in the same class can make a real difference.

Why Quinine Is Not the Answer

Quinine, the compound found in tonic water, was once widely prescribed for leg cramps. It does have some muscle-relaxing properties, but the FDA has made it clear that quinine is not considered safe or effective for cramps. It’s approved only for treating malaria. The risks include a dangerous drop in platelet counts, life-threatening allergic reactions, and heart rhythm problems. Fatalities and kidney failure requiring dialysis have been reported. Since 2006, the FDA has added a boxed warning (the most serious type) to quinine labeling specifically about these risks when the drug is used off-label for cramps. The small amount of quinine in a glass of tonic water isn’t dangerous, but it’s also not enough to treat cramps meaningfully.

When Leg Pain Isn’t Just a Cramp

Most nighttime leg cramps are benign and resolve on their own. But leg pain that doesn’t follow the typical cramp pattern deserves attention. A deep vein thrombosis (DVT), or blood clot in a leg vein, can cause pain, cramping, or soreness that often starts in the calf. The key differences: DVT pain tends to be persistent rather than sudden and brief, and it’s usually accompanied by swelling, warmth in the affected area, or a change in skin color (redness or a purplish hue). DVT can also occur without noticeable symptoms, which is why unexplained, one-sided leg swelling warrants prompt evaluation.

Cramps that happen many times per week, don’t respond to stretching, or come with muscle weakness or numbness could point to nerve issues, circulatory problems, or an underlying metabolic condition. Frequent severe cramps that disrupt your sleep consistently are worth discussing with a healthcare provider, especially if the basic prevention strategies aren’t making a dent.