We introduce and test an expression for calculating the variance of a physical field in three dimensions using only information contained in the two-dimensional projection of the field. The method is general but assumes statistical isotropy. To test the method we apply it to numerical simulations of hydrodynamic and magnetohydrodynamic turbulence in molecular clouds, and demonstrate that it can recover the three-dimensional (3D) normalized density variance with 10 per cent accuracy if the assumption of isotropy is valid. We show that the assumption of isotropy breaks down at low sonic Mach number if the turbulence is sub-Alfv??nic. Theoretical predictions suggest that the 3D density variance should increase proportionally to the square of the Mach number of the turbulence. Application of our method will allow this prediction to be tested observationally and therefore constrain a large body of analytic models of star formation that rely on it.