What to Eat for Leg Cramps: Magnesium, Potassium, and More

Leg cramps are most often linked to shortfalls in three key minerals: magnesium, potassium, and sodium. Eating foods rich in these nutrients, staying well hydrated, and getting enough B vitamins can reduce how often cramps strike and how intense they feel. Here’s what to put on your plate and why it helps.

Magnesium: The Most Important Mineral for Cramps

Magnesium plays a direct role in muscle relaxation. When levels drop too low, muscles contract more easily and have trouble releasing, which is exactly what a cramp is. Adults need about 420 mg of magnesium per day, and many people fall short without realizing it.

The fastest way to close that gap is through seeds, nuts, and leafy greens. One ounce of roasted pumpkin seeds delivers 156 mg of magnesium, covering 37% of your daily needs in a single handful. An ounce of chia seeds provides 111 mg (26%), and an ounce of dry-roasted almonds adds 80 mg (19%). Half a cup of boiled spinach comes in at 78 mg, and the same amount of black beans provides 60 mg.

Less obvious sources add up over the course of a day. A baked potato with the skin on has 43 mg. A cup of plain low-fat yogurt or half a cup of brown rice each contribute about 42 mg. Even a medium banana provides 32 mg. Two tablespoons of peanut butter give you 49 mg. None of these are powerhouses on their own, but stacking several of them across meals makes hitting 420 mg realistic without supplements.

Potassium-Rich Foods That Prevent Cramping

Potassium works alongside magnesium to regulate muscle contractions. Low potassium, a condition called hypokalemia, is specifically flagged as a cause of leg cramps. Adults generally need around 2,600 to 3,400 mg per day depending on sex and age.

Many of the best potassium sources overlap with magnesium-rich foods, which makes meal planning easier. Potatoes (with the skin), bananas, avocados, black beans, and spinach all deliver significant amounts of both minerals. Sweet potatoes, oranges, tomatoes, and dried apricots are additional potassium standouts. Dairy products like yogurt and milk contribute meaningful amounts too.

A practical approach: build meals around a starchy vegetable (potato or sweet potato), a leafy green (spinach or Swiss chard), and a serving of beans or lentils. That combination alone covers a large percentage of both your magnesium and potassium needs.

Sodium and Electrolytes After Sweating

If your leg cramps tend to happen during or after exercise, sodium loss from sweat is a likely culprit. This is especially true if you exercise for more than two hours, sweat heavily, or notice white salt residue on your clothes after a workout.

The American College of Sports Medicine recommends 300 to 600 mg of sodium per hour during prolonged exercise. In hot or humid conditions (above 77°F or 60% humidity), you may need the higher end of that range. A simple trick: adding about half a teaspoon of table salt to 32 ounces of a sports drink boosts sodium concentration without making it taste bad.

For everyday meals, you don’t need to aggressively salt your food unless you’re losing a lot of sweat. But if you eat a very low-sodium diet and exercise regularly, you may be setting yourself up for cramps. Broth, olives, pickles, and salted nuts are easy ways to replace what you sweat out.

B Vitamins and Muscle Function

Two B vitamins have a specific connection to cramping. A vitamin B1 (thiamine) deficiency can cause aching and cramping in the lower legs. Vitamin B12 deficiency can trigger muscle cramps throughout the body. Both vitamins support nerve signaling, and when nerves misfire, muscles can seize up.

B1 is found in whole grains, pork, black beans, and fortified cereals. B12 comes primarily from animal products: meat, fish, eggs, and dairy. If you eat a plant-based diet, B12 is the one to watch, since reliable plant sources are limited to fortified foods like nutritional yeast and plant milks. Most people eating a varied diet get enough B1 without thinking about it.

Hydration Makes Everything Else Work

Even if your mineral intake is perfect, dehydration can still trigger cramps. Water helps transport electrolytes into muscle cells, so falling behind on fluids effectively creates a mineral deficit at the muscle level even when your overall intake is fine.

A useful formula from Mass General Brigham: multiply your body weight in pounds by 0.67 to get the number of ounces of water you need per day. Then add 12 ounces for every 30 minutes of exercise. A 150-pound person who works out for an hour would need roughly 125 ounces. That sounds like a lot, but food contributes some of that fluid, and spreading intake across the day makes it manageable.

You can also check your urine color. Pale straw yellow means you’re well hydrated. Deeper yellow or golden means you need more fluids. During exercise, aim for 6 to 12 ounces of fluid every 20 minutes, and drink 16 to 24 ounces of water or a sports drink in the two hours before activity. Afterward, the ideal target is 24 ounces of fluid for every pound of body weight you lost during the session.

Alcohol and caffeine both promote fluid loss and are worth cutting back on if nighttime leg cramps are a recurring problem. Cleveland Clinic specifically recommends avoiding both for cramp prevention.

Pickle Juice: A Surprisingly Fast Fix

If you’re looking for something that stops a cramp in the moment rather than preventing one over time, pickle juice has real science behind it. Research from Michigan Medicine found that just one tablespoon of pickle juice can shut down an active cramp. The mechanism isn’t about replacing electrolytes. It’s the acid in the brine triggering nerves in the back of the throat, which sends a signal that essentially tells the cramping muscle to relax.

This works within seconds, much faster than any mineral could be absorbed through digestion. Keeping a small jar of pickle juice in the fridge is a practical backup for people who get cramps at night. Mustard, which contains a similar type of acid (vinegar), is sometimes used the same way, though the evidence is strongest for pickle juice specifically.

A Sample Day for Cramp Prevention

Putting this together doesn’t require a dramatic overhaul. Here’s what a cramp-fighting day of eating might look like:

  • Breakfast: Oatmeal (36 mg magnesium) topped with a tablespoon of chia seeds (about 55 mg) and a banana (32 mg), plus a glass of milk or fortified plant milk.
  • Lunch: A spinach salad with black beans, avocado, and pumpkin seeds. This single meal can deliver over 200 mg of magnesium along with substantial potassium.
  • Snack: A handful of almonds or cashews with a piece of fruit.
  • Dinner: Baked salmon with a skin-on potato and steamed broccoli. The potato alone adds 43 mg of magnesium plus a strong dose of potassium.

That combination comfortably exceeds 420 mg of magnesium for the day, delivers a large share of your potassium needs, and includes B vitamins from the whole grains, greens, and salmon. Pair it with adequate water intake and you’ve addressed the most common nutritional triggers for leg cramps without any supplements.

What to Limit

Some foods and drinks work against you. Alcohol is a diuretic that depletes both fluids and magnesium. Excessive caffeine does the same, though moderate amounts (a cup or two of coffee) are generally fine. Highly processed diets tend to be low in magnesium and potassium while being high in sodium, which creates an electrolyte imbalance rather than a healthy balance. Refined grains like white rice have a fraction of the magnesium found in their whole-grain counterparts: white rice has just 10 mg per half cup compared to 42 mg in brown rice.

Swapping white rice for brown, choosing whole wheat bread over white, and replacing sugary snacks with nuts or seeds are small changes that shift the mineral balance in the right direction over time.