How to Treat a Muscle Spasm: Relief and Prevention

To treat a muscle spasm, stretch the affected muscle and massage it firmly until the contraction releases. Most spasms resolve within seconds to a few minutes with these two steps alone. There’s no pill or injection that instantly stops a spasm, but several strategies can ease the pain afterward and reduce how often spasms happen in the first place.

Stop a Spasm in the Moment

When a muscle locks up, your first move is to gently stretch it in the opposite direction of the contraction. If your calf cramps, flex your foot upward toward your shin. If your hamstring seizes, straighten your leg. If your hand cramps, spread your fingers wide and press them flat against a surface. Hold the stretch until the spasm breaks, which usually takes 15 to 30 seconds.

Once the muscle releases, massage the area with your hands or a foam roller using slow, firm pressure. This helps the muscle fibers relax fully and improves blood flow to the area. If the spasm happened during exercise, stop the activity and let the muscle rest before putting it under load again.

Heat, Ice, or Both

After a spasm passes, applying warmth helps the muscle loosen and reduces lingering tightness. A warm towel, heating pad, or warm bath all work. If the muscle feels sore or slightly swollen afterward, cold therapy can help with pain. Wrap ice in a damp towel (never place ice directly on skin) and apply it for 15 to 20 minutes.

One important timing rule from Johns Hopkins Medicine: if the spasm was triggered by an acute injury, avoid heat for the first 48 hours. Use cold during that window, then switch to heat once the initial inflammation settles. For spasms not tied to injury, heat is typically the better first choice because it promotes blood flow and relaxation in the muscle.

Over-the-Counter Pain Relief

If a spasm leaves you sore, ibuprofen (Advil, Motrin) or naproxen (Aleve) can reduce both pain and any minor swelling. These are NSAIDs, which work by dialing down inflammation. Acetaminophen (Tylenol) handles pain but won’t address swelling.

Always check the label for your maximum daily dose. For acetaminophen, the ceiling is 4,000 mg per day for healthy adults, which works out to about six extra-strength tablets. People with liver disease should stay under 2,000 mg. NSAIDs carry their own limits and can irritate the stomach, so follow the package directions carefully rather than stacking doses when the pain lingers.

Hydration and Electrolytes

Dehydration is one of the most common and fixable causes of muscle spasms, especially during exercise or hot weather. A practical 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 160-pound person, for example, would aim for about 107 ounces on a rest day and more on active days.

Plain water isn’t always enough. When you sweat heavily, you lose sodium and other electrolytes that your muscles need to contract and relax properly. High-sodium sports drinks are formulated to replace those salts. Drinking large volumes of plain water without replacing sodium can actually dilute your blood sodium to dangerously low levels, a condition called hyponatremia. If you’re exercising for more than an hour or sweating heavily, adding a sodium-containing beverage is a smart move.

Daily Stretching to Prevent Spasms

Regular stretching is one of the most effective ways to reduce how often spasms happen. The muscles that cramp most frequently, calves, hamstrings, and the muscles along the spine, all respond well to a daily routine.

There are two types worth incorporating. Dynamic stretches involve flowing, repetitive movements and work best as a warm-up. Spend 10 to 15 minutes loosening up before activity. Static stretches, where you hold a position for 20 to 30 seconds without bouncing, are ideal after exercise or before bed. A few high-value static stretches:

  • Calves: Do a deep lunge with your back heel planted flat on the ground. You should feel the stretch along the back of your lower leg.
  • Hamstrings: Sit on the floor with your legs straight in front of you and reach toward your toes.
  • Chest and shoulders: Clasp your hands behind your back, straighten your arms, and lift them toward the ceiling.

Doing these daily, even on days you don’t exercise, helps keep muscles flexible and less prone to involuntary contraction. Harvard Health recommends treating stretching as a preventive habit rather than something you only do when pain shows up.

Does Magnesium Help?

Magnesium is the most widely discussed supplement for muscle cramps, but the evidence is more nuanced than the marketing suggests. A 2021 randomized controlled trial of 184 people with nighttime leg cramps found that 226 mg of magnesium oxide taken daily did reduce cramp frequency, from about 5.4 cramps per week down to 1.9. The placebo group dropped from 6.4 to 3.7, so magnesium outperformed doing nothing, but the benefit only became significant after 60 days of consistent use.

Short courses of magnesium, anything under two months, have not shown meaningful benefit for leg cramps in clinical trials. If you want to try magnesium, commit to at least 60 days before judging whether it’s working. And keep in mind that if your spasms are caused by dehydration, poor stretching habits, or overuse, magnesium alone won’t solve the underlying problem.

Prescription Muscle Relaxants

There are no over-the-counter muscle relaxants available in the United States. If your spasms are frequent, severe, or tied to an underlying condition like a back injury or neurological disorder, a doctor may prescribe a muscle relaxant. These medications work on the nervous system to reduce the signals that cause muscles to contract involuntarily. They tend to cause drowsiness and are generally prescribed for short-term use alongside physical therapy rather than as a long-term fix.

When Spasms Signal Something Bigger

Most muscle spasms are harmless, caused by overuse, dehydration, or holding an awkward position too long. But certain patterns deserve medical attention. Spasms that happen frequently without an obvious trigger, affect muscles throughout your body rather than one area, don’t respond to stretching and hydration over several weeks, or come with weakness, numbness, or swelling could point to an underlying issue like nerve compression, circulation problems, or an electrolyte imbalance that needs lab work to identify.

A single charley horse after a long run is normal. Waking up multiple nights a week with cramps that aren’t improving with the strategies above is worth bringing up with your doctor, who can check for treatable causes you might not identify on your own.