Answer: Magnesium loses electrons to form 
Explanation:
An ionic bond is formed when an element completely transfers its valence electron to another element. Metals donate the electron and forms a positively charged ion called as cation. Non metals accept the electrons and forms a negatively charged ion called as anion.
Electronic configuration of magnesium:
![[Mg]:12: 1s^22s^22p^63s^2](https://tex.z-dn.net/?f=%5BMg%5D%3A12%3A%201s%5E22s%5E22p%5E63s%5E2)
Magnesium atom will loose one electron to gain noble gas configuration and form magnesium cation with +2 charge.
![[Mg^{2+}]:10:1s^22s^22p^63s^0](https://tex.z-dn.net/?f=%5BMg%5E%7B2%2B%7D%5D%3A10%3A1s%5E22s%5E22p%5E63s%5E0)
Electronic configuration of bromine
![[Br]:35:1s^22s^22p^63s^23p^64s^23d^{10}4p^5](https://tex.z-dn.net/?f=%5BBr%5D%3A35%3A1s%5E22s%5E22p%5E63s%5E23p%5E64s%5E23d%5E%7B10%7D4p%5E5)
Bromine atom will gain one electron to gain noble gas configuration and form bromide ion with -1 charge.
![[Br^-]=1s^22s^22p^63s^23p^64s^23d^{10}4p^6](https://tex.z-dn.net/?f=%5BBr%5E-%5D%3D1s%5E22s%5E22p%5E63s%5E23p%5E64s%5E23d%5E%7B10%7D4p%5E6)
Thus as magnesium forms a cation , it is the metal.