Barium, like the other alkaline earth metals, have two valence electrons. They have all have electron configurations that end
These metals will lose two electrons when they form ions. This gives them a charge of +2 since they give away two electrons that each have a charge of -1.
Here are a few videos that may be helpful with this concept.
Hope this helps!