Initially, in an attempt to understand the behavior of metals, Physicists had a model called the “free electron model of metals”.
In this model they assumed the electrons inside the metal to be completely free and not considered any interactions of electrons with the nucleus or themselves. This is why it is called free electron model.
Hence the system basically becomes that of electrons inside a free potential well. Where clearly the boundary of the potential well will be the boundary of the solid.
So when we do the Quantum Mechanics of the system, we get energy levels. When the electrons start occupying these levels, there will be a final level after which there will be no more electrons to get filled. This energy level or energy value is called the Fermi energy of the material.