The inorganic compound formed between magnesium and oxygen is magnesium oxide MgO . It is an ionic compound, as it is formed by the transfer of electrons between magnesium a metal and oxygen a non-metal . Magnesium loses two electrons to form a Mg2+ ion, while oxygen gains two electrons to form an O2- ion. These ions are attracted to each other due to their opposite charges, resulting in the formation of the ionic compound magnesium oxide.