There is no certain cause for muscle cramps. Many people wake up in the middle of the night with muscle cramps. For athletes they are part of the territory. They are only temporarily painful but often difficult to prevent. Applying pressure on the muscle while stretching will help unlock the cramp.
Gentle massage can also be beneficial.
Don't let thirst be your guide. By the time your thirsty you have already lost too much fluid. Ensure that you are eating adequate levels of potassium, calcium and magnesium. Bananas and oranges are excellent sources of potassium. Great sources of calcium and magnesium include low-fat milk and yogurt, whole gain breads and cereals, green leafy vegetables and beans.