Electrons exist in energy levels (i.e. atomic orbitals) within an atom.  Atomic orbitals are quantized, meaning they exist as defined values instead of being continuous (see: atomic orbitals). Electrons may move between orbitals, but in doing so they must absorb or emit energy equal to the energy difference between their atom's specific quantized orbital energy levels.  In optical spectroscopy, energy absorbed to move an electron to a higher energy level (higher orbital) and/or the energy emitted as the electron moves to a lower energy level is absorbed or emitted in the form of photons (light particles).  Because each element has a unique number of electrons, an atom will absorb/release energy in a pattern unique to its elemental identity (e.g. Ca, Na, etc.) and thus will absorb/emit photons in a correspondingly unique pattern.  The type of atoms present in a sample, or the amount of atoms present in a sample can be deduced from measuring these changes in light wavelength and light intensity.
Atomic spectroscopy is further divided into atomic absorption spectroscopy and atomic emission spectroscopy. In atomic absorption spectroscopy, light of a predetermined wavelength is passed through a collection of atoms.  If the wavelength of the source light has energy corresponding to the energy difference between two energy levels in the atoms, a portion of the light will be absorbed.  The difference between the intensity of the light emitted from the source (e.g., lamp) and the light collected by the detector yields an absorbance value. This absorbance value can then be used to determine the concentration of a given element (or atoms) within the sample.  The relationship between the concentration of atoms, the distance the light travels through the collection of atoms, and the portion of the light absorbed is given by the Beer–Lambert law. In atomic emission spectroscopy, the intensity of the emitted light is directly proportional to the concentration of atoms.