* Magnesium is a metal. Metals tend to lose electrons to form positively charged ions (cations). Magnesium, specifically, loses two electrons to achieve a stable electron configuration, forming Mg²⁺.
* Carbon is a nonmetal. Nonmetals tend to gain electrons to form negatively charged ions (anions).
* Oxygen is also a nonmetal and forms negatively charged ions (O²⁻).
* Bromine is a nonmetal and forms negatively charged ions (Br⁻).