Your car's onboard diagnostic system — OBD-II in any vehicle made after 1996 — runs continuous and readiness tests across hundreds of parameters. Sensors monitor oxygen content in the exhaust, fuel trim, ignition timing, transmission temperatures, emissions control systems, and dozens of other values. When any reading falls outside the acceptable range, the system logs a diagnostic trouble code (DTC) and illuminates the check engine light.
The code is a starting point, not a diagnosis. A P0420 code (catalyst efficiency below threshold) could mean a failing catalytic converter — or it could mean an oxygen sensor that's giving a bad reading, or an exhaust leak upstream of the sensor that's skewing the data. A code tells you what system is reporting a problem. A technician determines why.