Sleep quality is shaped by far more than diet — light exposure, stress, screen time and sleep schedule all matter enormously — but certain nutrients have a genuine, mechanistic role in the body’s ability to wind down. Chief among them is magnesium.
The Sleep Micronutrient: Magnesium
Magnesium acts as a natural relaxant by binding to gamma-aminobutyric acid (GABA) receptors, the neurotransmitter responsible for quieting nerve activity. Low magnesium status has been associated with poorer sleep quality in observational research, and magnesium also plays a supporting role in regulating melatonin, the hormone that governs the sleep-wake cycle. Vitamin B6 and calcium work alongside it — B6 is a required cofactor in the pathway that converts dietary tryptophan into serotonin and, eventually, melatonin, while calcium helps the brain use tryptophan to manufacture melatonin in the first place.
This hub gathers the foods and compounds from across the encyclopedia with the strongest, most practical magnesium content — the nuts, seeds and legumes most worth reaching for if sleep-supportive nutrition is the goal.
Foods that support Better Sleep

Pumpkin Seeds

Almonds

Black Beans

Peanut Butter

Sunflower Seeds

Flaxseed

Sesame Seeds

Cashews

Chia Seeds

Walnuts

Hazelnuts

Quinoa
Key compounds linked to Better Sleep
Recipes to try
Common questions
Does eating magnesium-rich food right before bed actually help you fall asleep? The research is more about overall status than a single pre-bed dose — consistently low magnesium intake over time is what’s linked to poorer sleep quality in studies, not a lack of magnesium in your last meal specifically. Building magnesium-rich foods into your regular diet is likely to matter more than timing any one food around bedtime.
Should I take a magnesium supplement for sleep instead? Food sources are generally preferable as a first step, since it’s very difficult to over-consume magnesium from diet alone, whereas supplemental magnesium can cause digestive upset at higher doses. If diet alone isn’t enough, that’s a conversation worth having with a doctor rather than self-prescribing a high-dose supplement.
Written by the Nutrition Encyclopedia data team
Last updated 1 July 2026
How we source & verify data · Medical disclaimer
Nutrition values are approximations compiled from public food-composition databases (USDA FoodData Central) and are provided for educational purposes only — not medical advice.