Prevent muscle cramps by staying hydrated, stretching before exercise, and maintaining electrolyte balance. If cramps occur, gently stretch and massage the affected muscle, apply heat or cold, and rest. Persistent cramps should be evaluated by a doctor.