Most leg cramps stop within a few minutes if you stretch the muscle, and most can be prevented with a few habit changes around hydration, movement, and nutrition. The painful, involuntary contraction you feel is likely caused by overactive nerve signals firing into a fatigued or shortened muscle, not necessarily a sign of something wrong with your electrolytes or overall health.
That said, cramps that keep coming back, wake you up regularly, or come with other symptoms deserve a closer look. Here’s how to handle them in the moment and reduce how often they happen.
What to Do During an Active Cramp
When a cramp hits, your goal is to lengthen the muscle that’s seizing up. For a calf cramp (the most common type), flex your foot by pulling your toes toward your shin. You can do this by standing and pressing your heel into the floor, or by grabbing your toes and gently pulling them back while seated. For a hamstring cramp, straighten your leg and lean forward at the hips. For a thigh cramp in the front of your leg, pull your foot behind you toward your glutes.
Hold the stretch until the contraction releases, usually 30 to 60 seconds. Once the acute spasm passes, massaging the area and applying heat (a warm towel or heating pad) can ease the lingering soreness. Ice works too if the muscle feels inflamed. Walking around gently for a minute or two helps the muscle reset to its normal resting length.
Why Leg Cramps Happen
The exact mechanism behind leg cramps isn’t fully settled, but muscle fatigue and nerve dysfunction are the leading explanations. Research on exercise-related cramps points to a problem with the nerve signals controlling muscle contraction: the signals telling a muscle to fire become overactive while the signals telling it to relax become underactive. This imbalance causes the muscle to lock into a sustained contraction, especially when it’s already in a shortened position.
That shortened-position detail helps explain why cramps so often strike at night. When you’re lying in bed with your feet pointed downward, your calf muscles are already contracted. In that position, even a small burst of nerve activity can tip the muscle into a full cramp. Fatigue from the day’s activity compounds the problem.
The older “dehydration and electrolyte” theory is less supported by current evidence for exercise-related cramps, but electrolyte levels still matter in a broader sense. Low magnesium or potassium can prevent muscles from fully relaxing, making cramps more likely in everyday life.
Daily Habits That Prevent Cramps
Staying hydrated is one of the simplest and most effective strategies. Muscles need adequate fluid to contract and relax properly, so drinking water consistently throughout the day, and especially before and during exercise, reduces your risk. You don’t need to follow a rigid schedule. Just drink enough that your urine stays a pale yellow.
Stretching is equally important. If you exercise, warm up with some walking in place or a slow jog before your workout, and stretch your leg muscles for a few minutes afterward. If nighttime cramps are your main problem, do a set of calf and hamstring stretches before bed. Stand facing a wall, place one foot behind you with the heel flat on the ground, and lean forward until you feel a gentle pull in the back of your lower leg. Hold for 30 seconds on each side.
Regular physical activity itself helps prevent cramps. Muscles that are conditioned and used to being loaded are less prone to the kind of fatigue that triggers involuntary contractions. Even daily walking makes a difference. On the other hand, suddenly ramping up activity, like a long hike after weeks of inactivity, is a classic cramp trigger.
Footwear matters more than most people realize. Shoes with poor arch support or flat soles can change how your calf muscles work throughout the day, contributing to fatigue. Shoes with a firm heel counter (the rigid part that cups your heel) provide better support and may reduce nighttime cramping.
Nutrition and Electrolytes
A diet low in magnesium, potassium, or calcium can set you up for more frequent cramps. These minerals help regulate how your muscles contract and relax. Potassium supports nerve and muscle function directly. Magnesium helps muscles release after contraction. Calcium plays a role in the nerve signaling that triggers contraction in the first place.
Good food sources of potassium include bananas, potatoes, spinach, and avocados. For magnesium, reach for nuts, seeds, dark leafy greens, and whole grains. Dairy products, fortified plant milks, and leafy greens cover calcium.
If food alone isn’t enough, magnesium supplements can help. Research in pregnant women found that magnesium citrate or magnesium lactate taken twice a day reduced leg cramp frequency. These two forms are better absorbed than magnesium oxide, which is cheaper but passes through the gut without being fully used. If you’re considering a supplement, magnesium citrate is widely available and well tolerated.
Leg Cramps During Pregnancy
Leg cramps are especially common during the second and third trimesters. The exact cause isn’t clear, but the combination of extra weight, changes in circulation, and shifting mineral demands likely plays a role. Some research suggests that lower blood calcium levels during pregnancy contribute to cramping.
The prevention strategies are the same as for anyone else, with a few additions. Pregnant women need about 1,000 milligrams of calcium daily. Stretching the calves before bed, staying physically active, and keeping well hydrated all help. A magnesium supplement may reduce cramp frequency, though the evidence is mixed. Supportive shoes with a firm heel counter can also make a difference when you’re carrying extra weight.
Medications That Can Cause Cramps
If your cramps started or worsened around the same time you began a new medication, the drug could be the trigger. Statins, commonly prescribed for high cholesterol, are well known for causing muscle pain, soreness, and cramping. Diuretics (water pills) can deplete potassium and other electrolytes, indirectly leading to cramps. Certain hormone therapies, some pain relievers, and osteoporosis medications have also been linked to increased cramping.
If you suspect a medication connection, that’s worth a conversation with whoever prescribed it. Switching to a different drug in the same class or adjusting the dose often resolves the problem.
Why Quinine Isn’t the Answer
Quinine, a malaria drug, was once widely prescribed off-label for leg cramps. The FDA has made it clear that quinine is not considered safe or effective for this purpose. It carries serious risks, including a dangerous drop in blood platelets, life-threatening allergic reactions, and heart rhythm problems. Fatalities have been reported. Despite a decline in use, people still occasionally encounter quinine as a suggestion for cramps, sometimes in the form of tonic water. The amount in tonic water is small, but there’s no good evidence it helps, and the risks of prescription-strength quinine far outweigh any benefit for something as manageable as leg cramps.
When a Cramp Might Be Something Else
A typical muscle cramp is painful but brief, and the muscle feels hard and knotted during the episode. It resolves on its own or with stretching, and the leg looks and feels normal afterward aside from mild soreness.
Deep vein thrombosis (a blood clot in a deep leg vein) can mimic a cramp but behaves differently. DVT pain is often a persistent cramping or soreness that starts in the calf and doesn’t go away with stretching. It typically comes with swelling in the leg, skin that looks red or purple, and a feeling of warmth in the affected area. Sometimes DVT causes no noticeable symptoms at all, which is what makes it tricky.
Cramps that are unusually frequent, happen in both legs, come with visible swelling or skin changes, or don’t respond to any of the prevention strategies above can also point to underlying conditions like vascular disease, nerve damage, or spinal problems. Persistent, unexplained cramping alongside numbness, tingling, or muscle weakness is worth getting evaluated.

