We perform cosmological hydrodynamic simulations to determine to what extent galaxies lose their gas due to photoheating from an ionizing background. We find that the characteristic mass at which haloes on average have lost half of their baryons is Mc∼ 6.5 × 109 h−1 M⊙ at z= 0, which corresponds to a circular velocity of 25 km s−1. This is significantly lower than the filtering mass obtained by the linear theory, which is often used in semi-analytical models of galaxy formation. We demonstrate it is the gas temperature at the virial radius which determines whether a halo can accrete gas. A simple model that follows the merger history of the dark matter progenitors, and where gas accretion is not allowed when this temperature is higher than the virial temperature of the halo, reproduces the results from the simulation remarkably well. This model can be applied to any reionization history, and is easy to incorporate in semi-analytical models.