What Vitamin Deficiency Causes Leg Cramps at Night?

Magnesium deficiency is the most commonly cited nutritional cause of nighttime leg cramps, though low levels of potassium, calcium, and certain B vitamins can also play a role. The tricky part: the exact mechanism behind nocturnal leg cramps is still not fully understood, and fixing a single deficiency doesn’t always solve the problem. Here’s what the evidence actually shows about which nutrients matter most and what you can do about it.

Magnesium: The Most Likely Culprit

Magnesium is essential for both nerve signaling and muscle contraction. When your body doesn’t have enough, nerves can become overexcitable, sending signals that cause muscles to contract involuntarily. This is why low magnesium (hypomagnesemia) consistently shows up as a risk factor for muscle cramps across a range of medical conditions, from kidney disease to thyroid disorders.

The recommended daily intake for magnesium is 420 mg for men and 320 mg for women over age 31. Most people don’t hit that number. Processed foods, alcohol, and certain medications can all reduce your magnesium levels further. The problem is compounded by the fact that standard blood tests are unreliable for detecting a true deficiency. Serum magnesium represents only about 0.8% of your total body stores, meaning you can have a normal blood reading while the other 99.2% of your magnesium, stored in bones, muscles, and other tissues, is running low. A practitioner measuring your serum magnesium may see results within the normal reference range even when your body is genuinely depleted.

Despite magnesium’s strong biological connection to muscle cramping, clinical trials on supplementation have been surprisingly modest. In one randomized trial, people taking magnesium oxide saw their cramps drop from about 8 per week to about 4.4 per week. That sounds promising until you see that the placebo group dropped from 8.5 to 5.5 per week. The difference between the two groups was small, suggesting that some of the improvement comes from the natural tendency of cramps to fluctuate over time. Still, many clinicians consider a trial of magnesium supplementation reasonable given its safety profile.

Potassium and Calcium Deficiencies

Potassium and calcium work alongside magnesium to regulate how your muscles contract and relax. When potassium drops too low, muscles can cramp, twitch, or even go into sustained spasms called tetany. Normal blood potassium falls between 3.5 and 5.3 mmol/L. Levels significantly below that range cause symptoms ranging from mild cramping and tingling to dangerous heart rhythm changes.

Calcium plays a similar role. Your muscles need calcium ions to initiate every contraction, and the nervous system uses calcium to regulate excitability. When calcium is too low, nerves fire more easily, which can trigger involuntary cramping. Notably, these minerals are interconnected. Magnesium deficiency can itself cause potassium and calcium levels to drop, creating a chain reaction that makes cramps worse. This is one reason why correcting just one mineral sometimes doesn’t help.

One study analyzing predictors of muscle cramps found that dietary potassium intake was one of only three significant variables predicting whether someone experienced cramps, alongside kidney function and pain levels. That finding held up even after accounting for calcium, magnesium, and vitamin D intake.

B Vitamins: A Lesser-Known Factor

B-complex vitamins don’t get as much attention for leg cramps, but there’s clinical evidence they matter. A randomized, placebo-controlled trial tested a B-vitamin complex (containing forms of B1, B2, B6, and B12) in elderly patients with high blood pressure who had severe nocturnal leg cramps disrupting their sleep. After three months, 86% of the patients taking the B-complex had prominent remission of their cramps. The placebo group showed no significant change. The treatment reduced cramp frequency, intensity, and duration.

B vitamins support nerve function, and deficiencies in B1, B6, and B12 can cause peripheral nerve damage that makes muscles more prone to involuntary contraction. People at higher risk for B-vitamin deficiency include older adults (who absorb B12 less efficiently), people taking certain acid-reducing medications, heavy alcohol users, and those following restrictive diets.

Vitamin D Probably Doesn’t Help

Vitamin D is often mentioned alongside leg cramps because it influences calcium absorption and muscle function. But the clinical evidence doesn’t support a direct link. A well-designed trial gave postmenopausal women with vitamin D insufficiency either high-dose vitamin D or a placebo, then tracked muscle cramps over time. Despite successfully raising blood vitamin D levels above 30 ng/mL, there was no difference in cramp frequency or severity between the vitamin D and placebo groups. About 40% of participants in every group experienced cramps regardless of treatment.

This doesn’t mean vitamin D is unimportant for muscle health in general, but if nighttime leg cramps are your primary concern, correcting a vitamin D deficiency alone is unlikely to resolve them.

Medications That Deplete Key Minerals

Sometimes the deficiency causing your cramps isn’t from your diet. It’s from your medicine cabinet. A large study found that certain medications significantly increased the likelihood of developing nocturnal leg cramps. Thiazide diuretics (commonly prescribed for blood pressure) were associated with a 48% increase in cramp treatment. Potassium-sparing diuretics, despite their name, more than doubled the risk. Long-acting bronchodilators used for asthma and COPD showed an even stronger association, with a roughly 2.4-fold increase.

Statins, often blamed for muscle problems, showed only a small 16% increase in cramp treatment. If you’re taking any of these medications and experiencing new or worsening leg cramps, the medication itself may be contributing by altering your electrolyte balance.

Leg Cramps During Pregnancy

Pregnant women are especially prone to nocturnal leg cramps, partly because the growing fetus draws heavily on the mother’s mineral stores. Increased kidney filtration during pregnancy accelerates the loss of calcium and magnesium, while the expanding uterus can compress nerves and blood vessels in the legs. Various treatments have been studied for pregnancy-related leg cramps, including supplementation with magnesium, calcium, and vitamins B1, B6, C, and E. Ensuring adequate mineral intake throughout pregnancy can help, though cramps often resolve after delivery regardless.

What Actually Helps

If you’re waking up with painful calf or foot cramps, the most practical first step is increasing your intake of magnesium and potassium through food. Magnesium-rich foods include dark leafy greens, nuts (especially almonds and cashews), seeds, beans, and whole grains. Potassium-rich foods include bananas, potatoes, sweet potatoes, avocados, and spinach. A diet consistently low in these foods is the most common reason for mild deficiencies.

For immediate relief during a cramp, passively stretching the affected muscle works. If your calf seizes, flex your foot upward (pulling your toes toward your shin) to lengthen the cramping muscle. Holding the stretch for 15 to 30 seconds typically breaks the spasm.

For prevention, nightly calf stretches before bed have some evidence behind them. Stand about arm’s length from a wall, step one foot back, and press the heel into the floor while leaning forward. Hold for 30 seconds on each side. This won’t address a nutritional deficiency, but it can reduce the frequency of cramps while you work on the underlying cause.

If you suspect a deficiency, keep in mind that a normal serum magnesium result doesn’t rule one out. Practitioners familiar with the limitations of standard testing may consider a trial of supplementation based on your symptoms and dietary history rather than relying solely on bloodwork. Magnesium citrate and magnesium glycinate are generally better absorbed than magnesium oxide, though oxide was the form used in most clinical trials.