Usually yes — magnesium and metformin are not known to interact dangerously and are often taken together, but stay within supplement dosing limits and check with your pharmacist or doctor first.
Magnesium is not listed as an interacting drug in metformin's FDA label, which flags interactions only with alcohol, carbonic anhydrase inhibitors, drugs that reduce metformin clearance, insulin/insulin secretagogues, and certain blood-sugar-affecting medicines — not mineral or vitamin supplements. The NHS metformin page lists no specific magnesium interaction either, advising only that you tell your doctor or pharmacist about any supplements because complementary products are not tested the same way as medicines. There's also relevant context: NIH notes people with type 2 diabetes are among the groups more likely to run low on magnesium, which is one reason supplementation is common in this group; magnesium is not expected to blunt metformin's glucose-lowering effect.
Keep supplemental magnesium at or below the NIH Tolerable Upper Intake Level of 350 mg/day from supplements and medications unless a clinician directs otherwise — going over this commonly causes diarrhea, nausea, and abdominal cramping, which can be mistaken for or stacked on top of metformin's own GI side effects. People with kidney disease or reduced kidney function should not take magnesium supplements without medical supervision, since impaired kidneys clear magnesium less well and can let it build up to dangerous levels. Magnesium can also reduce absorption of some other medicines (e.g., certain antibiotics and bisphosphonates), so separate those by a couple of hours. Because metformin can independently lower vitamin B12 (the label recommends periodic B12 checks), ask about B12 monitoring too. Tell your doctor or pharmacist about every supplement you take, and seek care promptly for severe or persistent diarrhea, muscle weakness, unusual drowsiness, irregular heartbeat, or signs of very low blood sugar.
This is general reference, not medical advice, and not a guarantee of safety. Interactions depend on your doses, health conditions, and other medicines. Always confirm with your pharmacist or doctor before combining products, and follow the dosing on each label.