Halogens can be extracted from the electrolysis of concentrated halide solutions.
The halide ions lose electrons at the anode and are oxidised to atoms. For example,
2Br-(aq) → Br2(g) + 2e-
Production of chlorine
Industrially, chlorine is made by the electrolysis of brine.
Brine is a solution of water with high concentrations of salts (mainly sodium chloride and some bromides and iodides) occurring naturally in salt lakes and sea water, but can be made by dissolving rock salt in water.
At the cathode, hydrogen is produced, while at the anode chlorine is produced.
Sodium ions and hydroxide ions stay in solution, so a solution of sodium hydroxide is left.
The electrolysis cell is constantly fed with a fresh stream of brine, and the chlorine is collected as a gas.
Production of bromine and iodine
Bromine and iodine can be produced by bubbling chlorine gas through brine.
Because chlorine is more reactive than bromine and iodine it will displace them.
2Br-(aq) + Cl2(aq) → Br2(g) + 2Cl-(aq), bromine produced is collected, condensed into a liquid and purified.
2I-(aq) + Cl2(aq) → I2(aq) + 2Cl-(aq), iodine produced is collected, purified and condensed into a grey solid.