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 air toward an IR light detector, which measures the amount of IR light that hits it. As the light passes through the tube, any gas molecules that are the same size as the wavelength of the IR light absorb the IR light light only, 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.