What are the causes of cramping, what can you do to prevent them? Unfortunately, nobody knows the answer for sure, but there are a number of possible causes and corresponding preventative measures.
Cramps are spasmodic, painful, involuntary muscle contractions. This page is focused on Exercise Associated Muscle Cramps (EAMC), though there are other types. Many runners suffer from cramps, and sometimes cramps can be severe enough to prevent the completion of an event, or catastrophically impact performance. There are two leading contenders  for the cause of muscle cramping; Sodium Deficiency and muscle fatigue.
2 Cause – sodium deficiency
Main article: Sodium Deficiency
The initial stages of Sodium Deficiency produce dehydration as the body excretes water to keep the blood sodium concentration at the right level. More extreme Sodium Deficiency, or excessive hydration, can lead to Hyponatremia where the sodium concentration in the blood drops. Either of these conditions are believed to interfere with nerve function and cause cramping. A study in 2005 showed that a carbohydrate/electrolyte drink delayed cramps in athletes that have a history of cramping. There is also a large body of anecdotal evidence that increased salt reduces cramping.
2.1 Preventing and treating sodium deficiency
Main article: Practical Hydration
Sodium Deficiency is easy to treat and pretty much risk-free. Sodium Deficiency can be either chronic (long-term) or acute (short-term). Increasing the salt in your diet can help prevent chronic Sodium Deficiency, and any excess will be naturally excreted. You may need to add far more salt to your diet than you expect. To prevent acute Sodium Deficiency you should add extra salt to the drink you take while running. I generally add a 1/4 teaspoon of salt to each quart of drink. To treat Sodium Deficiency triggered cramping, one recommendation is 3 g (1/2 teaspoon) of salt added to 0.5 L (~16oz) of water or sports drink, which is rather salty and unpleasant shouldn't trigger nausea. Heat Acclimation Training may also help prevent cramping.
2.2 Pickles juice and cramping
There is also evidence that even small amounts of pickle juice can help limit cramps. Coaches often recommend pickle juice for athletes who suffer from cramping. While pickle juice is quite salty there is evidence that it is not the sodium that is helping prevent cramping. Studies on pickle juice show that it takes effect within seconds and well before any of the pickle juice would've been digested. Instead it is believed that it is the vinegar (acetic acid) that is triggering a reflex that stops the cramping. There is some suggestion that small quantities of vinegar are just as effective as pickle juice. (For those interested in the details, the hypothesis is that the pickle juice triggers a reflex in the oropharyngeal at the back of the mouth, which acts to reduce alpha motor neuron activity in the cramping muscles.)
3 Cause – Muscle Fatigue
There is evidence that as muscles become tired the activity of the nerves changes. The mechanisms that activate muscle contraction become more active in the mechanisms that inhibit muscle contraction are weakened. This is a particular problem for muscles that will work in a contracted state such as the calf or hamstring and for muscles that do not have the opportunity to relax periodically. There are a number of potential treatments for cramping caused by muscle fatigue beyond the over simplistic and naïve approach of not exercising so hard.
3.1 Stretching to prevent cramping
One theory behind muscle fatigue causing cramping is the idea that a cramping muscle has lost its inverse stretch reflex. The inverse stretch reflex is stimulated by a prolonged stretch and causes the muscle to relax. If a muscle's inverse stretch reflex becomes weakened, it will tend to contract strongly. The theory also explains why cramps are more likely to occur in muscles that are contracting in a shortened position (calf, hamstring). This theory suggests that Stretching will help with cramping, not because of increased flexibility, but because it will reinforce the inverse stretch reflex.
3.2 Running form and cramping
Runners whose muscles are not fully extending while running may be more prone to cramping. For instance runners who land on their forefoot and have a relatively short stride will not allow the calf muscle to stretch out as they run. This continual use in the contracted position may contribute to the cramping. Likewise runners may not extend the hamstrings as they run due to limited knee extension or reduced paw back.
As the right leg decelerates for pawback, the momentum of the foot will cause it to come up towards the shin, Stretching the calf slightly.
Changing Running Form can be difficult and risky, and evaluation should be performed using something like high-speed video to verify that a problem exists. One alternative is to vary your pace and running style slightly every few miles. This could be to pick up the pace slightly for 20 to 30 seconds, or to consciously raise the knees higher, or any other variation that helps to stretch your muscles a little.
4 Sodium deficiency or muscle fatigue?
The following criteria can be used to determine if the cramping is due to muscle fatigue or Sodium Deficiency:
- Sudden onset. Sodium Deficiency tends to cause minor cramping that escalates whereas muscle fatigue is often sudden and dramatic.
- Localized. Muscle fatigue is usually localized to specific muscles such as the calf where I Sodium Deficiency is more generalized.
- Response to treatment. If the cramping is relieved by Stretching it is most likely to be from muscle fatigue, but if the cramping is relieved by hydration and electrolytes then it is likely to be Sodium Deficiency. Cramping that is relieved by pickle juice or vinegar could be because of either underlying cause is this treatment is working on the underlying behavior of the nerves.
5 Unlikely causes of cramping
There are a number of suggested courses of cramping that have little or no supporting evidence.
- Other electrolytes beyond sodium, such as calcium or potassium, are unlikely to have any bearing on cramping. Low levels of these electrolytes are extremely rare outside of serious medical conditions such as kidney failure or AIDS.
- It has been suggested that sleep deprivation can impair the brain's ability to accurately maintain core body temperature, and that this could lead to cramping. However there is little or no evidence to support this.
- There are anecdotal suggestions that coffee and/or Caffeine may cause cramps, but there is no scientific support for this hypothesis.
- Muscle Cramps during Exercise-Is It Fatigue or Electrolyte D... : Current Sports Medicine Reports http://journals.lww.com/acsm-csmr/Fulltext/2008/07001/Muscle_Cramps_during_Exercise_Is_It_Fatigue_or.9.aspx
- http://www.ncbi.nlm.nih.gov/pmc/articles/PMC1150229/ Influence of Hydration and Electrolyte Supplementation on Incidence and Time to Onset of Exercise-Associated Muscle Cramps
- Reflex inhibition of electrically induced muscle cramps in hypohydrated humans. http://www.ncbi.nlm.nih.gov/pubmed/19997012
- NYT Phys Ed: Can Pickle Juice Stop Muscle Cramps? http://well.blogs.nytimes.com/2010/06/09/phys-ed-can-pickle-juice-stop-muscle-cramps/
- http://www.ncbi.nlm.nih.gov/pmc/articles/PMC1478386/pdf/brjsmed00052-0048.pdf Physiotherapy and electromyography in muscle cramp
- http://bjsportmed.com/content/43/6/401.abstract Cause of Exercise Associated Muscle Cramps (EAMC) — altered neuromuscular control, dehydration or electrolyte depletion?