First, realize that for combustion to occur, there needs to be
fuel (such as hydrocarbon) and a source of
oxygenates (i.e. oxygen and/or molecules or partial molecules which contain oxygen). In addition, there are
diluents which are present in the mixture but do not contribute to the actual combustion (for example, nitrogen [N2]). This holds true for any combustion event, whether inside of an internal combustion engine or a small campfire.
Second, every atom is conserved in the combustion process, so it is possible to use exhaust gas constituents to reconstruct the amount of fuel and oxygenates before combustion. If this was not the case, then wideband oxygen sensors would not be capable of determining pre-combustion air/fuel ratio.
It is possible to express the combustion event as a balance of input reactants: fuel, oxygenates, and diluents (for example gasoline mixed with air) to the resultant combustion products (i.e. the composition of exhaust gas). Note that this is a chemical
balance, meaning that every element needs to be accounted for in its molecular balance, before and after the combustion event. In other words, if we know the proportions of fuel, oxygenates, and diluents entering the engine, one can determine the species composition in the exhaust gas. And we can work backwards. If we know the species in the exhaust we can determine the ratios of air and fuel (both in molar quantity and molecular mass).