Mainstream capnography involves a CO2 sensor housed externally to the breathing circuit, with no gas removed from the circuit. Sidestream capnography uses a sensor inserted between the circuit and endotracheal tube, with gas constantly aspirated via a sampling tube to the sensor, resulting in a delayed waveform but minimal increase in dead space. Capnography can be used to time respiratory cycles and detect issues like bronchospasm, equipment malfunctions, esophageal intubation, and return of spontaneous circulation during CPR.