If there is a more important and ubiquitious nutrient than magnesium, I don’t know about it. (Vitamin D is a close second if you ask me.) This mineral is used in 300+ enzyme systems and indirectly affects almost every system, organ and tissue in the body. When you go low on magnesium, everything suffers. And going low on magnesium is very easy to do: studies show that less than half of all Americans get their RDA of magnesium and up to 20% of seniors are deficient.  This is why a number of men on the Peak Testosterone Forum swear by magnesium before bed: it helps them fall to sleep and it helps them sleep better. (See my page on So You Can’t Sleep? for some of their stories.)
And the research supports the use of magnesium for improved sleep in MANY different ways. Here are just some of the reasons you should consider some magnesium an hour or two before bed:
1. Seratonin. Magnesium is a driver of seratonin metabolism and, especially for those deficient, can restore this key neurotransmitter to normal levels.
2. Wakefulness. Animal studies have shown that a magnesium deficiency leads to increases in dopamine and increases in walkefulness. This may seem good but can lead to disturbed sleep. 
CAUTION: Always dicuss with your physician any new supplement, especially if you are on medications or have any sort of medical condition.
4. Restless Leg and Periodic Limb Movement. One study showed that magnesium helped significantly with these two sleep disorders.  Studies out of Europe show surprisingly high prevalence rates: 3.0% and 5.5% for PLMD and RLS, respectively.
5. Pain. Many adults have trouble sleeping due to pain, such as from arthritis or an injury. Magnesium has been shown in many studies to help with pain and lower the need for pain medications. 
6. Muscle and Nerve Relaxation. Magnesium allows muscles and nerves to rela by helping regulate calcium flow in nerve cells, for example, as calcium is like the “switch” that turns on and off the nerve. 
7. Testosterone. Magnesium can increase testosterone and testosterone increases several key neurotransmitters, including dopamine as I document in my link on Testosterone and the Brain. This inexpensive supplement was found in a study of seniors to be tightly associated with T levels.  Can magnesium supplementation increase testosterone? One study noted that magnesium levels increased testosterone when combined with exercise.  (They received 10 mg per kg of body weight.)
8. Depression. Magnesium is powerful enough that it can have a clinical effect on some patients help with depression.  In fact, one study showed that magnesium therapy can cure severe, untreatable depression! Depression leads to disturbed sleep quality and sometimes lowers the quantity as well.
9. Blood Flow and Blood Pressure. There are literally dozens of studies showing that magnesium can improve blood flow and lower blood pressure. No, magnesium is not as powerful as a Viagra or a Cialis, but it can definitely help, especially if your levels are low like so much of the population. And good flow will not only help erections but the brain and also sleep. In addition, high blood pressure (hypertension) is also associated with low magnesium levels.
10. Metabolic Syndrome (Prediabetes) and Diabetes Prevention. Both of these epidemics are correlated with low magnesium levels. Since we know that magnesium helps improve two of the major components of these condition – dyslipidemia and high blood pressure – it is entirely reasonable to assume that low magnesium is often causative.  One study found that giving magnesium helps. 
NOTE: You always want to make sure that you are getting more than adequate Vitamin B6 levels when taking magnesiu, since it is Vitamin B6 that regulates the amount of magnesium that can actually be absorbed. There are many excellent form of magnesium, but the one that is probably the least absorbable is magnesium oxide. This can even have a laxative effect
2) Clin Chem, 1987 Apr, 33(4):518-23, “Prevalence of magnesium and potassium deficiencies in the elderly”
3) Magnes Res, 2013 Feb 1, 26(1):9-17, “Platelet serotonin and magnesium concentrations in suicidal and non-suicidal depressed patients”
4) Magnesium, 1984, 3(3):145-151, “Vigilance states and cerebral monoamine metabolism in experimental magnesium deficiency”
5) Neuropsychobiology, 1993, 27:237 245, “Effects of a Magnesium Deficient Diet on Sleep Organization in Rats”
6) Sleep, 1998, 21(5):501-505, “Magnesium therapy for periodic leg movements-related insomnia and restless legs syndrome: an open pilot study”
7) PAIN, Sep 2002, 99(1-2):235 241, “Magnesium bier’s block for treatment of chronic limb pain: a randomised, double-blind, cross-over study”
9) Int J Androl, 2011 Dec, 34(6 Pt 2):e594-600, “Magnesium and anabolic hormones in older men”
11) Acta Diabetologica, Dec 2002, 39(4):209-213,”Low serum magnesium levels and metabolic syndrome”
12) Molecular Aspects of Medicine, Feb 2003, 24(1-3):39 52, “Role of magnesium in insulin action, diabetes and cardio-metabolic syndrome X”