The CMB represents the universe's 'last scattering surface,' originating when the universe was approximately 380,000 years old and had cooled sufficiently for atoms to form.
In the very early universe, the cosmos was a scorching hot, dense plasma of charged particles — electrons, protons, and helium nuclei — where photons were constantly scattering off free electrons, unable to travel far. This state is often likened to a fog, making the universe opaque. As the universe expanded, it cooled. Approximately 380,000 years after the Big Bang, the temperature dropped to around 3,000 Kelvin (about 2,700 degrees Celsius), allowing electrons to combine with atomic nuclei to form stable, neutral atoms (primarily hydrogen and helium). This event, known as 'recombination,' dramatically reduced the number of free electrons. Consequently, photons were no longer constantly scattered and could 'decouple' from matter, streaming freely through space. These decoupled photons, having travelled across the vast expanse of the expanding universe for billions of years, constitute the CMB we observe today. Due to cosmic expansion, their wavelengths have been stretched (redshifted) into the microwave part of the electromagnetic spectrum, and their effective temperature has plummeted to just 2.725 Kelvin above absolute zero.