Muscle spasms are involuntary contractions that happen when a muscle fires without your brain telling it to. The causes range from something as simple as overworking a muscle during exercise to electrolyte imbalances, dehydration, medication side effects, and underlying neurological conditions. Most spasms are harmless and resolve on their own, but understanding the trigger helps you prevent them from recurring.
How Muscles Contract (and Misfire)
Normal muscle contraction is a tightly controlled chain reaction. A nerve signal travels to the end of a motor nerve, where calcium ions flood into the nerve terminal. That calcium triggers the release of a chemical messenger called acetylcholine, which crosses a tiny gap and binds to receptors on the muscle fiber. This binding opens channels that let charged ions rush in, creating an electrical signal that makes the muscle contract.
A spasm happens when something disrupts this chain. If the nerve becomes overly excitable, if calcium or other ion levels are off, or if the feedback loop that tells a muscle to relax gets overridden, the muscle contracts on its own and stays locked. That’s the sudden, sometimes painful tightening you feel in a calf, foot, or back muscle.
Electrolyte Imbalances
Your muscles depend on a precise balance of minerals to contract and relax properly. Three electrolytes play the biggest roles: potassium supports nerve and muscle signaling, magnesium helps regulate nerve impulses to muscles, and calcium is essential for the contraction mechanism itself. When any of these drop too low, muscles become more excitable and prone to involuntary firing.
Electrolyte levels can shift for many reasons. Heavy sweating, vomiting, diarrhea, and poor dietary intake all drain these minerals. Certain medications, especially diuretics, accelerate the loss. Kidney problems can throw off the balance as well. Symptoms of an electrolyte imbalance go beyond spasms and often include general weakness, fatigue, and irregular heartbeat, so recurrent spasms alongside those signs point toward something worth investigating with a blood test.
Exercise and Muscle Fatigue
If you’ve ever had a calf or hamstring lock up during a run or a long bike ride, you’ve experienced exercise-associated muscle cramps. For decades, the standard explanation was dehydration or salt loss through sweat. The evidence tells a different story.
A review in the British Journal of Sports Medicine examined four prospective studies and found no significant difference in blood electrolyte concentrations between athletes who cramped and those who didn’t. Athletes with cramps were also no more dehydrated than their non-cramping counterparts. One key observation: exercise cramps almost always hit the specific muscles being worked hardest, not the whole body. If dehydration or electrolyte depletion were the cause, you’d expect widespread symptoms, since those are systemic problems.
The stronger explanation is altered neuromuscular control. As a muscle fatigues, excitatory signals to the nerve increase while inhibitory signals (the ones that tell the muscle to calm down) decrease. The result is an uncontrolled burst of activity in the fatigued muscle. This is why cramps tend to strike late in a workout, during a race you haven’t trained enough for, or when you suddenly increase intensity. Pacing yourself, building endurance gradually, and stretching the affected muscle during a cramp all work with this mechanism.
Dehydration and Fluid Balance
Dehydration alone may not directly cause cramps during exercise, but what you drink afterward matters. A study published in BMJ Open Sport & Exercise Medicine had participants run in 35°C heat until they lost 2% of their body weight. Immediately after running, cramp susceptibility hadn’t changed. But when participants rehydrated with plain water, their muscles became significantly more prone to cramping within 30 to 60 minutes. When they drank a fluid containing electrolytes instead, cramp susceptibility actually decreased.
The likely explanation is dilution. Drinking plain water after heavy sweating lowers the concentration of sodium and chloride in your blood, which makes nerves more excitable. This doesn’t mean you should avoid water. It means that after prolonged sweating, replacing electrolytes alongside fluid is more protective than water alone.
Medications That Trigger Spasms
A surprisingly long list of medications can cause or contribute to muscle spasms. Some of the most common categories include:
- Blood pressure medications: certain beta-blockers and angiotensin II receptor blockers
- Diuretics: by depleting potassium, magnesium, and other electrolytes
- Cholesterol-lowering statins: lovastatin and related drugs are well-known for muscle complaints
- Stimulants: caffeine, amphetamines, nicotine, pseudoephedrine, cocaine, and ephedrine
- Bronchodilators: used for asthma
- Hormonal medications: oral contraceptives and synthetic parathyroid hormone
- Sedatives: alcohol, barbiturates, and benzodiazepines
If your spasms started or worsened around the time you began a new medication, that’s a connection worth raising with your prescriber. Diuretics and statins are among the most frequently prescribed drugs in the world, and muscle symptoms are one of the top reasons people stop taking them.
Neurological and Medical Conditions
Most muscle spasms are benign, but persistent or worsening spasms can be an early sign of a neurological condition. Multiple sclerosis damages the insulating coating around nerves, which disrupts signals and can produce stiffness and spasms, particularly in the legs. Amyotrophic lateral sclerosis (ALS) affects the motor neurons that control voluntary movement, and muscle twitching or cramping is often one of the first symptoms people notice. Dystonia, a movement disorder that causes sustained involuntary contractions, is typically diagnosed by a neurologist through a combination of physical examination, blood and urine tests, and brain imaging.
Other medical conditions linked to spasms include thyroid disorders, kidney disease, liver cirrhosis, peripheral artery disease (where reduced blood flow to the legs triggers cramps during walking), and nerve compression in the spine. Diabetes can damage peripheral nerves over time, making muscles more prone to cramping. Even chronic alcohol use contributes, both through direct nerve toxicity and by depleting key nutrients.
Does Magnesium Supplementation Help?
Magnesium is one of the most popular over-the-counter remedies for muscle cramps, but the clinical evidence is disappointing. A Cochrane review, widely considered the gold standard for evaluating medical treatments, pooled results from five well-designed studies and concluded with moderate certainty that magnesium supplementation is unlikely to meaningfully reduce the frequency or severity of muscle cramps in older adults.
Across these trials, magnesium didn’t outperform placebo for cramp frequency, intensity, or duration. One study comparing magnesium to no treatment at all also found no benefit. Meanwhile, participants taking magnesium were more likely to experience minor side effects, mostly digestive issues like diarrhea. For cramps during pregnancy, the evidence was mixed and inconclusive. If you have a confirmed magnesium deficiency, supplementing makes sense for overall health, but taking magnesium specifically to stop cramps is unlikely to help if your levels are already normal.
Warning Signs That Need Attention
Occasional cramps in the calves or feet, especially after exercise or during the night, are extremely common and rarely signal anything serious. Certain patterns, however, warrant a closer look. Spasms that affect the arms, trunk, or muscles you weren’t using are less typical than calf cramps and deserve evaluation. Muscle weakness that develops alongside the spasms, visible muscle wasting, or twitching (fasciculations) that doesn’t stop can point toward a motor neuron problem.
Pain, numbness, or tingling that follows the path of a specific nerve suggests nerve compression or damage rather than a simple cramp. Spasms accompanied by signs of significant fluid loss, such as dizziness, rapid heart rate, or very dark urine, indicate that dehydration or electrolyte depletion may be severe enough to need medical treatment. And if cramps are frequent enough to disrupt your sleep or daily activities, that alone is reason enough to investigate the cause rather than just stretching through it.

