Electrolysis in Solutions
When you dissolve ionic compounds in water, electrolysis becomes more interesting because you've got extra players in the game - the water molecules themselves can get involved!
Halide ions (like Cl⁻, Br⁻, F⁻) always get oxidised at the anode if they're present. If there aren't any halide ions around, oxygen gets oxidised instead, producing oxygen gas. This is why you might see bubbles forming during electrolysis.
At the cathode, it's all about reactivity. The less reactive cation gets reduced first. For example, H⁺ ions are less reactive than Na⁺ ions, so hydrogen gas forms whilst the sodium stays dissolved.
This selective process is brilliant for making useful products - like when electrolysing salt water produces sodium hydroxide solution, a strong alkali used in loads of industrial processes.
Remember: Halides at the anode, less reactive cations at the cathode - it's like a chemical popularity contest!