This contribution discusses the free energy of complex dislocation microstructures, which is a fundamental property of continuum plasticity and thermodynamic models of microstructure evolution. In the past, multiple models of the self energy of dislocations have been proposed in the literature that partially contradict each other. In order to gain fundamental insight into the relationship between dislocation microstructures and the free energy associated with them, we use large scale molecular dynamics simulations of nanoindentation. During these simulations a realistic distribution of dislocations is formed as the result of natural dislocation nucleation and multiplication processes. By virtue of advanced analysis methods it becomes possible to quantify of dislocation densities and the associated free energies. Furthermore, it is possible to discriminate between statistically stored dislocation densities and geometrically necessary dislocation densities and their energies. The simulation results support a linear relation between the scalar (total) dislocation density and the free energy modified by a logarithmic factor that contains a length scale, which can be related to the smaller of either the length scale provided by the dislocation density or the dimensions of the deformed volume. Hence, these findings might influence continuum descriptions of plasticity in small volumes.