emission and absorption of photons
Picture an electron on its atomic staircase deciding to change steps. Going up costs energy; coming down releases it. The currency it trades in is the photon — a single packet of light. Absorption is an electron paying for a step up by swallowing a passing photon; emission is an electron paying for a step down by creating a fresh photon and flinging it away. This two-way traffic of light packets is how atoms talk to radiation.
The crucial rule is exactness. A photon's energy is fixed by its colour, and an electron may only absorb a photon whose energy matches a real gap between two of its levels — anything too big or too small simply passes by untouched. When the electron drops back down, the photon it emits carries away precisely that gap's worth of energy, and therefore precisely that colour. Because each element's gaps are unique, the photons it emits and absorbs trace out a unique pattern of wavelengths.
This is the engine behind every spectral line. A cloud of hot gas glows with emission photons at its element's special colours; the same cloud, sitting cool in front of a brighter source, steals exactly those colours out of the passing light, leaving dark absorption gaps. One mechanism, two appearances — and the whole science of reading starlight rests on it.
A sodium atom absorbs yellow light at 589 nm to lift an electron one step, then emits yellow light at the very same 589 nm when it drops back — the colour of a street lamp.
Absorb and emit are the same jump run backwards — same energy, same colour.
An electron does not always emit a photon when it drops — it can sometimes hand its energy to a neighbouring atom in a collision instead. Emission is one path down, not the only one.