Stretching is the primary treatment for muscle cramps. Regular stretching loosens up muscles, reducing the chance that they will stiffen and spasm involuntarily. Massaging the affected muscles has a similar effect. You can try applying ice or a cold compress to tight, cramped muscles or heat to muscles that are no longer stiff but are still sore. In severe cases, a doctor might prescribe medication to loosen up muscles.