Here's why:
* Barium (Ba) is in Group 2 (alkaline earth metals) of the periodic table.
* Elements in Group 2 have 2 valence electrons (electrons in the outermost shell).
* To achieve a stable electron configuration like a noble gas, they tend to lose these 2 valence electrons, forming a +2 charge.