The canonical partition function Z of an ideal gas consisting of N = nN identical (non-interacting) particles, is:
where  is the thermal de Broglie wavelength:
with the usual definitions: h is the Planck constant, m the mass of a particle, k the Boltzmann constant and T the absolute temperature. In an ideal gas z is the partition function of a single particle in a container of volume V. In order to derive the Van der Waals equation we assume now that each particle moves independently in an average potential field offered by the other particles. The averaging over the particles is easy because we will assume that the particle density of the Van der Waals fluid is homogeneous.
The interaction between a pair of particles, which are hard spheres, is taken to be:
r is the distance between the centers of the spheres and d is the distance where the hard spheres touch each other (twice the Van der Waals radius). The depth of the Van der Waals well is .
Because the particles are not coupled under the mean field Hamiltonian, the mean field approximation of the total partition function still factorizes:
but the intermolecular potential necessitates two modifications to z. First, because of the finite size of the particles, not all of V is available, but only V − Nb′, where (just as in the conventional derivation above):
Second, we insert a Boltzmann factor
exp[−Φ/2kT] to take care of the average intermolecular potential. We divide here the potential by two because this interaction energy is shared between two particles. Thus:
The total attraction felt by a single particle is:
where we assumed that in a shell of thickness dr there are  particles. This is a mean field approximation; the position of the particles is averaged. In reality the density close to the particle is different than far away as can be described by a pair correlation function. Furthermore, it is neglected that the fluid is enclosed between walls.  Performing the integral we get:
Hence, we obtain:
From statistical thermodynamics we know that:
so that we only have to differentiate the terms containing . We get: