There are several causes of leg cramps including: injury, dehydration, rest cramps and vigorous activity.When leg cramps occur because of injury it can be the result of a muscle contracting in order to protect the leg. It is doing so to reduce the movement of the leg which could cause further injury.
You can experience leg cramps due to dehydration. Activities especially those that are sports-related can lead to excess fluid loss which can lead to cramps.
Vigorous activity can also cause cramps in your legs during or after the activity. If you are a very active person then the activity can lead to cramps occurring due to fatigue of the muscle or group of muscles.
Rest cramps especially during the nights do occur though it is more common in the elderly but can be experienced at any age. It can lead to sleep problems too which also lead to fatigue from not getting enough sleep.