A muscle cramp technically occurs when your muscle tightens and shortens causing sudden severe pain. Muscle cramps generally result from overexertion and dehydration. When you don’t have enough fluid in your system, it leads to an electrolyte imbalance that causes your muscles to cramp up. Electrolytes are minerals like sodium, magnesium, calcium and potassium that help cells function normally. An imbalance occurs when we have too much or too little of one or more electrolytes in our system. The main electrolytes affecting muscle cramps are potassium, sodium and calcium. Cramps may also occur after inactivity.