Best Foods for Leg Cramps: Electrolytes and More

The best foods for leg cramps are those rich in four key electrolytes: magnesium, potassium, calcium, and sodium. These minerals control how your muscle fibers contract and relax, and when levels run low, muscles are more likely to seize up. The good news is that a few targeted additions to your diet can make a real difference.

Why Electrolytes Matter for Muscle Cramps

Your muscles rely on a precise balance of calcium, magnesium, potassium, and sodium to fire and then release. Calcium triggers the contraction itself, while magnesium helps the muscle relax afterward. Potassium and sodium work together to transmit the electrical signals that tell the muscle when to do each. When any of these minerals dips too low, your muscles become more excitable and prone to involuntary, painful contractions.

This is why leg cramps often strike after heavy sweating, during pregnancy, or in people who eat a limited diet. The underlying problem is usually the same: not enough of the right minerals reaching the muscle.

Magnesium-Rich Foods

Magnesium is the mineral most closely tied to muscle relaxation, and it’s the one many people fall short on. Your body only absorbs about 30% to 40% of the magnesium you eat, so you need consistently good sources. The highest-impact foods per serving are seeds, nuts, and dark leafy greens.

Pumpkin seeds are the standout: a single ounce (a small handful) delivers 156 mg of magnesium, covering 37% of your daily value. Chia seeds provide 111 mg per ounce, and almonds or cashews land around 74 to 80 mg. Half a cup of cooked spinach gives you 78 mg, and the same amount of black beans provides 60 mg. Even two tablespoons of peanut butter add 49 mg.

For a practical daily strategy, sprinkle pumpkin seeds on a salad, snack on almonds, and include a serving of beans or lentils at dinner. That combination alone covers most of your magnesium needs. Whole grains like brown rice and oatmeal contribute smaller amounts (36 to 42 mg per serving) but add up over the course of a day. Refined grains like white rice provide far less, because processing strips out the magnesium-rich parts of the grain.

Potassium-Rich Foods

Potassium helps regulate the electrical signals that control muscle contractions. Bananas get all the credit, but several other foods deliver as much or more potassium along with bonus minerals.

Sweet potatoes are one of the best options because they pack potassium, calcium, and magnesium into a single food. Melons, especially cantaloupe and honeydew, provide potassium plus a high water content that helps with hydration. A baked potato with the skin on is another strong source, delivering potassium and 43 mg of magnesium. Bananas remain a solid choice and are easy to grab before bed or after a workout, though their magnesium content (32 mg) is modest compared to seeds and nuts.

Avocados, orange juice, and dried fruits like raisins round out the list. The key is variety: eating several moderate sources throughout the day is more effective than relying on one food.

Calcium Beyond Dairy

Calcium plays a direct role in muscle contraction. Most people think of milk and yogurt first, and those are fine sources (a cup of yogurt provides about 42 mg of magnesium as a bonus). But if you’re dairy-free or want more options, several plant foods deliver significant calcium.

Tofu made with calcium sulfate is the richest plant source, with 435 mg per half cup. Calcium-fortified orange juice provides around 250 mg per half cup. Collard greens and mustard greens offer about 110 mg per cooked half cup, and turnip greens come in at 100 mg. Navy beans deliver 125 mg per cup. Even five dried figs provide 70 mg.

Broccoli, kale, and spinach contribute smaller amounts of calcium but also supply magnesium, making them efficient choices for cramp prevention overall.

B Vitamins and Leg Cramps

Electrolytes get most of the attention, but B vitamins may also play a role, particularly for nighttime cramps. In a randomized, placebo-controlled trial of elderly patients with severe nocturnal leg cramps, 86% of those taking a B-complex supplement experienced significant remission after three months. The placebo group showed no improvement. The treatment reduced the frequency, intensity, and duration of cramps.

You can get these B vitamins from food. Good sources include poultry, fish, eggs, legumes, fortified cereals, and leafy greens. Vitamin B12 is found almost exclusively in animal products, so people following a plant-based diet may want to include fortified foods like nutritional yeast or fortified plant milks.

The Pickle Juice Trick

Pickle juice has a reputation for stopping cramps fast, and research supports it. As little as one tablespoon can abort a cramp within seconds, well before the liquid has time to leave your stomach and enter your bloodstream. That speed rules out electrolyte replacement as the explanation.

Instead, the acetic acid (vinegar) in pickle juice stimulates receptors in your mouth and throat, triggering a nerve reflex that travels through the vagus nerve and tells the overactive motor neurons in your cramping muscle to calm down. It works through your nervous system, not your mineral levels. This makes pickle juice useful as an in-the-moment remedy rather than a long-term prevention strategy. Mustard, which also contains acetic acid, appears to work through a similar mechanism.

What About Tonic Water?

Tonic water contains quinine, which was once prescribed for leg cramps. But the amount in commercial tonic water is far too low to help. A liter of tonic water contains no more than 83 mg of quinine, while the therapeutic dose used in medical settings was 500 to 1,000 mg. You’d need to drink several liters to approach a meaningful dose, and even then, quinine carries risks including heart rhythm changes. It’s not a practical or safe approach.

Hydration Ties It All Together

Even a diet rich in electrolytes won’t prevent cramps if you’re dehydrated. Water is the vehicle that carries minerals to your muscles and helps maintain the fluid balance your cells need to function. Dehydration concentrates your blood and disrupts that balance, making cramps more likely.

If you exercise heavily, fluid replacement should start before your workout and continue during and after. Drinking about 200 to 300 ml (roughly 7 to 10 ounces) every 10 to 20 minutes during exercise helps keep pace with sweat losses. Post-workout, aim to rehydrate within two hours using fluids or foods that contain some sodium, which stimulates thirst and helps your body retain the fluid you take in. Water-rich foods like melons, cucumbers, and oranges contribute to both hydration and electrolyte intake at the same time.

Putting a Cramp-Prevention Plate Together

Rather than fixating on a single food, the most effective approach is building meals that cover multiple electrolytes at once. A few combinations that do this well:

  • Spinach salad with pumpkin seeds, avocado, and almonds delivers magnesium, potassium, and calcium in a single bowl.
  • Black bean tacos with sautéed greens provide magnesium, calcium, and fiber.
  • A smoothie with banana, yogurt, and peanut butter covers potassium, calcium, magnesium, and B vitamins.
  • Baked sweet potato with a side of steamed broccoli supplies potassium, calcium, and magnesium with high water content.

Consistency matters more than any single meal. Leg cramps, especially the nighttime variety, tend to improve when your mineral intake is steady over weeks rather than corrected in a single day. If cramps are a recurring problem, tracking your intake of magnesium-rich foods for a week often reveals the gap. For most people, adding a daily handful of seeds or nuts and one extra serving of leafy greens is enough to notice a difference.