Due to a set of scientific laws called quantum mechanics that you will have to take on faith. The particular energies that an electron can have are called energy levels. Normally electrons are in the state of lowest energy called the ground state.
All electrons are in the lowest possible energy levels.
However if an atom absorbs energy it can go into an excited state. An important fact is that the energy levels of different types of atoms are different. Energy levels of hydrogen are different from those of carbon. Remember this since this is the key to how astronomers figure out the compositions of objects. Consider an H atom in ground state.