Answer:
identify the atoms on each side
count the atoms on its side
use coefficients to increase the atoms on each side
check to make sure you have the same number of each type of atom on each side
You should read up on Proust's law, better known as the Law of Definite Proportions. This is a chemical law that defines your question more generally, on why the ratio of elements and ions are always fixed.
Basically, this compound Magnesium(II) Chloride is MgCl2 because it has the same number of protons, neutrons, and electrons all the way. This defines the properties of the compound or atom.