Electrolysis occur when an electric current is passed through a liquid or solution thereby causing the decomposition of chemicals.
For magnesium chloride, it will be heated to be able to conduct electricity. When molten, the MgCl2 will decomposes into Mg2+ and 2Cl- ions. During electrolysis, the elements are separated according to the equations;
[tex]\begin{gathered} Mg^{2+}+2e^-\rightarrow Mg(s) \\ 2Cl^-\rightarrow Cl_2(g) \end{gathered}[/tex]According to the half reactions, the Mg2+ is reduced at the cathode (-) and the Cl- is oxidized at the anode (+). Reduction at the cathode shows that magnesium gains two electrons to form a magnesium solid while the chlorine ion looses two electrons at the anode