Electrolysis uses electricity to break down an ionic compound that is molten or dissolved in water. Two electrodes dip into the liquid. The electrode connected to the negative terminal of the power supply is the cathode, and the electrode connected to the positive terminal is the anode.
Positive ions are called cations and they move to the cathode. Negative ions are called anions and they move to the anode. Metal ions and hydrogen ions are positively charged, so metals (or hydrogen) are formed at the cathode. Non-metal ions are negatively charged, so non-metals are formed at the anode.
Inert electrodes, such as graphite or platinum, only carry the current. They do not react, so the products come from the ions in the liquid.