### Theory:

Extracting Metals towards the Top of the activity Series
Metals at the top of the reactivity scale are extremely reactive. By heating with carbon, they cannot be extracted from their compounds. For example, carbon cannot convert oxides of sodium, magnesium, calcium, aluminium, etc. to their respective metals. This is due to the fact that these metals have a higher affinity for oxygen than carbon. Electrolytic reduction is used to obtain these metals. For example, sodium, magnesium, and calcium are obtained via electrolysis of their molten chlorides. Metals are deposited at the cathode (the negatively charged electrode), while chlorine is released at the anode (the positively charged electrode). The reactions are as follows:

At cathode: ${\mathit{Na}}^{+}+{e}^{-}\stackrel{}{⟶}\phantom{\rule{0.147em}{0ex}}\mathit{Na}$

At anode: $2{\mathit{Cl}}^{-}\stackrel{}{⟶}\phantom{\rule{0.147em}{0ex}}{\mathit{Cl}}_{2\left(g\right)}+{\mathit{2e}}^{-}$

Similarly, electrolytic reduction of aluminium oxide yields aluminium. The metals produced by the above-mentioned reduction methods are not very pure. They contain impurities that must be eliminated before pure metals can be obtained. Electrolytic refining is the most common method for purifying impure metals.
Electrolytic refining
Copper, zinc, tin, nickel, silver, gold and other metals are purified electrolytically. The anode is constructed of impure metal, whereas the cathode is made of a narrow strip of pure metal. An electrolyte is a solution of metal salt. The pure metal from the anode dissolves into the electrolyte as the current is passed through it. On the cathode, an equivalent amount of pure metal from the electrolyte is deposited. The soluble impurities dissolve in the solution whereas the insoluble impurities gets collected at the bottom of the anode which is called anode mud.

Electrolytic refining of metals
Reference: