Valence electrons are the outermost electrons of an atom that can be gained or lost to form ions. Atoms are most stable when they have 8 valence electrons, as this allows them to achieve a full valence shell configuration. Atoms will gain or lose electrons through bonding to reach the stable configuration of 8 valence electrons. Metals tend to lose or gain one electron to achieve stability, while non-metals gain or lose 7 electrons. During flame tests, atoms absorb energy and their electrons become excited, moving to higher energy states. When the electrons fall back to the ground state, they emit photons of light of specific colors.