Muscle cramps are sudden, involuntary contractions that occur in various muscles. These contractions are often painful and can affect different muscle groups.

Commonly affected muscles include those in the back of your lower leg, the back of your thigh, and the front of your thigh.

You may also experience cramps in your:

  • abdominal wall
  • arms
  • hands
  • feet

The intense pain of a cramp can awaken you at night or make it difficult to walk.

A sudden, sharp pain, lasting from a few seconds to 15 minutes, is the most common symptom of a muscle cramp. In some cases, a bulging lump of muscle tissue beneath the skin can accompany a cramp as well.

Muscle cramps have several causes. Some cramps result from overuse of your muscles. This typically occurs while you’re exercising.

Muscle injuries and dehydration can also trigger cramps. Dehydration is the excessive loss of fluids in the body.

Low levels of any of the following minerals that contribute to healthy muscle function may also cause muscle cramps:

Low blood supply to your legs and feet can cause cramping in those areas when you exercise, walk, or participate in physical activities.

In some cases, a medical condition can cause muscle cramps. These conditions include:

Other times, the cause of muscle cramps is unknown.

Muscle cramps are usually harmless and don’t require medical attention. However, you should see a doctor if your muscle cramps are severe, don’t improve with stretching, or persist for a long time. This could be a sign of an underlying medical condition.

To learn the cause of muscle cramps, your doctor will perform a physical examination. They may ask you questions, such as:

You may also need a blood test to check the levels of potassium and calcium in your blood, as well as your kidney and thyroid function. You may also take a pregnancy test.

Your doctor may order an electromyography (EMG). This is a test that measures muscle activity and checks for muscle abnormalities. An MRI may also be a helpful test. It’s an imaging tool that creates a picture of your spinal cord.

On occasion, a myelogram, or myelography, another imaging study, might be helpful.

Let your doctor know if you’re experiencing weakness, pain, or a loss of sensation. These symptoms can be signs of a nerve disorder.

You can apply a hot or cold compress to your sore muscles at the first sign of a spasm to ease the pain of muscle cramps. You can use any of the following:

Stretching the affected muscle can also alleviate the pain of muscle cramps. For example, if your calf is cramping, you could pull your foot upward with your hand to stretch the calf muscle.

If your pain doesn’t improve, try taking an over-the-counter, anti-inflammatory medication, such as ibuprofen. It may also help to stretch the sore muscles gently.

Muscle cramps can interrupt your sleep. If this happens, talk to your doctor about a prescription muscle relaxer. This medication helps relax your muscles and calm spasms.

Controlling the underlying cause of muscle cramps can improve your symptoms and ease spasms. For example, your doctor may recommend supplements if low calcium or potassium levels are triggering cramps.

Shop for calcium and potassium supplements.

The simplest way to prevent muscle cramps is to avoid or limit the exercises that strain your muscles and cause cramps.

You can also:

  • Stretch or warm up before participating in sports and exercising. Failure to warm up can result in muscle strain and injury.
  • Don’t exercise right after eating.
  • Lower your intake of food and drink that contains caffeine, such as coffee and chocolate.
  • Make sure that you drink enough liquid to avoid dehydration. Your body loses more water when physically active, so increase your liquid intake when you exercise.
  • Increase your calcium and potassium intake naturally by drinking milk and orange juice and eating bananas.
  • Talk to your doctor about taking a vitamin supplement to ensure that your body receives the necessary supply of nutrients and minerals.

Shop for multivitamins.