Transparency Disclosure — We may receive a referral fee for products purchased through the links on our site…Read More.

Magnesium vs. Melatonin: Which One Helps Better With Sleep?

Disclaimer – Nothing on this website is intended to be a substitute for professional medical advice, diagnosis, or treatment… Read More Here.

If you have trouble sleeping, you’ve likely heard of melatonin as a natural alternative to prescription sleep aids. The supplement has gotten a lot of buzz from the media and word of mouth with some folks swearing by it as their go-to remedy.

In the ever-evolving market, though, there’s a newer kid in town, and its name is magnesium. The hype surrounding magnesium has some consumers rethinking their sleep-aid strategy and wondering whether they should purchase magnesium or melatonin.

This article will take an in-depth look at both of these sleep supplements, including how they work, the differences between them, and which is better for a restful night.

What Is Magnesium?

Magnesium is a powerful nutrient5, present in a variety of foods like nuts, seeds, leafy greens, beans, potatoes, rice, bananas, and more. This nutrient is important because it regulates muscles and nerves, blood sugar, and blood pressure, and it helps make protein, bone, and DNA5.

What’s interesting is that magnesium may also help regulate your body’s melatonin production6. This means that magnesium-deficient individuals may not be producing the amount of melatonin necessary to properly regulate the sleep-wake cycle. 

How Does a Magnesium Supplement Work?

Magnesium can be used to treat a variety of issues, however, all magnesium supplements aren’t created equal. There are several different types of magnesium7, including magnesium citrate, magnesium oxide, magnesium chloride, and more. Magnesium oxide8 seems to be the best for treating constipation, whereas magnesium chloride seems to work well for people with fibromyalgia9 or sore muscles.

For sleep, however, the types of magnesium that seem to be the best are magnesium citrate and magnesium glycinate because they are both easily absorbed6.

Magnesium aids sleep by acting on certain receptors in the brain called “benzodiazepine receptors.” This is the same receptor that drugs like Ambien and Valium work on to create a feeling of relaxation. Similar to these prescription drugs, magnesium seems to aid sleep by relaxing both the mind and the muscles of the body.6

A 2016 study10 found that intake of this supplement was able to reduce stress levels and could help with bedtime disorders and restlessness, as well as irritability, lack of concentration, anxiety, and depression.

Check Out Our Guide: Best Magnesium Supplements for Sleep

What Is Melatonin?

Melatonin is a hormone produced by the brain’s pineal gland in response to darkness and is part of the body’s sleep cycle. Levels of this hormone become higher at night11 to make you sleepy as it gets dark.

Recent studies are uncovering melatonin’s other important roles in the body. For example, this hormone also appears to play a role in puberty onset, hormonal regulation, memory, inflammation, mental health disorders, and more.2 However, research on this is ongoing.

How Does a Melatonin Supplement Work?

Although the body naturally produces more melatonin at night to facilitate sleepiness, some people who struggle to sleep may try to increase their melatonin levels through supplementation.

For example, shift workers who go to bed when it is light outside may need help telling their body it’s time to sleep since this schedule goes against the natural circadian rhythm. If you’re traveling across time zones and your circadian rhythm is still “on your home time,” you might also benefit from melatonin to help you adjust to your destination’s dark and light cycles. Additionally, many who simply struggle to sleep in general may find melatonin helps them doze off.

Health experts suggest taking 1-3 milligrams of this supplement approximately two hours before your bedtime to help with sleep.11 It may require some trial and error to find the dose that’s best for you, however, it is always recommended to start on the low end of the range.

For those who want to alleviate jet lag, you should take melatonin one or two hours prior to your destination bedtime beginning several days before your trip.11

For anyone who wants to exhaust all options before using a melatonin supplement, Nastasi mentions that melatonin is found naturally in certain foods. While these levels are relatively low compared to what the body naturally produces, incorporating these foods into your diet may contribute to better sleep. 

Some natural sources of melatonin12 include eggs, fish, fruits,  tart cherries, grapes, strawberries, tomatoes, bell peppers, almonds, walnuts, and peanuts29. That said, the levels of melatonin in these foods are not as high as what is commonly found in melatonin supplements, so relying on them alone may not provide sufficient melatonin for those seeking its use as a sleep aid.

View Our Guide: Best Melatonin Supplements

Magnesium vs. Melatonin: Which is Better for Sleep?

Experts say melatonin has been shown to help people fall asleep more quickly.10 Meanwhile, additional research suggests it could increase rapid eye movement (REM) sleep22.

REM sleep is when we are most likely to dream and is a necessary part of the sleep cycle as it plays a vital role in memory formation23. During REM sleep, the brain transfers short-term memories from one part of the brain into another, to become long-term memories.23 This may be why melatonin has been shown to improve memory24, as well as sleep.

While melatonin may help improve how quickly you fall asleep and the percentage of time you spend in REM sleep, magnesium seems to improve how quickly you fall asleep, along with overall sleep quality and length of time spent sleeping25.

Ultimately, it may require some experimentation to determine which of these supplements may be right for you. That being said, we always advise you to speak with a primary healthcare provider before implementing either of these supplements into your regular routine.  

Get More Info: Best Natural Sleep Aids

How Do These Supplements Affect Our Bodies?

The human body has a natural way of operating, and by adding a supplement, you could manipulate those processes.

Circadian Rhythm

Circadian Rhythm13 refers to your body’s mental, physical, and behavioral changes in a 24-hour cycle. For example, being awake during the day and asleep at night is due to your circadian rhythm. The circadian rhythm is regulated by what is called a “biological clock,” or a bundle of proteins that interacts with cells throughout the body.13 Nearly all of the body’s tissues contain a biological clock for a different function.13

Magnesium plays an important part in making sure all those biological clocks are ticking smoothly. In fact, research has found that magnesium, in particular, was vital to these 24-hour clocks14 because magnesium levels rise and fall in a daily cycle, helping control how cells “keep time” with the environmental cycles of dark and light. Interestingly, this is true not just in humans but in almost all organisms.14

Melatonin seems to be just as important in regulating the sleep-wake circadian rhythm as it tells the body when it should be getting sleepy, in response to darkness.2 Both melatonin and magnesium supplements can be used as a possible way to adjust these cycles or make them more efficient.

Nervous System

Magnesium is vital to the nervous system15 because it helps with nerve transmission and neuromuscular conduction. It also protects from excitotoxicity, which can lead to cell death.15 For this reason, magnesium is being studied in relation to disorders of the nervous system, including Alzheimer’s, Parkinson’s, stroke, migraine, chronic pain, and epilepsy.

Since magnesium plays such a pivotal role in both the central and peripheral nervous system16, that means it is critical for brain function, including the part of the brain that copes with stress and anxiety. This is why research shows17 that these supplements may help lower stress – a condition linked to insomnia.

According to research18, melatonin has been found to be effective at protecting the central nervous system from neurological issues like brain injuries or degeneration. Meanwhile, newer studies19 are currently looking at its protective effects against degenerative disorders like Alzheimer’s. Though the findings are promising, research is ongoing.


Julia Forbes testing a mattress in the side sleeper sleeping position
Our lead product tester, Julia Forbes, testing different sleeping positions on a mattress in our testing facility.

Melatonin supplements do not act as a sedative or necessarily help you sleep through the night, but rather, they can help you get to sleep earlier.13 If you take melatonin about one or two hours before your desired bedtime, it should help you to feel sleepy at that time. However, unless you’re taking prolonged-release tablets, it won’t necessarily help you sleep longer through the night. This is why melatonin could be especially helpful for travelers or those who work overnight because it can help adjust your internal clock.13

Magnesium, however, can work in two ways. The first is to better regulate melatonin production, which as we have discussed, promotes sleepiness. The second is that it helps activate your parasympathetic nervous system20, which is the system responsible for relaxing you.

Overdosing Side Effects

Since these products are classified as supplements, they are not regulated by the FDA and are recommended as temporary aids, not permanent fixes. Possible side effects of melatonin supplements include headaches, dizziness, nausea, and drowsiness.4 Even though you can overdose on melatonin (in other words, take an amount that causes adverse side effects), no studies show that melatonin taken at any level can be lethal21.

Excessive amounts of magnesium from supplements have been reported to cause diarrhea, nausea, and abdominal cramping.5 In rare cases, taking too much magnesium can be fatal, however, this amount must exceed more than 5,000 milligrams in a day, where the daily upward recommendation is just 350 milligrams.5

Learn More: Can You Overdose on Melatonin?

Are Sleep Aids Safe Long Term?

A sleep aid can start as something you use on occasion, say, after a long overseas trip. What happens, though, when that evolves into regular consumption?

For those who struggle with insomnia, you may have a doctor prescribe sleeping pills. Health experts1 say taking these pills for too long, however, could lead to dependency. The same goes for over-the-counter remedies; they are meant to be a temporary solution.

That said, a lot of research is still being done concerning the long-term safety of melatonin2 and its health benefits in areas aside from sleep. It may be that it is safe to take long-term for specific conditions, but we don’t have enough information yet to confirm this.

As for magnesium, experts say that low doses in healthy individuals3 should be fine for those in good health. However, prior to supplementation, they encourage people to try to increase their magnesium intake through a healthy diet. 

Certified nutrition coach Pete Nastasi notes that foods rich in magnesium include nuts and seeds, such as pumpkin seeds, chia seeds, almonds, and cashews, soy products like tofu, edamame, and soy milk, as well as dark leafy greens like spinach and broccoli. 

It’s also important to note that doctors say some sleep aid products could interfere with other medications4 you take, and there is still much to learn about how safe they are. This is why it’s always recommended to speak with your doctor before adding in a sleep aid, even if it is natural.

Frequently Asked Questions

Can I take magnesium and melatonin at the same time?

There are no negative interactions between magnesium and melatonin, according to pharmacists26, so taking them together should be safe. In fact, a recent study found that taking them together27 is better at improving sleep quality than taking either one of them alone. A study from 201928 also showed that taking a combination of magnesium, melatonin, and vitamin B complex worked well in treating insomnia.

Even though it should be safe to take them together, you should still speak to your doctor before starting either, as they may interact with other medications or supplements you’re taking.


The growing interest in these supplements is understandable considering the mounting evidence suggesting their health benefits, including their ability to help you get better sleep. Even though melatonin and magnesium are naturally found in the body, you should still take low, recommended doses to avoid over-usage.

While getting a good night’s sleep is crucial to living a healthy life, sleep aids, including over-the-counter ones, should be a temporary solution, unless otherwise directed by your doctor. We always recommend speaking to a healthcare professional before introducing any new supplements or if you are experiencing chronic insomnia.

Jill Zwarensteyn

Jill Zwarensteyn


About Author

Jill Zwarensteyn is the Editor for Sleep Advisor and a Certified Sleep Science Coach. She is enthusiastic about providing helpful and engaging information on all things sleep and wellness.

Combination Sleeper


  1.  “Sleeping Pills”. Cleveland Clinic. Last modified April 27, 2021.  
  2. Minich, Deanna M., et al. “Is Melatonin the “Next Vitamin D”?: A Review of Emerging Science, Clinical Uses, Safety, and Dietary Supplements”. MDPI Journals. 2022. 
  3. McCallum, Katie. “Should You Be Taking Magnesium Supplements?”. Houston Methodist Hospital. 2022. 
  4. “Sleep aids: Understand options sold without a prescription”. Mayo Clinic. Last modified June 8, 2022.
  5. “Magnesium”. Harvard T.H. Chan School of Public Health. Last modified March 2024.
  6. “What an Expert Says About Taking Magnesium for Sleep”. UC San Diego Health. 2024.
  7. “Magnesium”. National Institutes of Health. Last modified June 2, 2022.
  8. Mori, Hideki., Tack, Jan., Suzuki, Hidekazu. “Magnesium Oxide in Constipation”. National Library of Medicine. 2021. 
  9. Engen, Deborah J., et al. “Effects of transdermal magnesium chloride on quality of life for patients with fibromyalgia: a feasibility study”. ScienceDirect. 2015. 
  10. Wienecke, Elmar., Nolden, Claudia. “[Long-term HRV analysis shows stress reduction by magnesium intake]”. National Library of Medicine. 2016. 
  11. “Melatonin for Sleep: Does It Work?”. Johns Hopkins Medicine. Webpage accessed August 7, 2024.
  12. Meng, Xiao., et al. “Dietary Sources and Bioactivities of Melatonin”. Nutrients. 2017.
  13. “Circadian Rhythms”. National Institute of General Medical Sciences. Last modified May 4, 2022.
  14. “Vital nutrient has key role in keeping body clocks running on time”. ScienceDaily. 2016. 
  15. Kirkland, Anna E., Sarlo, Gabrielle L., Holton, Kathleen F. “The Role of Magnesium in Neurological Disorders”. National Library of Medicine. 2018.  
  16. “What are the parts of the nervous system?”. Eunice Kennedy Shriver National Institute of Child Health and Human Development. Last modified October 1, 2018.
  17. Pickering, Gisèle., et al. “Magnesium Status and Stress: The Vicious Circle Concept Revisited”. National Library of Medicine. 2020.  
  18. Zhang, Wei., Li, Fang., Zhang, Tong. “Relationship of nocturnal concentrations of melatonin, gamma-aminobutyric acid and total antioxidants in peripheral blood with insomnia after stroke: study protocol for a prospective non-randomized controlled trial”. National Library of Medicine. 2017.  
  19. Lee, Jung Goo., et al. “The Neuroprotective Effects of Melatonin: Possible Role in the Pathophysiology of Neuropsychiatric Disease”. National Library of Medicine. 2019. 
  20. Wienecke, Elmar., Nolden, Claudia. “[Long-term HRV analysis shows stress reduction by magnesium intake]”. National Library of Medicine. 2016. 
  21. Malhotra MD, Samir., Sawhney MD, Girish., Pandhi MD, Promila. “The Therapeutic Potential of Melatonin: A Review of the Science”. Webpage accessed August 8, 2024.
  22. “Can Melatonin Cause Bad Dreams? What Experts Say”. Cleveland Clinic. 2021. 
  23. Rasch, Björn., Born, Jan. “About Sleep’s Role in Memory”. National Library of Medicine. 2013. 
  24. “Melatonin: finally, a supplement that actually boosts memory”. American Association for the Advancement of Science. 2020. 
  25. Zhang, Yijia., et al. “Association of magnesium intake with sleep duration and sleep quality: findings from the CARDIA study”. Oxford Academic. 2022. 
  26. Staiger, Brian. “Is It Safe To Take Magnesium And Melatonin Together?”. Hello Pharmacist. Last modified August 8, 2024.  
  27. Alizadeh, Mohammad., et al. “Metabolic and hormonal effects of melatonin and/or magnesium supplementation in women with polycystic ovary syndrome: a randomized, double-blind, placebo-controlled trial”. BMC. 2021. 
  28. Djokic, Gorica., et al. “The Effects of Magnesium – Melatonin – Vit B Complex Supplementation in Treatment of Insomnia”. National Library of Medicine. 2019.