By clicking on the product links in this article, Mattressnut may receive a commission fee to support our work. See our affiliate disclosure.

Leg Cramps at Night: Causes, Instant Relief, and Prevention

Our Top Pick: Saatva Classic

Check Price & Reviews →

Nocturnal leg cramps — those sudden, painful muscle contractions that wake you at 2 a.m. — affect roughly 60% of adults at some point. They’re most common in the calf, but can strike the foot or thigh. The good news: most cases are preventable once you identify the trigger.

What Are Nocturnal Leg Cramps?

A leg cramp is an involuntary, sustained contraction of a muscle lasting anywhere from a few seconds to several minutes. Unlike restless legs syndrome (which involves an urge to move without pain), leg cramps are acutely painful and often leave soreness the next day.

They peak during the night because muscle circulation slows, electrolyte balance shifts, and any tension built up during the day has nowhere to release.

7 Common Causes

1. Dehydration

Even mild dehydration (1–2% body weight) disrupts the sodium-potassium pump in muscle cells. Drink at least 2–2.5 L of water daily, and more if you exercise heavily or live in a warm climate.

2. Magnesium Deficiency

Magnesium regulates nerve signals to muscle tissue. Low levels — common in people who consume processed food or take diuretics — increase cramping frequency. Leafy greens, nuts, and seeds are the easiest dietary sources.

3. Potassium and Calcium Imbalance

Both electrolytes are critical for proper muscle contraction and relaxation. Bananas, sweet potatoes, and dairy help maintain balance. Strenuous exercise depletes these faster than a normal sedentary day.

4. Prolonged Sitting or Standing

Sitting with legs crossed or standing on hard floors for hours shortens the calf muscles and compresses circulation. Short walking breaks every 45–60 minutes help prevent this.

5. Poor Sleep Position and Mattress Support

A mattress that sags or is too soft allows the hips to sink, rotating the pelvis and creating tension in the piriformis and calf muscles. This tension can trigger nocturnal cramping. A best mattress for back pain with proper zoned support keeps the spine neutral and reduces this risk.

6. Overexertion or New Exercise

Starting a new workout program, particularly running or cycling, causes lactic acid buildup and micro-tears that increase cramping until your muscles adapt over 2–3 weeks.

7. Medications

Statins, diuretics, beta-blockers, and some antidepressants are known to increase cramping frequency. If you started a new medication and noticed more cramps, mention it to your prescriber.

Instant Relief: What to Do During a Cramp

  1. Dorsiflexion stretch: Flex your foot hard toward your shin. Hold for 30–60 seconds. This is the most effective immediate technique in clinical evidence.
  2. Stand and bear weight: Get out of bed and stand flat-footed. The mechanical load helps reset the motor neuron signal.
  3. Massage: Firmly knead the cramped muscle toward the heart to restore blood flow.
  4. Heat: A warm towel or heating pad relaxes the residual tension after the acute cramp passes.

Prevention Strategies

Hydration Protocol

Front-load your hydration earlier in the day so you’re not waking up to use the bathroom at night. A small glass of water with electrolytes 30 minutes before bed is well tolerated by most people.

Bedtime Stretching Routine

Spend 5–7 minutes stretching the calves, hamstrings, and hip flexors before sleep. A standing calf stretch (lean into a wall, heel flat, hold 30 seconds each side) is the most evidence-backed intervention for nocturnal cramps.

Mattress and Sleep Position

If you sleep on your side, a medium-firm mattress with good hip support reduces the pelvic tilt that strains the calf chain. best mattress for side sleepers covers this in detail. A pillow between the knees further reduces piriformis tension.

Back sleepers benefit from a small pillow under the knees to relieve calf tension. Avoid sleeping with feet plantarflexed (pointed down) under heavy bedding — use a footboard or loosen the sheets at the foot of the bed.

Dietary Adjustments

Increase dietary magnesium through pumpkin seeds, almonds, spinach, and black beans. Consider a magnesium glycinate supplement if dietary intake is consistently low — this form has the best bioavailability and is least likely to cause digestive upset.

Reduce Alcohol and Caffeine Before Bed

Both are diuretics that increase urinary magnesium and potassium excretion. Cutting alcohol and caffeine after 2 p.m. meaningfully reduces nighttime electrolyte loss.

Our Top Pick: Saatva Classic

Check Price & Reviews →

Frequently Asked Questions

What causes leg cramps at night?

The most common causes include dehydration, magnesium or potassium deficiency, sitting in poor positions for long periods, overexertion during the day, and nerve compression from a mattress that doesn't support neutral spine alignment.

How do you stop a leg cramp immediately?

Stretch the affected muscle by flexing your foot upward (dorsiflexion), stand up and put weight on the leg, or massage the cramp firmly. Most cramps resolve within 1–3 minutes with active stretching.

Does magnesium help with nocturnal leg cramps?

Evidence is mixed, but magnesium glycinate or citrate (200–400 mg before bed) may reduce frequency for people who are deficient. Talk to your doctor before supplementing, especially if you have kidney issues.

Can a bad mattress cause leg cramps?

Indirectly, yes. A mattress that forces your hips and lower back out of alignment creates muscular tension that can trigger cramping. A medium-firm supportive mattress that keeps the spine neutral reduces that tension.

When should I see a doctor about leg cramps at night?

See a doctor if cramps occur more than three times per week, last longer than 10 minutes, are accompanied by swelling or skin changes, or don't improve with home stretching. They may signal peripheral artery disease or a neurological issue.

Voted best luxury innerspring mattress with exceptional lumbar support and white-glove delivery.

Check Price & Availability FAQPage", "mainEntity": [{"@type": "Question", "name": "What causes leg cramps at night?", "acceptedAnswer": {"@type": "Answer", "text": "The most common causes include dehydration, magnesium or potassium deficiency, sitting in poor positions for long periods, overexertion during the day, and nerve compression from a mattress that doesn't support neutral spine alignment."}}, {"@type": "Question", "name": "How do you stop a leg cramp immediately?", "acceptedAnswer": {"@type": "Answer", "text": "Stretch the affected muscle by flexing your foot upward (dorsiflexion), stand up and put weight on the leg, or massage the cramp firmly. Most cramps resolve within 1–3 minutes with active stretching."}}, {"@type": "Question", "name": "Does magnesium help with nocturnal leg cramps?", "acceptedAnswer": {"@type": "Answer", "text": "Evidence is mixed, but magnesium glycinate or citrate (200–400 mg before bed) may reduce frequency for people who are deficient. Talk to your doctor before supplementing, especially if you have kidney issues."}}, {"@type": "Question", "name": "Can a bad mattress cause leg cramps?", "acceptedAnswer": {"@type": "Answer", "text": "Indirectly, yes. A mattress that forces your hips and lower back out of alignment creates muscular tension that can trigger cramping. A medium-firm supportive mattress that keeps the spine neutral reduces that tension."}}, {"@type": "Question", "name": "When should I see a doctor about leg cramps at night?", "acceptedAnswer": {"@type": "Answer", "text": "See a doctor if cramps occur more than three times per week, last longer than 10 minutes, are accompanied by swelling or skin changes, or don't improve with home stretching. They may signal peripheral artery disease or a neurological issue."}}]}