The production of formic acid (HCOOH) in cold and hot regions of the interstellar medium is not well understood. Recent gas-phase experiments and gas-grain models hint at a solid-state production process at low temperatures. Several surface reaction schemes have been proposed in the past decades, even though experimental evidence for their efficiency was largely lacking. The aim of this work is to give the first experimental evidence for an efficient solid-state reaction scheme providing a way to form HCOOH under astronomical conditions. Several surface reaction channels have been tested under fully controlled experimental conditions by using a state-of-the-art ultrahigh vacuum set-up through co-deposition of H atoms and CO:O2 mixtures with 4:1, 1:1 and 1:4 ratios. During deposition spectral changes in the ice are monitored by means of a Fourier transform infrared (FTIR) spectrometer in reflection absorption infraRed (RAIR) mode. After co-deposition a temperature programmed desorption (TPD) experiment is performed and gas-phase molecules are detected by a quadrupole mass spectrometer (QMS). Formation of HCOOH is observed at low temperatures mainly through hydrogenation of the HO–CO complex, while reactions with the HCO radical as intermediate are found to be inefficient. The HO–CO complex channel, which was previously not considered as an important HCOOH formation route, can explain the presence of HCOOH in dense cold clouds, at the beginning of the warm-up phase of a protostar, and, therefore, is likely to be astrochemically relevant.