Nighttime leg cramps can usually be stopped within seconds by stretching the affected muscle, and future episodes can be reduced with a few simple habits before bed. Most nocturnal cramps hit the calf, last anywhere from a few seconds to several minutes, and leave behind a sore feeling that can linger into the next day. The good news is that they’re almost always harmless, even though they can be intensely painful in the moment.
How to Stop a Cramp While It’s Happening
When a cramp seizes your calf in the middle of the night, your instinct might be to tense up or grab the muscle. Instead, work against the contraction by stretching it out. Straighten your leg, then pull your toes back toward your shin. If you can reach your foot, gently pull the toes toward you and hold. This forces the cramping muscle to lengthen, which helps it release.
If the cramp is in your thigh rather than your calf, bend your knee and pull your foot up toward your buttock, using a wall or chair for balance. For either location, standing up and pressing your feet flat against the floor can break the spasm quickly. Walking around on your heels for a minute also helps by actively engaging the muscles opposite the ones that are cramping.
Once the cramp passes, apply a warm towel or heating pad to the area to relax any remaining tightness. Some people prefer ice if the muscle feels bruised afterward. Gently massaging the spot can ease the residual soreness that often lingers into the morning.
What Actually Causes Them
Despite what you may have heard, nighttime leg cramps are probably not caused by dehydration or low electrolytes. A review from the American Academy of Family Physicians found that neither nocturnal cramps nor exercise-related cramps have been associated with dehydration or disturbances in potassium, sodium, or magnesium levels. A separate study of patients with liver cirrhosis found no relationship between cramps and levels of calcium, magnesium, potassium, sodium, zinc, or glucose.
The current thinking is that muscle fatigue and nerve dysfunction are the more likely culprits. Your nerves can misfire during sleep, sending signals that cause a muscle to contract involuntarily. This is more common in older adults, during pregnancy, and after prolonged sitting or standing. Sleeping with your feet pointed downward (a natural position when you’re on your back under heavy blankets) keeps the calf in a shortened position, which may make spontaneous contractions more likely.
Certain medications are commonly blamed, particularly water pills like hydrochlorothiazide, but evidence-based reviews have not confirmed that link either. That said, if your cramps started or worsened around the time you began a new medication, it’s worth mentioning to your prescriber.
Preventing Cramps Before Bed
A short stretching routine before sleep is the most consistently recommended prevention strategy. Focus on your calves: stand about arm’s length from a wall, place your palms flat against it, and step one foot back while keeping that heel on the ground. Lean forward until you feel a stretch in the back calf. Hold for 20 to 30 seconds, then switch legs. Repeating this two or three times on each side takes less than five minutes.
Beyond stretching, a few adjustments to your sleep setup can help. Loosen your sheets and blankets at the foot of the bed so they don’t push your feet into a pointed position. If you sleep on your back, try propping a pillow under your calves or letting your feet hang slightly off the edge of the mattress to keep them in a more neutral angle. Light activity during the day, like walking, helps keep your leg muscles conditioned without overloading them.
Do Supplements Actually Help?
Magnesium supplements are one of the most popular home remedies for leg cramps, but the evidence is not encouraging. A Cochrane review, the gold standard of medical evidence summaries, analyzed 11 clinical trials involving 735 people and concluded that magnesium is unlikely to provide meaningful cramp prevention for the general adult population. Across those studies, magnesium showed no significant difference from placebo in cramp frequency, intensity, or duration at four weeks. The picture is slightly less clear for pregnancy-related cramps, where the evidence is conflicting.
Potassium and calcium supplements have also been studied, and no evidence supports their routine use for cramp prevention. Routine blood tests for electrolyte levels are considered unnecessary for diagnosing nocturnal leg cramps, since no consistent association has been found.
One lesser-known option is vitamin B complex. A small clinical trial found that a daily B complex supplement (containing 30 mg of vitamin B6) led to cramp remission in 86% of treated patients compared to placebo. The study was small, with only 28 participants, so the evidence is considered limited. A review published in the journal Neurology classified vitamin B complex as something that “may be considered” for cramp treatment, a modest endorsement. Side effects were minimal and no different from placebo.
Why Quinine Is Not Worth the Risk
Quinine, found in tonic water and available by prescription, was once widely used for nighttime leg cramps. The FDA has made clear that quinine is not considered safe or effective for this purpose. It is only approved for treating a specific type of malaria.
The risks are serious. Quinine is associated with life-threatening drops in platelet count, dangerous heart rhythm changes, severe allergic reactions, and kidney failure requiring dialysis. Fatalities have been reported. Since 2006, the FDA has issued multiple warnings, added a boxed warning to the drug’s label, and worked to educate prescribers about these dangers. If someone has suggested quinine or tonic water for your cramps, the potential harm far outweighs any possible benefit.
Leg Cramps vs. Restless Legs Syndrome
People sometimes confuse nighttime leg cramps with restless legs syndrome because both happen at rest and disrupt sleep, but they feel quite different. A leg cramp is a sudden, painful, involuntary contraction. You can usually feel the muscle knotted under the skin, and it resolves once the muscle releases. Restless legs syndrome, by contrast, involves an uncomfortable urge to move your legs rather than a painful contraction. The sensation is more of a crawling, pulling, or aching feeling that improves with movement but returns when you’re still again.
If your nighttime leg discomfort is more restless than painful, more urge-to-move than muscle-seizing, you may be dealing with restless legs syndrome, which has a different set of treatments. Cramps that are genuinely painful, sudden, and involve a visibly tight muscle are classic nocturnal leg cramps and respond best to the stretching and prevention strategies above.

