Muscle cramps and spasms in the rib cage are most commonly caused by dehydration leading to electrolyte imbalance, or by muscle overuse and injury, according to PubMed Health. While painful, the condition is self-limiting and can be treated at home with rest, ice and heat.
Stopping the activity that triggered the cramp and massaging the area can prevent the cramp from getting worse, states PubMed Health. Light stretching can also be helpful. If soreness persists, using a heating pad can help loosen tight muscles. Heat should be applied for 15 to 20 minutes at a time, several times a day, with the pad covered with a cloth to protect skin from burns. An ice pack can be helpful once the pain has improved, especially after an activity that has triggered spasms in the past. It should be applied for 10 to 15 minutes at a time, several times a day. Covering the skin with a cloth reduces the chance of frostbite.
Dehydration can also lead to cramps as the body's potassium and calcium stores are depleted, notes PubMed Health. While drinking water is important and can ease the cramping, it doesn't replace the depleted minerals. Sports drinks and salt tablets can help bring the body's electrolytes back into balance.