Although we don't know the exact role that magnesium plays in PCR,
we know that an incorrect magnesium concentration will reduce or prevent
amplification of your PCR product completely. So how do you know what concentration
will work for your reaction? By running experimental PCR reactions with
the magnesium concentration as the only variable, and then running the reactions
on an agarose gel, you will be able to see which concentration is the most
effective by the presence of the most DNA(your PCR product).

For example, the gel below shows such an experiment. The lane contents
are listed to the right of the gel. Lane 3 obviously yielded the most DNA,
so we can conclude that this PCR reaction requires 1.0 mM MgCl2 to work properly. A smaller band in lane 4 shows
that the reaction was successful using 1.25 mM MgCl2,
but it was not as effective. Generally, ~1.5 mM MgCl2
is a good concentration to work around.