Sudden cramps in a calf at night are very common, and may occur in almost half of all adults. They’re more common with older age, and also occur in children. They last seconds to minutes. The best treatment is to stretch the knee straight, and stretch the foot upwards and back (“dorsiflex”). This may require getting out of bed, and leaning against a wall.
In most cases, nobody knows what causes cramps. They may occur more Parkinson’s and other neurologic diseases, joint abnormalities such as flat feet or knees which bend backwards, pregnancy, and perhaps certain medications. If a new medicine was begun recently before the cramps began, it may be worth discontinuing it, if possible, to see what happens, and then trying it again (when any symptom abates with stopping a medication, and recurs with restarting, such rechallenge provides decent evidence as to the cause).
Even though nighttime leg cramps may occur during the progression of other more serious conditions, in such cases, there are always other symptoms which predominate. There’s no need to order any special tests when cramps are the only symptom. In pregnancy it may be worth checking the blood level of magnesium, and testing for sodium and potassium in patients taking diuretics (“water pills” for blood pressure). We might test iron levels for “restless leg syndrome,” but that involves an inability to lie with legs still, but does not include muscle pains.
Unfortunately, there’s no proven treatment to prevent muscle cramps. Many suggestions include exercise, staying well-hydrated, stretching before bedtime, avoiding alcohol and caffeine, taking a variety of vitamins / supplements, and more. None have been proved to work. Medical providers might try a couple of possibilities, none of which have strong evidence in their favor.
There was indeed one over-the-counter drug, quinine, which had proven benefit; sufferers swore by it. The problem was that up to one in 25 people experienced certain heart arrhythmias or other possibly life-threatening side effects. So the FDA has banned over-the-counter quinine, and no provider would risk getting sued for a death from their prescription.