This is why we get cramps at night

Yes, for some people.

A simple calf stretch can be done by:

Facing a wall
Putting one foot behind you
Keeping the heel on the floor
Leaning forward slowly
Holding for 20–30 seconds
Repeat on the other side.

Should You Take Magnesium?

Not automatically.

Magnesium deficiency can cause muscle symptoms, but ordinary nighttime cramps do not prove deficiency.

People with kidney disease should be especially careful with magnesium supplements.

If cramps are frequent, ask a healthcare professional whether testing makes sense.

What About Potassium?
Low potassium can also affect muscles, but too much potassium can be dangerous.

It is usually safer to get potassium from food unless a clinician recommends supplements.

Good sources include:

Potatoes
Beans
Lentils
Bananas
Avocados
Yogurt
Leafy greens
Simple Ways to Reduce Night Cramps
Helpful habits may include:

Staying appropriately hydrated
Stretching regularly
Increasing exercise gradually
Moving more during the day
Wearing comfortable shoes
Eating a balanced diet
When Leg Cramps Need Medical Attention
See a healthcare professional if cramps:

Happen very often
Are getting more painful
Regularly wake you from sleep
Last unusually long
Come with muscle weakness
Are associated with numbness or tingling
Started after a medication change
A Red, Swollen, Warm Leg Is Different

A normal muscle cramp usually improves as the muscle relaxes.

A leg that remains: