What Causes Muscle Cramps in Your Legs and Feet?

Leg and foot cramps are caused by involuntary firing of motor neurons that force your muscle into a sustained contraction. The triggers range from dehydration and mineral shortages to nerve compression, poor circulation, and simple muscle fatigue. About 40% of adults over 50 experience nocturnal leg cramps, and the frequency increases with age.

Most cramps are harmless, but understanding the specific cause helps you prevent them. Here’s what’s actually happening in your body and what makes certain people more vulnerable.

How a Cramp Starts Inside the Muscle

A cramp isn’t your muscle acting on its own. It starts with your nervous system. Peripheral nerves or spinal circuits become hyperexcitable, sending rapid, sustained signals that lock the muscle into contraction. Several things can trigger this misfiring: electrolyte shifts that destabilize nerve membranes, mechanical disruption at the junction where nerve meets muscle, or fatigue that throws off the feedback loop between your muscles and spinal cord.

Under normal conditions, sensors in your tendons (called Golgi tendon organs) detect when a muscle is under heavy load and send inhibitory signals to dial down the contraction. When a muscle is fatigued, this braking system weakens while the excitatory signals from muscle spindles ramp up. The result is a contraction your brain didn’t ask for, and one you can’t immediately shut off.

This is why stretching works during an active cramp. Pulling the muscle lengthwise reactivates those tendon sensors and restores the inhibitory signal, essentially overriding the spasm at the spinal level.

Electrolyte Imbalances

Potassium, magnesium, calcium, and sodium all play roles in how nerves fire and muscles contract and relax. When levels drop or shift, the electrical signaling across muscle membranes becomes unstable, making cramps far more likely.

Potassium supports nerve and muscle communication and helps move nutrients in and out of cells. Magnesium aids both nerve and muscle function directly. Calcium helps the nervous system send messages between cells. A shortage in any of these can produce muscle cramps, spasms, or weakness.

You lose electrolytes primarily through sweat and urine. Heavy sweating during exercise or hot weather is a classic trigger, but the problem isn’t just fluid loss. Some of the strongest historical evidence comes from studies of miners and steel mill workers in the 1920s and 1930s, where adding salt to drinking water nearly eliminated cramps among 12,000 workers. The issue wasn’t dehydration alone. It was drinking plain water while losing large amounts of sodium and chloride through sweat, diluting the remaining electrolytes in the blood.

Exercise and Muscle Fatigue

If you’ve ever gotten a cramp during a long run, a pickup basketball game, or a hike that went longer than planned, fatigue is the most likely culprit. Exercise-associated muscle cramps tend to hit muscles that are working hardest, especially when they’re contracting in a shortened position.

The leading explanation is that fatigue disrupts the spinal reflex that controls muscle contraction. As a muscle tires, the excitatory signals increase while the inhibitory signals from tendons decrease. This creates a perfect setup for sustained, involuntary firing. It explains why cramps tend to strike late in a workout or competition, and why they target the specific muscles under the most strain rather than hitting randomly throughout the body.

Overloading your feet specifically, whether from exercising harder than usual, running on a new surface, or standing for extended periods, can fatigue the small intrinsic muscles of the foot and trigger arch cramps.

Nighttime Leg Cramps

Nocturnal cramps are among the most common type, affecting roughly 40% of people over 50. They also occur in about 7% of children and adolescents, peaking between ages 16 and 18. The cramps are associated with sleep disturbance and tend to become more frequent with age, with no difference between men and women.

The exact mechanism behind nighttime cramps isn’t fully settled, but several factors converge while you sleep. Your legs are relatively still for hours, which can allow fluid and electrolytes to redistribute. Sleeping with your feet pointed downward (a natural position under blankets) shortens the calf muscles, putting them in a vulnerable, partially contracted state. Minor nerve signals that your brain would normally override during the day may go unchecked during sleep, tipping a resting muscle into full spasm.

Poor Circulation

When arteries in your legs narrow from plaque buildup, a condition called peripheral artery disease, your muscles can’t get enough oxygen-rich blood to meet demand during activity. The result is a cramping pain that typically starts during walking and eases with rest.

This type of pain, called claudication, follows a predictable pattern. It tends to hit at a certain walking speed and distance, and it reliably improves within minutes of stopping. As the condition progresses, the pain threshold drops: you cramp sooner, with less effort, and eventually the discomfort can persist even at rest. The key distinction from ordinary cramps is the consistent link to activity and the relief that comes from stopping. Regular muscle cramps can strike at any time, including during sleep, and don’t follow this exercise-rest pattern.

Footwear and Nerve Compression

Foot cramps in particular have a mechanical dimension that leg cramps don’t. Shoes that are too tight or too small restrict circulation and compress nerves, which can cause your foot to cramp, go numb, or force your toes to curl. High heels hold the foot in a shortened, plantarflexed position that fatigues the arch muscles over time. Even flat shoes with poor support can overwork the small muscles in the foot, especially if you’re on your feet all day.

If your foot cramps cluster around specific activities or specific shoes, the footwear is the first thing to address. Switching to shoes with adequate width and arch support often resolves the problem entirely.

Medications That Trigger Cramps

Several common drug classes list muscle cramps as a side effect. Statins, used to lower cholesterol, are among the most well-known offenders. In clinical practice, 15% to 20% of patients on statins report muscle-related symptoms including pain and cramping, with women affected more often than men.

Diuretics (water pills) are another frequent cause. They work by increasing urine output, which pulls potassium, magnesium, and sodium out of the body along with the excess fluid. This electrolyte drain directly increases cramp risk. Blood pressure medications, asthma drugs, and some osteoporosis treatments can also contribute. If your cramps started or worsened after beginning a new medication, the timing is worth noting and discussing with your prescriber.

Stopping a Cramp and Preventing the Next One

When a cramp hits, stretching the affected muscle is the fastest relief. For a calf cramp, keep your leg straight and pull the top of your foot toward your face, or stand and press your weight down through the cramped leg. For a front-of-thigh cramp, pull your foot up toward your buttock while holding a chair for balance. Gently massaging the muscle while stretching helps it release faster.

For prevention, the strategy depends on the cause:

  • Hydration and electrolytes: If you sweat heavily during exercise or work, drink fluids that contain sodium rather than plain water alone. Sports drinks, electrolyte tablets, or lightly salted water all help maintain the mineral balance your muscles need.
  • Magnesium: Magnesium supplements have been studied for nocturnal cramps, with trials testing doses in the range of 200 to 400 mg daily. Results have been mixed, but people with low dietary magnesium intake (common in older adults) are most likely to benefit. Foods rich in magnesium include nuts, seeds, leafy greens, and whole grains.
  • Stretching before bed: A brief calf-stretching routine before sleep can reduce the frequency of nighttime cramps. Holding a wall stretch for 30 seconds on each side takes minimal effort and addresses the shortened-muscle trigger directly.
  • Proper footwear: Ensure your shoes have enough room in the toe box, adequate arch support, and aren’t compressing the top of your foot. This is especially important if your cramps center on the arch or toes.
  • Pacing during exercise: Since fatigue is a primary driver of exercise-related cramps, building up training volume gradually and conditioning the specific muscles you’ll be using reduces your risk.

Occasional cramps are normal and rarely signal anything serious. Cramps that happen frequently, wake you multiple times per week, don’t respond to stretching, or are accompanied by swelling, numbness, or muscle weakness may point to an underlying condition worth investigating.