Treat a leg cramp while swimming by stretching or massaging the affected muscle, recommends HealthDay. If possible, get out of the water or try to get to shallower water. If in deep water, float on your back while trying to stretch the cramped muscle. If the cramp is in the calf, try flexing the foot upward with toes toward the shin and if it is in the back of the thigh, pull the foot toward the buttocks to relax the muscle.

Other ways to deal with cramping while swimming include rotating your foot if the cramp is in the leg. If unable to float on your back, treading water is another way to work on a cramp while in deep water, as noted by Skipping poolside as a method of relaxing cramped muscles is also suggested by

Muscle cramps while swimming can be dangerous, so prevention is key. Avoid cramps by ensuring adequate hydration, stretching before swimming, getting plenty of food and drink rich in potassium and sodium, and enduring enough training, USA Swimming suggests. A theory, explained USA Swimmers, is that muscle exhaustion is another cause of cramps. Getting enough rest and not overusing muscles while swimming are ways to avoid exhaustion and the over-contracting of muscles.