What Nutrient Deficiency Causes Leg Cramps at Night?

Low levels of magnesium, potassium, and calcium are the three deficiencies most commonly linked to leg cramps at night. Of these, magnesium deficiency gets the most attention, though the actual evidence connecting any single nutrient to nocturnal cramps is more complicated than most people expect. Dehydration, medication side effects, and simple muscle fatigue also play significant roles, sometimes making it hard to pin cramps on one missing mineral.

Magnesium: The Most Cited Deficiency

Magnesium is involved in over 300 enzyme reactions in the body, including the process that allows muscles to relax after contracting. When magnesium drops too low, muscles can become hyperexcitable, meaning they fire and tighten more easily than they should. Severe magnesium deficiency causes a condition called tetany, where muscles contract involuntarily and painfully. Milder shortfalls may not reach that extreme but are still thought to lower the threshold for cramping.

Symptoms of low magnesium go beyond cramps. Fatigue, weakness, loss of appetite, nausea, numbness, and tingling are all signs. In extreme cases, dangerously low magnesium can cause irregular heartbeat or seizures. The tricky part is that a standard blood test only measures the magnesium circulating in your bloodstream, which represents roughly 1% of your body’s total stores. You can have depleted magnesium in your muscles and bones while your blood level looks normal. A red blood cell magnesium test or a urine magnesium test can sometimes give a fuller picture.

Here’s the surprising part: despite magnesium’s well-known role in muscle function, supplementing with it doesn’t reliably stop nighttime cramps. A Cochrane review combining five studies with over 300 older adults found that magnesium supplements reduced cramp frequency by less than 0.2 cramps per week compared to placebo, a difference that was not statistically significant. The percentage of people who experienced at least a 25% improvement was identical in the magnesium and placebo groups. Cramp intensity and duration didn’t improve either. The reviewers concluded, with moderate to high certainty, that magnesium is unlikely to provide meaningful cramp relief for older adults.

That doesn’t mean magnesium is irrelevant. If you are genuinely deficient, correcting the deficiency addresses a real physiological problem. The evidence simply suggests that most people who get nighttime leg cramps aren’t deficient enough for magnesium to be the fix.

Potassium and Its Role in Muscle Signaling

Potassium is the dominant electrolyte inside your cells, while sodium dominates outside. A molecular pump on every cell membrane constantly shuffles sodium out and potassium in, maintaining the electrical charge difference that allows nerves and muscles to fire properly. When potassium drops below about 3.6 mmol/L in the blood (a condition called hypokalemia), muscles lose their ability to contract and relax in an orderly way. The result can be weakness, twitching, and cramping.

Unlike magnesium, potassium levels are reliably measured with a standard blood draw. Low potassium is relatively common in people who take certain water pills (diuretics), have chronic diarrhea or vomiting, sweat heavily, or don’t eat enough fruits and vegetables. Bananas get all the credit, but potatoes, beans, spinach, and avocados are actually richer sources. Most adults need around 2,600 to 3,400 mg of potassium daily, and many fall short.

Calcium’s Connection to Cramping

Calcium is the mineral that directly triggers muscle fibers to contract. When a nerve signal arrives at a muscle cell, calcium floods in and starts the contraction. If blood calcium drops too low, the nervous system becomes overly excitable, which can cause muscles to spasm or cramp without a deliberate signal from the brain.

True calcium deficiency severe enough to cause cramping (hypocalcemia) is less common in the general population but more likely during pregnancy and in people with vitamin D deficiency, parathyroid disorders, or kidney disease. During pregnancy, the growing baby draws heavily on the mother’s calcium stores, and some research suggests that lower blood calcium levels during pregnancy contribute to the leg cramps that are especially common in the second and third trimesters.

How Vitamin D Fits In

Vitamin D doesn’t act on muscles directly in the way magnesium or calcium does, but it controls how much calcium your body absorbs from food. Without enough vitamin D, calcium absorption drops, and your blood calcium can fall even if your dietary intake is adequate. This is why vitamin D deficiency is sometimes an indirect cause of muscle cramps.

Researchers have tested whether correcting vitamin D insufficiency reduces cramps. In a randomized, double-blind trial involving postmenopausal women with low vitamin D, supplementation did not significantly reduce the frequency or severity of muscle cramps. As with magnesium, the relationship between a nutrient’s known biological role and its ability to fix cramps when supplemented turns out to be less straightforward than it seems.

Dehydration vs. Mineral Deficiency

Many people assume their cramps are caused by dehydration, and while fluid loss can contribute, the picture is more nuanced. Research on exercise-related cramps found that the incidence of cramping was similar whether people were mildly dehydrated or had consumed an electrolyte drink. When fluid loss was only about 1% of body weight and the cramps were localized to specific muscles, fatigue appeared to be the primary trigger rather than dehydration or electrolyte imbalance.

That said, there is a meaningful distinction between cramps caused by fatigue and cramps caused by heavy sweating in heat. Fatigue-induced cramps tend to affect one specific muscle, like a calf. Heat-related cramps, where significant fluid and electrolyte losses shrink the fluid space around cells, tend to be more widespread, affecting multiple muscle groups. Nighttime leg cramps in people who aren’t exercising intensely are more likely related to prolonged positioning, mild chronic dehydration, or subtle electrolyte shifts than to acute fluid loss.

Medications That Deplete Key Minerals

Some of the most commonly prescribed medications can quietly drain your body of the very electrolytes that keep muscles functioning smoothly. Thiazide and loop diuretics, prescribed for high blood pressure and fluid retention, increase urinary loss of both potassium and magnesium. If you’ve started a diuretic and noticed more nighttime cramps, the connection is worth raising with your prescriber. Proton pump inhibitors (used for acid reflux) can impair magnesium absorption over time, particularly with long-term use. Certain blood pressure medications, laxatives used frequently, and even high-dose caffeine intake can also shift electrolyte balance enough to contribute to cramping.

Which Form of Magnesium Is Best Absorbed

If you do want to try magnesium supplementation, the type matters more than whether it comes as a capsule, powder, or gummy. Magnesium citrate, glycinate, and malate are all well absorbed. Magnesium glycinate is the gentlest on the stomach and may also have a calming effect that helps with sleep. Magnesium citrate absorbs easily but is more likely to cause loose stools. Magnesium oxide, one of the cheapest and most widely sold forms, is poorly absorbed and primarily useful as a laxative.

The recommended daily intake for magnesium is 400 to 420 mg for men and 310 to 320 mg for women, with slightly higher needs during pregnancy. The upper limit specifically for supplements (on top of what you get from food) is around 350 mg per day. Going above that increases the risk of diarrhea and digestive discomfort. Epsom salt baths (magnesium sulfate) may feel soothing on sore muscles, but they don’t meaningfully raise your body’s magnesium levels through the skin.

What Nighttime Cramps Likely Are

Nocturnal leg cramps are extremely common, affecting up to 60% of adults at some point. In most cases, no clear deficiency is found. The leading theory is that the calf muscle shortens slightly when the foot naturally points downward during sleep, and in that shortened position, the muscle is more prone to involuntary contraction. Age-related loss of motor neurons, reduced stretching habits, prolonged sitting or standing during the day, and the factors above (mild electrolyte imbalances, dehydration, medications) all raise the likelihood.

If your cramps are occasional, gentle calf stretching before bed, staying well hydrated throughout the day, and eating potassium- and magnesium-rich foods (leafy greens, nuts, seeds, bananas, beans) are the most practical first steps. If cramps are frequent, worsening, or accompanied by muscle weakness, numbness, or swelling, blood work for potassium, magnesium, calcium, and kidney function can help identify or rule out a deficiency as the cause.