The Ratio of Magnesium to Chloride is 1:2. Magnesium is an alkali Earth Metal, it naturally forms ions with a +2 charge.
Chlorine is a halogen gas it naturally forms ions with a -1 charge. This means that two Chloride ions must be present to balance the charge of the Magnesium ions.
Another way to look at it is by valence electrons. Magnesium has two valence electrons and isn't strongly attached to them, so gives them freely. Chlorine has 7 electrons, and strongly attracts others, but it only has room for one more, so you need two Chlorine atoms to take Magnesium's electrons.
Either way you get a ratio of 1 Magnesium ion to 2 Chloride ions.