Nocturnal leg cramps are extremely common, affecting up to 60 percent of adults at some point. They happen when a muscle in your calf, foot, or thigh contracts involuntarily and won’t release, often jolting you awake with sharp pain that can last seconds to several minutes. The reason they keep coming back usually involves a combination of factors rather than a single cause.
What Triggers Cramps During Sleep
Your muscles don’t fully shut off when you sleep. Motor neurons remain active at a low level, and the sensory receptors inside your muscles (called spindles) continue monitoring tension and length. When these components become overly excitable, a small, normal signal can snowball into a full involuntary contraction. Amplifying circuits in the spinal cord can make this worse by boosting incoming nerve signals instead of dampening them, which is why a cramp can escalate so quickly from a twitch to an intense lock-up.
Several things push your nerves and muscles toward that hyperexcitable state. Dehydration, electrolyte shifts, prolonged sitting, certain medications, and age all play a role. For most people, it’s not one dramatic deficiency but a stack of mild contributors that tips the balance.
Dehydration and Electrolytes
Fluid balance matters because the concentration of electrolytes around your nerve endings influences how easily those nerves fire. When you’re even mildly dehydrated, the fluid surrounding muscle and nerve cells shifts, and local electrolyte concentrations change in ways that make spontaneous firing more likely. This is why cramps often spike in summer, after evening exercise, or if you drink alcohol before bed.
Magnesium, potassium, and calcium are the three electrolytes most tied to muscle cramping. Low magnesium is especially relevant because it directly affects the balance of the other two. Normal magnesium levels fall between about 1.5 and 2.7 mg/dL, and even mild drops below that range can cause muscle spasms, tremors, and numbness in the hands and feet. If your diet is low in leafy greens, nuts, seeds, and whole grains, you may be running a subtle deficit without obvious symptoms beyond nighttime cramps.
Medications That Increase Cramp Risk
If you started a new medication around the time your cramps got worse, that’s worth investigating. Diuretics (water pills) are a well-known trigger because they flush electrolytes. Statin cholesterol drugs, blood pressure medications like angiotensin II receptor blockers, oral contraceptives, bronchodilators, and even high caffeine intake are all associated with increased cramping. Stimulants in general, including nicotine and pseudoephedrine (found in many cold medicines), can raise nerve excitability enough to provoke nighttime cramps.
Sitting Too Much, Moving Too Little
Prolonged sitting shortens your calf muscles over time. When you lie down at night and your foot naturally points downward (a position called plantar flexion), already-shortened calf muscles compress further. That shortened position can trigger the stretch receptors inside the muscle to misfire, setting off a cramp. People who sit at a desk all day and then go straight to the couch in the evening are particularly prone to this pattern. The cramps aren’t from overuse; they’re from underuse followed by a vulnerable sleeping position.
Age, Pregnancy, and Other Risk Factors
Nocturnal cramps become more frequent with age. The prevalence climbs steadily after 50, likely because of gradual nerve changes, decreased muscle mass, and the accumulation of medications. Women are slightly more affected than men across all age groups.
Pregnancy is another major trigger. Blood volume nearly doubles during pregnancy, which slows circulation in the legs and causes swelling. The growing uterus also puts pressure on blood vessels that return blood from the lower body, further straining circulation. This combination makes leg cramps especially common in the second and third trimesters.
Certain chronic conditions are known to cause nocturnal cramps as well, including kidney disease, diabetic nerve damage, and peripheral artery disease (narrowed arteries in the legs). But these conditions come with other noticeable symptoms, so cramps alone are unlikely to be your first sign of something serious.
How to Stop a Cramp in the Moment
When a charley horse hits your calf or hamstring, the fastest relief comes from stretching the muscle in the opposite direction of the contraction. For a calf cramp, flex your foot upward toward your shin. You can do this by standing and walking on your heels, or by lying down and pulling your toes toward your nose with your hand or a towel looped around the ball of your foot. For a quadriceps cramp (front of the thigh), bend your knee and pull your foot up toward your buttock. Gently rubbing the muscle while stretching it helps it release faster.
For a foot cramp, stand up and put weight on the cramping foot, then flex your toes upward. The key in all cases is to lengthen the muscle that’s contracting. Pushing through the pain of the stretch is uncomfortable for a few seconds, but it overrides the faulty nerve signal and breaks the cramp cycle.
Preventing Cramps From Coming Back
Start with the basics: drink enough water throughout the day (not just at bedtime), and make sure your diet includes magnesium and potassium-rich foods like bananas, avocados, sweet potatoes, nuts, and dark leafy greens. A short calf-stretching routine before bed, even just 60 seconds per leg, can meaningfully reduce cramp frequency by keeping muscles at a longer resting length overnight.
Your sleeping position matters too. Try to avoid letting your feet point straight down under heavy blankets, which holds your calves in a shortened position for hours. Sleeping with a pillow between your knees can improve blood flow through the major veins returning blood to your heart. Untucking the sheets at the foot of the bed gives your feet room to stay in a neutral position.
What About Supplements?
Magnesium supplements are widely recommended for leg cramps, but the evidence is mixed. A randomized clinical trial of magnesium oxide for nocturnal leg cramps, published in JAMA Internal Medicine, was actually terminated early because the magnesium showed no meaningful benefit over placebo. That doesn’t mean magnesium is useless if you’re genuinely deficient, but taking extra when your levels are already normal probably won’t fix the problem.
A more promising option is vitamin K2 (specifically the form called menaquinone-7). A recent clinical trial found that taking 180 micrograms of vitamin K2 in the evening cut the average number of weekly cramps roughly in half over two months, dropping from about 3.6 cramps per week in the placebo group to under 1 per week in the treatment group. It has few side effects, though it should not be taken by anyone on the blood thinner warfarin, as it can reduce the drug’s effectiveness.
Cramps vs. Restless Legs Syndrome
These two conditions get confused often because both happen at night and involve the legs. The difference is straightforward: a charley horse is a sudden, painful, involuntary contraction you can see and feel as a hard knot in the muscle. Restless legs syndrome is an uncomfortable crawling or pulling sensation that creates an urge to move your legs but is not typically painful and doesn’t involve a visible muscle contraction. Restless legs symptoms also tend to last much longer than a cramp, which usually resolves within a few minutes. If your experience is more of a restless, creepy-crawly discomfort than a sharp seizing pain, you may be dealing with a different condition entirely.