Codes are "fault indicators"
The ECM monitors and controls the engine through various sensors and adjusts various things to maintain proper emissions levels. The ECM knows each sensors "normal range" and when a sensor or condition exceeds the given range the ECM logs the error and iluminates the "Check Engine" light.
Each sensor is given a code and certian conditions are given codes as well.
For example If an O2 sensor were to get coated with soot it will not be able to transmit accurate O2 levels in the exhaust. The mixture of air and fuel that goes into the engine will not be accurate either.
The ECM controls the Fuel/Air ratio by controlling the "Pulse width" of the injector. There is a max pulse range and a min pulse range stored into the ECMs memory for a given set of conditions (throttle position, air temp, engine load, vehicle speed, engine temp, ect ect ect). The ECM will try to bring the O2 levels back into a normal range by adjusting the (pulse width) mixture. Once the ECM reaches a point where it can no longer adjust the mixture to maintain proper O2 levels, the ECM sets a code and turns on the "idiot light" on the instrument panel.
Simple, huh?
The ECMs in our cars handle only a handfull of engine parameters compared to ones in newer cars. Our cars have only 1 ECM while newer cars have several and they can comunicate with each other to boot.