When should you take magnesium for sleep?
Take magnesium about an hour before bedtime, but do not expect a guaranteed effect: the evidence is thin and a substantial placebo effect is likely playing a role.
Magnesium works best for sleep when taken in the evening, about an hour before bedtime. This is supported by a study that used a combination supplement (containing melatonin and zinc): participants took it one hour before sleep, over a period of eight weeks. Taking it at a fixed time close to bedtime also helps build a consistent sleep routine.
On the question of whether magnesium genuinely works better than nothing, findings are mixed. Three small studies in older adults with sleep problems show that magnesium reduces the time it takes to fall asleep by an average of about 17 minutes. However, in a separate study the placebo group improved just as much as the magnesium group, suggesting that a large part of the effect is driven by expectation. A large population study found no better sleep among magnesium users, and, notably, those users actually reported leg cramps at night more often.
If you still want to try whether magnesium helps your sleep problems, you can opt for 320 to 500 mg of elemental magnesium per day, in the form of citrate or oxide (as stated on the label). Stick with it for at least eight to twelve weeks before drawing any conclusions. Magnesium oxide has the poorest absorption of all forms, while citrate is better absorbed. The ratio of calcium to magnesium in your diet makes no demonstrable difference for sleep.
For people with diabetes there is somewhat more to go on: one study in 290 people with diabetes showed that magnesium (sometimes combined with potassium) reduced insomnia and raised the sleep hormone melatonin, while the stress hormone cortisol decreased. This does concern a specific group and a medical condition, so discuss it with your doctor if you have diabetes and are sleeping poorly.
This answer draws on three pooled analyses of multiple studies, supplemented by individual randomised trials and one large population study. The authors of the most relevant pooled analysis themselves rate all trials as having a moderate to high risk of bias, and describe the quality of the evidence as low to very low. This makes the 17-minute gain in time to fall asleep less certain than the number suggests. Results for the general population are contradictory, and magnesium is not recommended as a standard approach to sleep problems by the most recent broad analysis.