We investigate the evolution of the gas mass fraction for galaxies in the COSMOS field using submillimetre emission from dust at 850$mu$m. We use stacking methodologies on the 850$mu$m S2COSMOS map to derive the gas mass fraction of galaxies out to high redshifts, 0 <= $z$ <= 5, for galaxies with stellar masses of $10^{9.5} < M_* (rm M_{odot}) < 10^{11.75}$. In comparison to previous literature studies we extend to higher redshifts, include more normal star-forming galaxies (on the main sequence), and also investigate the evolution of the gas mass fraction split by star-forming and passive galaxy populations. We find our stacking results broadly agree with scaling relations in the literature. We find tentative evidence for a peak in the gas mass fraction of galaxies at around $z$ ~ 2.5-3, just before the peak of the star formation history of the Universe. We find that passive galaxies are particularly devoid of gas, compared to the star-forming population. We find that even at high redshifts, high stellar mass galaxies still contain significant amounts of gas.