While most muscle cramps occur due to idiopathic (unknown) causes, they are often linked with factors such as exercise, muscle overuse, straining, and diet. Muscle cramps can also occur in people with low levels of certain vitamins.
Grace Cary / Getty Images

1. Magnesium Deficiency
Magnesium is an essential mineral that virtually every organ in your body needs to regulate good health. It supports normal body functions likeblood pressure,blood glucose control, bone health, and muscle and nerve function. Amagnesium deficiency, also called hypomagnesemia, occurs when your magnesium levels are lower than the amount needed to support these functions.
Magnesium is naturally present in many foods and beverages. It is also added to some foods and other products such as antacids andlaxatives. A magnesium deficiency is unlikely to occur in healthy people who consume a well-balanced diet. Instead, magnesium deficiency is typically linked to health conditions that include:
In addition to muscle cramps,symptoms of a magnesium deficiencycan include:
Your healthcare provider can diagnose a magnesium deficiency with amagnesium blood test. Depending on your results, the following strategies may be effective in restoring normal magnesium levels:
Magnesium for Muscle Pain
2. Vitamin D Deficiency
Vitamin D is a fat-soluble vitamin obtained from sun exposure, foods, and supplements. “Vitamin D” is an umbrella term for two different forms of the vitamin:vitamins D2 and D3. They both promotecalciumabsorption in your gut and support your nervous, immune, and muscle systems. The inadequate calcium and phosphorus absorption that occurs with a vitamin D deficiency can lead to brittle bones and muscle weakness.
A vitamin D deficiency can occur as a result of any of the following reasons:
A vitamin D deficiency can be asymptomatic in many people. When symptoms occur, they can include:
Your healthcare provider can diagnose a vitamin D deficiency with a blood test. The diagnosis is sometimes reached with X-rays. Your healthcare provider may advise one or more of the following treatments to reverse a vitamin D deficiency:
Vitamin D vs. D3: What’s the Difference?
3. Vitamin B Deficiency
Vitamin B includes a group of eight vitamins that are important to converting food into energy. Together, they are called the vitamin B complex. Since each B vitamin has a unique function, the impact of a vitamin B deficiency can vary based on the specific B vitamin you are lacking. Muscle cramps are most likely to occur from a vitaminB12 (cobalamin)deficiency.
Vitamin B12 naturally occurs in foods that originate from animal sources such as meat, fish, poultry, dairy products, and eggs. While plants do not contain vitamin B12 naturally, many breakfast cereals and nutritional yeasts are fortified with vitamin B12.
Research indicates that a vitamin B12 deficiency can occur with a heterogeneous list of symptoms. The most prevalent symptoms include:
Causes of a vitamin B12 deficiency are most often linked to one of the following problems:
Blood tests are used to diagnose a vitamin B12 deficiency. Based on your condition, your healthcare provider may advise one or more of the following treatments:
The Best Sources of Vitamin B12 for Any Diet
Other Common Causes of Muscle Cramps
Insufficient Stretching
Muscle cramps can occur as a result of an intense workout or other physical activity. Your muscles consist of bundles of fibers that expand and contract to produce movement. Regular stretching lengthens muscle fibers so they can contract and tighten during exercise.
Muscle Fatigue
Skeletal overload andmuscle fatiguecan trigger muscle cramping in overworked muscle fibers. When a tight muscle tries to relax, it can begin to contract more than normal and cause a cramp. This often occurs if the muscle is out of shape and being exercised after a lengthy period of inactivity or underuse. It is often the case for athletes, who are more likely to develop cramps in the preseason when their bodies are not well-conditioned.
Sedentary Lifestyle
Research indicates a strong association between a sedentary lifestyle and nighttime leg cramps. People who live a sedentary lifestyle are more likely to have muscle weakness in their lower limbs, a factor that is linked with nighttime leg cramps.
Heat, Dehydration, and Loss of Electrolytes
Muscle cramps are more likely to occur in hot weather when you have a higher risk of dehydration. The loss of fluids, salt, andelectrolytesthat occurs with sweating in hot weather or during intense physical activity can cause a muscle to spasm, especially when these substances are not immediately replenished.
Muscle Atrophy (Loss)
The muscle atrophy that starts in your mid-40s and continues with aging is accelerated with inactivity. With aging, your muscles can’t work as hard or respond as quickly as they previously had. Aging also decreases your body’s sense of thirst and your ability to sense and respond to temperature changes, making you less likely to replenish lost fluids.
Use of Certain Medications and Other Substances
Certain medications and substances can contribute to the onset of muscle cramps. Examples of these substances include:
Health Conditions
The following health conditions can contribute to the onset of muscle cramps:
Causes of Muscle Spasms and Cramps
Ways to Prevent Muscle Cramps
You can help prevent the onset of muscle cramps and reduce your risk of having these painful problems with the following strategies:
Leg Cramps at Night: Getting to the Bottom of Sharp, Aching Pain
Summary
While most muscle cramps are brief and not harmful, they can cause severe pain and debilitation when they occur. Working to prevent muscle cramps can help you enjoy movement during the day and avoid the interruption of muscle cramps at night.
While the exact cause of muscle cramps is unknown, they may occur as a symptom of certain vitamin deficiencies. Other factors, such as muscle fatigue, inadequate stretching before exercise, and loss of body fluids can also trigger muscle cramps.
Most muscle cramps resolve on their own without the need for medical treatment. However, muscle cramps can also occur as a symptom of an underlying health problem. Contact your healthcare provider if you have muscle cramps that are severe, frequent, constant, or concerning.
16 Sources
Verywell Health uses only high-quality sources, including peer-reviewed studies, to support the facts within our articles. Read oureditorial processto learn more about how we fact-check and keep our content accurate, reliable, and trustworthy.
Scripps Health.4 things that trigger muscle spasms and cramps.
National Institutes of Health Office of Dietary Supplements.Magnesium.
MedlinePlus.Magnesium deficiency.
Ahmed F, Mohammed A.Magnesium: the forgotten electrolyte—a review on hypomagnesemia.Med Sci. 2019;7(4):56. doi:10.3390/medsci7040056
Yale Medicine.Vitamin D deficiency.
National Institutes of Health Office of Dietary Supplements.Vitamin D.
Merck Manual Consumer Version.Vitamin D deficiency.
Wolffenbuttel BHR, Wouters HJCM, Heiner-Fokkema MR, van der Klauw MM.The many faces of cobalamin (vitamin B12) deficiency.Mayo Clin Proc Innov Qual Outcomes. 2019;3(2):200-214. doi:10.1016/j.mayocpiqo.2019.03.002
National Institutes of Health Office of Dietary Supplements.Vitamin B12.
American Academy of Orthopaedic Surgeons (AAOS).Muscle cramps.
Houston Methodist.Muscle cramps: 8 things that cause them and 4 ways to stop them.
Delacour C, Chambe J, Lefebvre F, et al.Association between physical activity and Nocturnal Leg Cramps in patients over 60 years old: a case-control study.Sci Rep. 2020;10(1):2638. doi:10.1038/s41598-020-59312-9
Merck Manual Consumer Version.Conditions that cause or contribute to muscle cramps.
Mass General Bringham.Nutrition tips to prevent cramps.
Banner Health.7 ways to prevent night leg cramps (charley horse).
Meet Our Medical Expert Board
Share Feedback
Was this page helpful?Thanks for your feedback!What is your feedback?OtherHelpfulReport an ErrorSubmit
Was this page helpful?
Thanks for your feedback!
What is your feedback?OtherHelpfulReport an ErrorSubmit
What is your feedback?