This is what is referred to as a non-spontaneous reaction which requires impetus.
At the cathode, reduction (in this case, the gain of electrons) occurs. At the anode, oxidation (in this case, the loss of electrons) occurs. Normally, the reaction is balanced with either an acid or a base as shown in the equations below.
the oxidation at anode: 2 H2O(l) → O2(g) + 4 H+(aq) + 4e−
That two reactions are half reactions. They are balanced with an acid. Commonly hydrochloric acid or sulfuric acid is used. However, the half reactions can also be balanced with a base, for example with sodium hydroxide.
the reduction at cathode: 2 H2O(l) + 2e− → H2(g) + 2 OH−(aq)
the oxidation at anode: 4 OH−(aq) → O2(g) + 2 H2O(l) + 4 e−
Combining one pair of half reactions leads to an overall reaction, which is then the decomposition of water into oxygen and hydrogen.