Muscle cramps are painful spasms that occur most commonly in the legs. Cramps occur because of a lack of oxygen and/or a build-up of waste products causing the muscle to contract and harden. Although muscle cramps can occur at rest, they most commonly occur during exercise or sustained work.