What Causes Leg and Foot Cramps and How to Prevent Them

Leg and foot cramps are caused by involuntary muscle contractions that can last from a few seconds to several minutes. The triggers range from simple dehydration and mineral shortages to nerve fatigue, poor circulation, and medication side effects. For most people, cramps are harmless but painful, and understanding the cause points directly to the fix.

How a Cramp Happens Inside the Muscle

A muscle cramp starts in the nerves, not the muscle itself. Electromyographic studies show that cramps originate in the lower motor neurons, which fire rapid, involuntary signals that lock the muscle into contraction. Normally, sensors in your tendons act as a brake, telling the nerve to ease off when a muscle contracts too hard. During a cramp, that braking system fails. The nerve keeps firing, the muscle stays clenched, and you feel a sudden, intense tightening you can’t voluntarily release.

Four minerals play central roles in this signaling process. Sodium controls fluid balance and helps nerves fire. Potassium supports nerve and muscle function and helps regulate your metabolism. Calcium helps blood vessels and nerves send signals properly. Magnesium supports nerve-to-muscle communication. When any of these drop too low, the electrical signaling between nerves and muscles becomes unstable, and cramps, spasms, or weakness can follow.

Exercise and Muscle Fatigue

Cramps during or after exercise have been debated by sports scientists for decades, and two competing theories explain them. The traditional view blames dehydration and electrolyte loss: heavy sweating depletes sodium, the fluid around your muscle fibers shrinks, and nerve endings become hyperexcitable and start firing on their own. This theory makes intuitive sense, especially for people who cramp during long runs or outdoor work in the heat.

A newer theory, now supported by stronger evidence, points to altered neuromuscular control. As a muscle fatigues during prolonged, intense exercise, the sensors that normally inhibit excessive contraction (in the tendons) become less effective while the sensors that promote contraction (in the muscle fibers) become more active. This imbalance pushes motor neurons into a “cramp-prone state,” first visible as small twitches, then progressing to a full cramp if the fatiguing activity continues. In practice, both mechanisms likely contribute. If you’re exercising hard in the heat without enough fluids, you’re dealing with fatigue and dehydration simultaneously.

Why Cramps Strike at Night

Nocturnal leg cramps are remarkably common, especially with age. In one study of adults 60 and older, nearly one-third had experienced rest cramps in the previous two months, and among those 80 and older, the rate climbed to half. Another study of elderly outpatients found that 50% had rest cramps, with 20% reporting symptoms for 10 years or more.

The reason night cramps are so common comes down to foot position. When you’re lying in bed, your foot naturally points downward, which shortens the calf muscle. In that already-shortened position, even a small involuntary nerve signal can trigger a full contraction because the muscle fibers have very little slack. Combine that with the fact that you’ve been on your feet all day (building up low-grade fatigue in your lower motor neurons), and the conditions are set for a cramp to fire while you sleep.

Medications That Trigger Cramps

Several common drug classes can cause or worsen leg and foot cramps. Diuretics (water pills), frequently prescribed for high blood pressure, work by flushing extra fluid from the body. They also flush potassium, magnesium, and sodium along with it, which can destabilize nerve-muscle signaling. Statins, taken by millions of people for cholesterol, cause muscle pain or soreness in roughly 5% of users. While cramps are not always the primary complaint, the muscle irritability statins create can lower the threshold for cramping, particularly at night.

If your cramps started or worsened around the same time you began a new medication, that timing is worth noting. Other drug categories linked to cramps include certain asthma medications, blood pressure drugs beyond diuretics, and hormonal therapies.

Poor Circulation and Peripheral Artery Disease

Not all leg pain that feels like a cramp is a simple muscle spasm. Peripheral artery disease (PAD) causes painful cramping in the hips, thighs, or calves when narrowed arteries can’t deliver enough blood to meet the muscles’ demand. Fatty deposits build up on artery walls, restricting flow, and the result is a specific pattern called claudication: pain that starts with activity (walking, climbing stairs) and stops with rest.

The key distinction is predictability. A PAD cramp shows up reliably when you walk a certain distance and fades within minutes of stopping. A regular muscle cramp tends to strike more randomly, especially at rest or at night. In severe PAD, though, pain can occur even while lying down or wake you from sleep, which makes it harder to tell apart from nocturnal cramps. PAD is more common in smokers, people with diabetes, and adults over 65. If your leg pain follows a predictable exercise-then-rest pattern, or if one leg is noticeably cooler or paler than the other, that points toward a circulation problem rather than a simple cramp.

Pregnancy-Related Cramps

Leg cramps are especially common during the second and third trimesters of pregnancy. The exact mechanism isn’t fully understood, but some research suggests that lower blood calcium levels during pregnancy play a role. The growing baby draws heavily on the mother’s mineral stores, and shifts in how the body processes calcium and magnesium may leave muscles more prone to involuntary contraction. The additional weight, changes in posture, and increased pressure on leg nerves from the expanding uterus all add to the burden on lower-leg muscles.

Cramps vs. Restless Leg Syndrome

People often confuse nighttime cramps with restless leg syndrome (RLS), but the two feel quite different. A cramp is a sudden, painful contraction that locks the muscle in place for seconds to minutes. RLS is an uncomfortable urge to move your legs, typically when you’re trying to fall asleep. RLS is usually not painful, and the sensation lasts longer than a cramp does. The hallmark of RLS is that moving your legs relieves the discomfort, while moving during a cramp often makes the pain worse until the contraction releases on its own.

What Actually Helps Prevent Cramps

Despite magnesium’s reputation as a cramp remedy, a Cochrane review of clinical trials found that magnesium supplements produce little to no reduction in cramp frequency, intensity, or duration in non-pregnant older adults. The placebo groups in those studies saw cramp frequency drop by about 29% on their own, and magnesium added less than 10% beyond that, a difference that was not statistically significant. For pregnant women, the evidence is more mixed, with some studies suggesting a modest benefit from magnesium supplementation.

Stretching, on the other hand, has more consistent support. Cleveland Clinic recommends a specific calf stretch for cramp prevention: stand about three feet from a wall, lean forward with your arms outstretched and feet flat on the floor, hold for a count of five, and repeat for at least five minutes. Doing this three times a day can reduce both the frequency and severity of nocturnal calf cramps. The stretch works by lengthening the muscle fibers that tend to cramp when shortened during sleep.

Staying well hydrated throughout the day matters, particularly if you exercise, sweat heavily, or take diuretics. Eating potassium-rich foods (bananas, potatoes, beans) and ensuring adequate calcium and sodium intake supports the electrolyte balance your nerves depend on. When a cramp does strike, gently pulling your toes back toward your shin stretches the calf and can shorten the episode. For foot cramps, pulling the toes upward and pressing the sole flat against the floor or a wall works on the same principle.