Hydrogen fuel cells work by the reverse of electrolysis.
Electrolysis is the electrification of water to split the water into hydrogen and oxygen.
A hydrogen fuel cell creates a controlled reaction between hydrogen and oxygen that produces electricity, water and heat. These protons pass through an electrolyte between the anode and cathode sides. Once the protons get to the cathode side they combine with oxygen and electrons from the cathode electrode to produce water. The freeing of electrons on the anode side and the recapturing on the cathode side produces an electric current. The fuel cell electrochemically combines air with fuel and converts it directly into electricity.