

In the process of electrolysis of molten NaCl, Cl2 is obtained at the anode as a by product.
NaCl → Na+ + Cl-
Cathode: Na+ + e- → Na
Anode: Cl- → Cl(g) + e-
2Cl(g) → Cl2(g)
The overall reaction is as follows:

If an aqueous NaCl solution is electrolyzed, Cl2 will be obtained at the anode but at the cathode, H2 will be obtained and not Na. This is because the standard reduction potential of Na (E°= - 2.71 V) is more negative than that of H2O (E° = - 0.83 V). Hence, H2O will get preference to get reduced at the cathode and as a result, H2 is evolved.
NaCl(aq) → Na+(aq) + Cl-(aq)
At cathode: 2 H2O(l) + 2e- → H2(g) + 2OH-(aq)
At anode: Cl- → Cl(g) + e-
2Cl(g) → Cl2(g)
