Leg cramps are caused by tight muscles. So, the best way to prevent leg cramps is to stretch your muscles before bedtime.