Most cramps, whether they strike your calf at 3 a.m. or your abdomen during a workout, trace back to a shortage of specific minerals, inadequate hydration, or both. The foods that stop and prevent cramps are rich in potassium, magnesium, and sodium, the three electrolytes your muscles need to contract and relax properly. Eating more of these foods, and drinking enough fluid to absorb them, is the most reliable dietary fix.
Why Electrolytes Control Your Muscles
Your muscles contract when nerve signals trigger a flow of sodium and calcium into muscle cells. They relax when potassium and magnesium help flush those signals out. When any of these minerals runs low, the “off switch” for a contraction can malfunction, leaving the muscle locked in a painful spasm. Sweating makes things worse because you lose sodium and potassium in sweat faster than most people replace them.
Dehydration alone can set the stage. A study in BMJ Open Sport & Exercise Medicine found that drinking plain water after heavy sweating actually made muscles more susceptible to cramping, while a drink containing electrolytes (sodium, potassium, and magnesium) reversed that effect. The takeaway: water matters, but minerals matter just as much.
Best Foods for Potassium
Potassium is the mineral most people fall short on. Adults need roughly 2,600 to 3,400 mg per day, and a single food swap can close a big chunk of that gap. The highest-potassium foods per serving, drawn from Dietary Guidelines data, include:
- Baked potato with skin (1 medium): 926 mg
- Cooked spinach (1 cup): 839 mg
- Cooked sweet potato (1 cup): 572 mg
- Plain nonfat yogurt (8 oz): 625 mg
- Banana (1 medium): 451 mg
- Cantaloupe (1 cup): 473 mg
- Orange juice (1 cup): 496 mg
- Cooked lima beans (1 cup): 955 mg
- Acorn squash (1 cup): 896 mg
Bananas get all the credit, but a baked potato delivers more than double the potassium. Cooked greens like spinach and Swiss chard (961 mg per cup) are even more potent. If you’re cramping regularly, adding one or two of these foods daily is a practical first step.
Best Foods for Magnesium
Magnesium helps muscles relax after contraction and plays a role in over 300 enzyme reactions in the body. Your body only absorbs about 30% to 40% of the magnesium you eat, so getting enough from food takes some intention. The richest sources, per the NIH:
- Pumpkin seeds, roasted (1 oz): 156 mg
- Chia seeds (1 oz): 111 mg
- Almonds, dry roasted (1 oz): 80 mg
- Cashews, dry roasted (1 oz): 74 mg
- Spinach, cooked (½ cup): 78 mg
- Black beans, cooked (½ cup): 60 mg
- Edamame (½ cup): 50 mg
- Peanut butter (2 tbsp): 49 mg
- Brown rice (½ cup): 42 mg
A small handful of pumpkin seeds as a snack gets you nearly 40% of a typical daily target. Spinach pulls double duty here, ranking high for both potassium and magnesium, making it one of the single best anti-cramp foods you can eat. If you’re considering a supplement instead, forms like magnesium citrate or magnesium chloride are absorbed more completely than magnesium oxide.
Sodium and Hydration Together
Sodium gets a bad reputation, but if you sweat heavily during exercise or in hot weather, you lose significant amounts of it. Replacing only water without sodium can dilute what’s left in your bloodstream and make cramping worse. This is why sports drinks and oral rehydration solutions contain sodium alongside other electrolytes.
A practical hydration formula from Mass General Brigham: take your body weight in pounds, multiply by 0.67, and that’s roughly how many ounces of water you need per day. Add 12 ounces for every 30 minutes of exercise. On heavy sweat days, include a pinch of salt in your water, eat salty snacks like pretzels or olives, or use an electrolyte drink. Research has shown that adding about half a tablespoon of salt to a liter of electrolyte beverage before and during exercise delayed the onset of cramps and extended exercise time compared to drinking nothing.
Pickle Juice: The Unexpected Remedy
If you’ve heard that pickle juice stops cramps fast, the evidence backs it up. Anecdotal reports suggest it works within about 35 seconds, far too quickly for the sodium to be digested and absorbed. Researchers at Brigham Young University concluded that the strong vinegar taste likely triggers a reflex in the mouth and throat that sends a signal through the nervous system to shut down the overactive nerve firing that causes the cramp. It’s not about the salt content at all. It’s a neurological trick.
You don’t need much. A few ounces (about a shot glass worth) is the typical amount used in studies. Mustard, which contains vinegar and similar pungent compounds, appears to work through the same mechanism, which is why some athletes keep mustard packets in their gym bags.
What to Eat for Period Cramps
Menstrual cramps have a different cause than muscle cramps. The uterus contracts to shed its lining, driven by hormone-like molecules called prostaglandins. Higher prostaglandin levels mean stronger, more painful contractions. The dietary strategy here shifts from electrolytes to reducing inflammation.
Vitamin D appears to lower prostaglandin production directly. A 2023 meta-analysis found that women who took high doses of vitamin D had meaningful relief from period pain regardless of how long they supplemented. Food sources of vitamin D include salmon, trout, tuna, mackerel, egg yolks, and fortified milk. Mushrooms contain some vitamin D too, and you can boost their levels by placing them in direct sunlight for 15 minutes to two hours before eating them.
Omega-3 fatty acids from fatty fish (salmon, sardines, mackerel) also help tamp down the inflammatory pathways that make cramps worse. Pairing these with magnesium-rich foods like dark leafy greens and nuts addresses both the inflammation and the muscle tension side of period pain. Foods to limit during your period include highly processed snacks, excess caffeine, and alcohol, all of which can increase inflammation or worsen dehydration.
What to Eat for Stomach and Digestive Cramps
Cramps in the digestive tract involve smooth muscle rather than skeletal muscle, so the approach is different. Peppermint is one of the best-studied remedies for intestinal spasms. It relaxes the smooth muscle lining your gut, easing the cramping sensation. Peppermint oil capsules are widely available, and the NHS recommends one capsule three times daily, taken 30 to 60 minutes before eating. You can also drink peppermint tea, though it delivers a lower concentration of the active compounds.
Ginger is another option for stomach cramps, particularly when nausea is involved. Fresh ginger steeped in hot water for 10 minutes makes a simple tea. For digestive cramps tied to bloating or gas, cooked vegetables are generally easier to tolerate than raw ones, and fermented foods like yogurt and kefir can support the gut bacteria that help regulate digestion.
Vitamin Deficiencies That Cause Cramps
Sometimes cramps persist despite eating well, and a vitamin deficiency may be the reason. Vitamin B12 deficiency is an underrecognized cause of painful leg spasms, especially at night. In one clinical case published in the journal Neurology, a patient with an eight-month history of severe nocturnal calf and thigh spasms saw full resolution within four weeks of B12 supplementation after blood tests confirmed low levels. B12 is found in meat, fish, eggs, and dairy. People who eat little or no animal products are at higher risk of deficiency.
Vitamin D deficiency is similarly linked to muscle cramps and weakness. Because relatively few foods are naturally rich in vitamin D, and because your body produces it primarily through sun exposure, deficiency is common, particularly in winter months and among people with darker skin. If cramps are frequent and your diet seems adequate in electrolytes, asking for a blood test to check B12 and vitamin D levels is a reasonable next step.
Putting It All Together
A cramp-prevention plate doesn’t need to be complicated. A baked potato with skin, a side of cooked spinach, and a piece of salmon covers potassium, magnesium, vitamin D, and omega-3s in a single meal. Snack on a handful of pumpkin seeds or almonds, drink water matched to your activity level, and add electrolytes on heavy sweat days. For acute cramps that hit suddenly, a shot of pickle juice or a spoonful of mustard can interrupt the spasm within seconds through a nerve reflex, buying you time to address the underlying shortfall in your diet.

