For calculating the energy of a surface, we need to split the contribution of the surface and the contribution of the bulk to the total energy.
$$E_\mathrm{total} = E_\mathrm{surface} + E_\mathrm{bulk}$$
The term $E_\mathrm{total}$ is obtained from a calculation on a simulation cell that models the surface (let this be Calculation 1). The term $E_\mathrm{bulk}$ is obtained from a calculation that only contains the material in bulk (let this be Calculation 2).
Since the simulation cells are different, we must normalise the contribution of the energy. This is usually done by dividing the calculated energy by the number of atoms (or formula units) in the simulation cell. If $n_2$ is the number of atoms (or formula units) in the simulation cell in Calculation 2, the energy contribution per atom (or formula unit) be
$$E'_\mathrm{bulk} = \frac{E_\mathrm{bulk}}{n_2}$$
Now, we can subtract the contribution of the bulk and obtain the surface contribution. If $n_1$ is the number of atoms (or formula units) in the simulation cell in Calculation 1 (see point 1 below), the surface contribution will be:
$$E_\mathrm{surface} = E_\mathrm{total} - n_1 E'_\mathrm{bulk}$$
Surface energy is also usually normalised with the area. Hence, if $A$ is the area of the surface (see point 2 below), the final expression will become
$$ E'_\mathrm{surface} = \frac{1}{A} \left( E_\mathrm{total} - n_1 E'_\mathrm{bulk} \right)$$
Points to note:
- Even though some of the atoms in Calculation 1 are part of the "surface", we must still include them in $n_1$ while calculating the bulk contribution because the surface energy is defined as the excess energy due to a surface. So the energy in the bulk is simply the reference energy using which we calculate the contribution of the surface.
- When slab models are used to model the surface, and if the energy calculations use periodic boundary conditions, then the contribution to area $A$ will actually be 2 times the area of one surface.
- The only input we need here is the energy, so irrespective of what atomistic modelling method we use to calculate the energy, this procedure can be used to get the surface energy.