In our industry, many of us use the term "NDIR CO2 sensor", without thinking about what it stands for, or how NDIR sensors actually work.
NDIR is an industry term for "nondispersive infrared", and is the most common type of sensor used to measure CO2.
An infrared (IR) lamp directs waves of light through a tube filled with a sample of air toward an IR light detector, which measures the amount of IR light that hits it.
The 4.2 micron band of IR radiation produced by the lamp is very close to the 4.26 micron absorption band of CO2. Because the IR spectrum of each molecule is unique, it can serve as a signature or "fingerprint" to identify the CO2 molecule.
As the IR light passes through the tube, the CO2 gas molecules absorb the specific band of IR light while letting other wavelengths of light pass through. Next, the remaining light hits an optical filter that absorbs every wavelength of light except the exact wavelength absorbed by CO2.
Finally, an IR detector reads the amount of light that was not absorbed by the CO2 molecules or the optical filter.
The difference between the amount of light radiated by the IR lamp and the amount of IR light received by the detector is measured. The difference is proportional to the number of CO2 molecules in the air inside the tube.
Of course, this is a very simplified explanation. If you want to learn more about NDIR, this Wikipedia article is a great place to start.