Getting a charley horse mid-box jump may be more painful than finishing that set would’ve been.

So what gives? There are a few reasons your feet may be cramping up.

Let’s start with the easiest to fix (and prevent): Dehydration can come into play with any type of muscle cramp, says New York-based trainer Chris Ryan, C.S.C.S. “Your muscles need water to function properly, so when we sweat, they’re getting less and less water, becoming tighter and tighter, which can lead to contractions within the muscle,” he explains.

But when it comes to your feet specifically, the most likely culprit is ill-fitting shoes, says Alex Kor, D.P.M., a podiatrist at Froedtert & the Medical College of Wisconsin and immediate past president of the American Academy of Podiatric Sports Medicine. As you exercise and your feet swell with the heat, ultra-tight shoes can compress the nerves on top of your foot. You can mitigate it temporarily by tying your shoes differently to relieve pressure on the top, says Kor. (Check out this tutorial to try it out.)

Similarly, if you don’t have proper arch support, your shoes will bend too much midfoot, potentially leading to overuse injuries like inflammation of a nerve or tendinitis.

In fact, tendinitis—either caused by poor footwear or other overuse events—is a prime culprit of foot cramping, Kor says. This inflammation in your tendons can cause not just pain but also potential swelling. But you won’t know if it’s a soft tissue condition, nerve issue, or bone problem unless you see a doc, Kor adds.

Metabolic disorder is another potential cause of foot cramping—albeit a much less likely one—because low potassium and low sodium levels can cause cramps. But if this were the case, you'd suffer from cramps outside the gym as well, Kor adds.

Your safest, long-term fix is to go to a running store and get fitted for proper shoes. If the cramps continue, go see a doc in case it’s something more serious.

And when your feet start cramping up in the moment, pull off your shoes and roll a lacrosse ball or golf ball under foot, Ryan suggests. Massage down in the heel, the instep, up toward the ball of your foot, along the center tendon—it’ll help relax the muscles and stop the pain.

Lastly, rehydrate—just in case it’s that simple—by replenishing both your water and mineral stores simultaneously, Ryan adds. He recommends cold pressed juices, like WTRMLN WTR, which has a good amount of both potassium and magnesium.