Here's why:
* Barium has two valence electrons (electrons in its outermost shell) and wants to lose them to achieve a stable electron configuration like the noble gas Xenon.
* Oxygen has six valence electrons and wants to gain two electrons to achieve a stable electron configuration like the noble gas Neon.
When barium and oxygen react, barium will lose two electrons to become a +2 cation (Ba²⁺), and oxygen will gain two electrons to become a -2 anion (O²⁻). These oppositely charged ions will then attract each other, forming an ionic bond.
The resulting compound is barium oxide (BaO).