Roughly half of all Americans (48%) are deficient in magnesium.  A recent review estimated that up to 68% consume less than the recommended daily allowance (RDA) of magnesium—this larger percentage includes those who have not yet reported symptoms of deficiency but are at higher risk for their development. 
This deficiency shouldn’t be taken lightly, as there are few nutrients involved in more metabolic processes than magnesium.
The Many Critical Functions of Magnesium
The movement of magnesium (and calcium) through ion channels in cell membranes allows for the contraction of all muscle tissues (including the heart).
In addition to its role in muscle contraction, magnesium is also a cofactor for over 300 enzymes, including those involved in protein synthesis, nerve function, blood glucose control, and energy production. 
As a result, magnesium gets used at a high rate in the body and needs to be continually replenished. Many studies have also noted that magnesium is almost entirely absent from processed foods, refined grains, and even fruits and vegetables grown in nutrient-depleted soil.  This means that food sources of magnesium are usually insufficient, and most people hover in the less-than-ideal range without supplementation.
The Benefits of Supplementation
Addressing low magnesium levels via supplementation commonly alleviates headaches, eases pain and muscle tension, and improves sleep. 
Researchers have also found a strong link between magnesium deficiency and emotional disorders. One review reports that magnesium supplementation can perform on par with leading antidepressants, and has been shown to “rapidly terminate major depression safely and without side effects.” 
We’ll highlight just one more of magnesium’s countless benefits. If you’ve followed the push in recent years toward vitamin D supplementation, you should be aware that low magnesium levels make vitamin D ineffective.
A 2018 study demonstrated that, due to magnesium deficiency, vitamin D remains “stored and inactive” for up to 50% of Americans. When the body is unable to mobilize vitamin D properly, calcium and phosphate levels increase, thus heightening the risk of vascular calcification while leaving the original vitamin D deficiency unaddressed. 
4-Week Protocol for Addressing Magnesium Deficiency
Your first priority is to address existing deficiency, so that all the enzymes that depend on magnesium can return to optimal functioning.
Know your status; get tested. We highly recommend getting a lab test, before and after this protocol, so that you can accurately track your magnesium levels (it’s also really satisfying to see the quantifiable benefits of your supplementation protocol). It’s fairly cheap to run this test alone at a Quest lab, or as part of a more complete blood panel ordered by your primary care physician.
If getting a lab test sounds like a chore, though, don’t let it stop from beginning the protocol. Knowing your precise magnesium levels is ideal, but If you haven’t been actively supplementing, it’s almost guaranteed that you’re running some level of magnesium deficiency.
Epsom salt baths. The quickest and most effective way to increase both free/serum and stored magnesium in the body is with an epsom salt bath (epsom salts are magnesium sulfate).
Add 2 cups to a standard size bathtub of warm water, 2-3 times per week for 4 weeks. For best absorption, stay in the bath for 15-20 minutes each time.
Oral supplementation. If you’d prefer an oral magnesium supplement, chelated formulas have been shown to have the best overall absorption. Take 800mg per day of magnesium glycinate for 4 weeks.
Oral supplementation occasionally causes diarrhea, though this effect is more common with other forms of magnesium (especially magnesium oxide). If you still experience this issue with magnesium glycinate, though, experiment with splitting the 800mg into separate doses throughout the day (with or without food, depending on what works best for your body).
Best Magnesium Supplement For Muscle Relaxation, Sleep and Maintenance Supplementation
Once our magnesium levels are in a healthy range and simply need to be maintained, you can turn to other forms of magnesium that have lower total absorption, but offer other benefits.
A fast-absorbing magnesium like magnesium carbonate can produce a perceptible muscle-relaxing effect. Taking 400mg/day of magnesium carbonate 30 minutes before sleep can also help improve time-to-sleep and even quality of early sleep cycles. 
Note that with popular products like this one, 400mg of magnesium is generally somewhere between 2-5g of powder.
Magnesium Threonate is interesting as it crosses the blood-brain-barrier at a higher rate than other forms of magnesium, which some people believe could allow it to improve sleep quality to an even greater degree.
I personally see a greater improvement to my sleep quality using magnesium carbonate, but which form offers the greatest benefit likely varies person to person.