The product formed at the cathode depends on what you are electrolysing - in aqueous solutions it is often hydrogen; in molten electrolytes (ie molten salts) it is not a gas at all, but the metal.
It really is about whether you are electrolysing a molten salt or an aqueous one and the reactivity of the metals which provide the cations in the salt - in the former situation (molten salts), it is the metal ions which are attracted to the cathode where they get reduced to the corresponding metal atoms. It is worth noting that you typically need high temperatures to melt an ionic compound (ie a salt) and therefore electrolysis of molten salts is largely an industrial process carried out often to extract the more reactive metals like aluminium and sodium.
In aqueous solutions, however, there is effectively a 'competition' between water (which will provide hydrogen ions for reduction to hydrogen gas, releasing hydroxide ions into solution) and the metal ions which will be reduced to metal atoms.
Typically, if the metal itself is more reactive than hydrogen, then the metal ions are more stable and it is the hydrogen ions which are reduced (eg aqueous sodium chloride produces hydrogen gas at the cathode on electrolysis, not sodium metal). If the metal is less reactive than hydrogen, then it is the metal ions which are reduced (eg aqueous copper sulphate produces copper metal at the cathode, not hydrogen gas).
One last point: the products may also be influenced by the composition of the electrodes themselves, eg whether they are inert or not.