Hydrogen has been used as a fuel in various experiments. The largest-scale experiment I'm aware of is the BMW Hydrogen 7, a 7-series V12 produced from 2005-2007. About 100 were built.
This engine could be switched from gasoline to hydrogen.
The difference in fuel consumption is largely due to the different energy density with gasoline (petrol) yielding 34.6 MJ/L and liquid hydrogen yielding 10.1 MJ/L. Based on these energy density figures, one would expect 47.6 L/100 km for hydrogen based on 13.9 L/100 km for gasoline (petrol); which is very close to the stated 50.0 L/100 km.
The big challenge with hydrogen is storing it:
The hydrogen fuel is stored in a large, nearly 170 litre (45 gallon),[6] bi-layered and highly insulated tank that stores the fuel as liquid rather than as compressed gas, which BMW says offers 75% more energy per volume as a liquid than compressed gas at 700 bars of pressure.[7] The hydrogen tank’s insulation is under high vacuum in order to keep heat transfer to the hydrogen to a bare minimum, and is purportedly equivalent to a 17-metre (56 ft) thick wall of polystyrene Styrofoam.[8]
To stay a liquid, hydrogen must be super-cooled and maintained at cryogenic temperatures of, at warmest, −253 °C (−423.4 °F). When not using fuel, the Hydrogen 7’s hydrogen tank starts to warm and the hydrogen starts to vaporize. Once the tank’s internal pressure reaches 87 psi, at roughly 17 hours of non-use, the tank will safely vent the building pressure. Over 10–12 days, it will completely lose the contents of the tank because of this.[9]
The tank is large and heavy, and only a tiny fraction of its weight is fuel:
The hydrogen fuel tank holds roughly 8 kg (18 lb) of hydrogen, enough to travel 201 kilometres (125 mi). The curb weight of the Hydrogen 7 is roughly 250 kilograms (550 lb) heavier than the 760Li...
A third method is storage in a metal hydride. IIRC Mercedes experimented with that in the 1980s, but their fuel tank reportedly cost over $100,000 making it unpractical.
Performance also suffers when running on hydrogen. The conventional BMW V12 develops 327 kW. The hydrogen car was limited to 191 kW.
The car is powered by a 6.0 litre V12 engine capable of running on both premium gasoline and hydrogen fuel. It is rated at 191-kilowatt (260 PS; 256 hp) and 390 N·m (290 lb·ft) of torque using either fuel.[4]