Have you ever been swimming and had a calf cramp? Or pregnant and had a foot cramp? How about after a hard workout, suffering from spasms in the back or thigh?

Chances are you’ve experienced a cramp. If so, you know how sudden, unexpected and excruciating they are.

Cramps also can be debilitating. I once cared for a Division I football player named Keith who suffered cramps in each game. His brother was an NFL starter, and with his 256 pounds of muscle, 4.5 speed and nose for the ball, Keith looked headed for the pros as well.

The problem was Keith cramped in every game. He never had a problem in practice and could work out all day without so much as a muscle twitch. But put him in a game and by the second quarter, Keith had to be taken off the field by the trainers because of debilitating pain in his legs.

Nothing Keith did seemed to work. He tried pickle juice, he was hooked up to IV fluids each game, and he had his own cooler filled with every brand of sports drink available. None of these made a bit of difference when the game started.

Muscle cramps always have been a mystery to sports medicine physicians. Research shows they have little to do with dehydration, despite what sports drinks makers would like you to believe. Electrolytes? It turns out no matter how many bananas and salt pills most crampers eat, they still have crippling symptoms.

Instead, cramps are related to the signals our nerves send to our muscles. Each muscle, no matter how small, has a nerve running to it. These nerves tell the muscle when to contract and how hard. With exercises (say, running a marathon, for example) it’s not just the muscles that get fatigued. Our motor nerves tire, too.

Tired nerves, in some people, tend to be more likely to fire erratically. Some of these discharges tell the muscle to tighten — to cramp.

Stretching helps cramps, primarily because it provides feedback to the motor nerve. In fact, passive stretching causes an apparatus in our muscles called the Golgi tendon organ to shut down the muscle’s contraction. Numerous studies show that nothing even comes close to the effectiveness of stretching in treating cramping. Strength training may prevent cramps by decreasing the amount that the muscles become fatigued.

There is some emerging evidence that genetics may play a role in cramping. If your parents are crampers, chances are you might suffer from this problem, too.

While it’s true that exercising athletes need electrolytes and water to fuel their muscles and nerves, there is little evidence that lack of either explains why some people cramp and others don’t. In fact, it may even be more dangerous to drink too much than to become somewhat dehydrated while exercising.

So if you’re cramping, put down that banana and the sports drink. Think about your nerves (after all, the brain is our biggest and best nerve.) Work on easing the cramp by stretching gently. Once the heat of the moment has passed, it’s time to focus on bringing that motor unit up to speed. Make your muscles stronger and fitter, and they’ll reward you with fewer cramps.

Dr. James Glazer is a sports medicine physician for Coastal Orthopedics and Sports Medicine in Freeport. He serves as a consultant for the U.S. ski team.