The reasons why cramps happen can be various.
The most common, however, are as follows:
1. Dehydration
Sometimes, leg cramps that happen during the night are caused by the lack of hydration as this condition leads to an electrolyte imbalance.
2. Mineral Deficiencies
Muscle cramps can also happen due to the shortage of certain minerals within the body, such as magnesium, potassium, and calcium.
3. Overexertion
Although exercises is good for the body, overexertion can sometimes overwork the muscles, leading to cramps.

4. Sedentary lifestyle
In order to function properly, muscles need to be stretched from time to time, which is something we often forget about when our job requires too much sitting throughout the day.
5. Improper sitting position
It’s easy for muscles to get strained in case of poor posture and prolonged sitting or standing.

6. Nerve Compression
Nerves in the legs may get compressed or pinched by conditions such as sciatica or herniated discs, which can result in cramps.
7. Pregnancy