Here's how it works:
* SO₄²⁻ is the sulfate ion, which has a -2 charge.
* Ba²⁺ is the barium ion, which has a +2 charge.
To form a neutral compound, the charges must balance. Since the charges are equal and opposite, they cancel each other out, resulting in the formula BaSO₄ (barium sulfate).