An electron that is far away from the nucleus have higher energy than an electron near the nucleus. Nucleus are positively charged and those electrons near it get attracted; those electrons gain kinetic energy hence reducing their internal energy. The electrons far from nucleus have low kinetic energy hence more internal energy.