Nocturnal leg cramps are caused by involuntary, sustained contractions of the calf or foot muscles, most likely driven by overexcitable nerve signals to the muscle. Up to 60 percent of adults experience them, and about 20 percent of those people have cramps frequent enough to seek medical help. The causes range from simple muscle fatigue to medication side effects and underlying health conditions.
What Happens Inside the Muscle
A nighttime leg cramp is not just a twitch. It’s a forceful, involuntary contraction that can last from a few seconds to several minutes, often leaving soreness that lingers into the next day. The leading explanation centers on the motor neurons that control your calf and foot muscles. These nerve cells become hyperexcitable, firing repeatedly and forcing the muscle into a locked contraction you can’t voluntarily release.
Why this happens preferentially at night isn’t fully understood, but several factors converge during sleep. Your legs are relatively still for hours, which may allow nerve irritability to build. Slight changes in sleeping position can trigger a shortened calf muscle to fire. And your body’s natural ability to inhibit unwanted nerve signals may be reduced while you’re asleep, giving those overactive motor neurons free rein.
Muscle Fatigue and Physical Activity
One of the most common triggers is simply how much you used your legs during the day. Unusual or prolonged physical activity, like a long hike, yard work, or standing on your feet for hours, fatigues the muscle in ways that make it more prone to involuntary contraction later. The fatigue doesn’t always feel dramatic at the time. You might not notice it until you’re woken at 2 a.m. with a rock-hard calf.
The reverse is also true. Prolonged sitting and a sedentary lifestyle can shorten the calf muscles and Achilles tendon over time, making those muscles more susceptible to cramping when they’re in a slightly shortened position during sleep. This helps explain why nocturnal leg cramps become more common with age: older adults tend to lose muscle mass and spend more time sitting, both of which increase vulnerability.
Dehydration and Electrolytes
Dehydration is a well-known contributor, particularly if you exercise in hot weather, don’t drink enough water throughout the day, or take medications that increase fluid loss. When your body is low on fluids, the balance of minerals in your blood shifts, and your muscles become more irritable.
Magnesium, potassium, and calcium all play roles in normal muscle contraction and relaxation. Deficiencies in any of them can increase cramp frequency. However, the evidence for supplementation is surprisingly weak. Magnesium is widely used to treat leg cramps, especially in Europe and Latin America, but almost all clinical studies have found it no more effective than a placebo. A 2017 randomized trial of 94 adults found magnesium oxide capsules did nothing to reduce night cramps compared to a sugar pill, and a 2013 review of seven trials reached the same conclusion for the general population. The one exception: magnesium may offer a small benefit for pregnant women. This doesn’t mean electrolytes are irrelevant to cramping. It means that if you’re eating a reasonably balanced diet, popping a supplement is unlikely to fix the problem.
Medications That Trigger Cramps
A surprisingly long list of common medications can cause or worsen leg cramps. If your nighttime cramps started around the same time you began a new prescription, the medication may be the culprit. Drug classes associated with leg cramps include:
- Diuretics (water pills), which deplete fluids and electrolytes
- Statins, particularly lovastatin, used for cholesterol
- Blood pressure medications, including certain beta-blockers and angiotensin II receptor blockers
- Bronchodilators and asthma inhalers with beta-agonist effects
- Oral contraceptives
- Stimulants, including caffeine, nicotine, pseudoephedrine (found in many cold medications), and amphetamines
If you suspect a medication is involved, don’t stop taking it on your own. But it’s worth flagging for whoever prescribed it, because alternatives or dosage adjustments can sometimes help.
Medical Conditions Linked to Cramps
For most people, nighttime leg cramps are annoying but harmless. In some cases, though, they’re a signal of an underlying condition. Diabetes is one of the more common links. Diabetic peripheral neuropathy, the nerve damage that develops when blood sugar stays elevated over time, affects the feet and legs first and tends to worsen at night. Sharp pains and cramps are among its hallmark symptoms.
Peripheral artery disease, where narrowed blood vessels reduce blood flow to the legs, can also produce cramping, though this more commonly shows up during walking rather than at rest. Kidney disease, thyroid disorders, and liver disease all affect electrolyte balance and nerve function in ways that can increase cramp frequency. If your leg cramps are happening nightly or are severe enough to regularly disrupt your sleep, an underlying medical cause is worth investigating.
Pregnancy and Leg Cramps
Pregnant women are especially prone to nocturnal leg cramps, particularly in the second and third trimesters. The exact mechanism isn’t clear, but research suggests that lower blood calcium levels during pregnancy may play a role. Added weight, changes in circulation, and pressure on leg nerves from the growing uterus all likely contribute. For pregnant women specifically, there is limited evidence that magnesium supplementation may offer modest relief, unlike in the general population.
How to Tell It’s Not Restless Legs Syndrome
Many people confuse nocturnal leg cramps with restless legs syndrome because both happen at night and involve the legs. The distinction is straightforward: a leg cramp is a painful, forceful contraction that locks the muscle in a hard knot. Restless legs syndrome is uncomfortable but not agonizing. It produces a crawling, tingling sensation and an irresistible urge to move your legs, but no actual muscle contraction or sharp pain. If what you’re feeling is an unpleasant restlessness rather than a sudden, gripping cramp, you may be dealing with a different condition entirely.
What Actually Helps Prevent Them
The intervention with the best evidence behind it is simple calf stretching before bed. A clinical trial of adults over 55 found that a nightly stretching routine targeting the calves and hamstrings reduced cramp frequency by about 35 percent after six weeks. The routine doesn’t need to be elaborate. Standing on a step and letting your heels drop below the edge, or doing a classic runner’s stretch against a wall for 30 seconds per leg, is enough to keep the muscle lengthened heading into sleep.
Staying well hydrated throughout the day, particularly if you’re active or taking diuretics, reduces one of the most modifiable risk factors. Some people find that keeping blankets loose at the foot of the bed helps, since tight sheets can push the feet into a pointed position that shortens the calf muscles and invites cramping.
When a cramp strikes, the fastest relief comes from forcefully flexing your foot upward (pulling your toes toward your shin), which stretches the contracting calf and helps break the spasm. Walking on the affected leg or massaging the muscle can also shorten the episode. The soreness that sometimes lingers afterward responds well to a warm towel or heating pad.

