The properties of both observed galaxies and dark matter haloes in simulations depend on their environment. The term ‘environment’ has, however, been used to describe a wide variety of measures that may or may not correlate with each other. Popular measures of environment include, for example, the distance to the Nth nearest neighbour, the number density of objects within some distance or, for the case of galaxies only, the mass of the host dark matter halo. Here we use results from the Millennium Simulation and a semi-analytic model for galaxy formation to quantify the relations between different measures of environment and halo mass. We show that the environmental parameters used in the observational literature are in effect measures of halo mass, even if they are measured for a fixed stellar mass. The strongest correlation between environmental density and halo mass arises when the number of objects is counted out to a distance of 1.5–2 times the virial radius of the host halo and when the galaxies/haloes are required to be relatively bright/massive. For observational studies, this virial radius is not easily determined, but the number of neighbours out to 1–2 h−1 Mpc gives a similarly strong correlation with halo mass. For the distance to the Nth nearest neighbour, the (anti)correlation with halo mass is nearly as strong provided N≥ 2. We demonstrate that this environmental parameter becomes insensitive to halo mass if it is constructed from dimensionless quantities. This can be achieved by scaling the minimum luminosity/mass of neighbours to that of the object that the environment is determined for and by dividing the distance to a length-scale associated with either the neighbour or the galaxy under consideration. We show how such a halo mass independent environmental parameter can be defined for both observational and numerical studies. The results presented here will help future studies to disentangle the effects of halo mass and external environment on the properties of galaxies and dark matter haloes.