It detects unburned oxygen in the exhaust. The Engine Computer constantly switches the fuel / air mixture from rich to lean a few times per second and the sensor reports that back to the computer. During the lean part of the cycle, that extra oxygen is stored in the material in the catalytic converter. During the next half cycle, the extra unburned fuel mixes with that stored oxygen and is burned.
You would think a perfect mixture would be ideal, and that is correct for proper engine performance and lowest emissions, but with a perfect mixture there is no oxygen to measure in the exhaust. The sensor does not respond to unburned fuel, so if the exhaust went to the rich side, the computer would never know it. By watching the swings between rich and lean, the computer can figure out how to make the average mixture perfect.
Those oxygen sensors are always before the catalytic converter. On '96 and newer cars there will also be a downstream sensor. It could be the same part number but it has a different purpose. When the upstream sensor is working properly, it switches from rich to lean a couple of times per second. If the catalytic converter is working correctly, the exhaust leaving it will switch from a little rich to a little lean very slowly, perhaps only a few times per minute. That tells the computer that the converter is working. When is doesn't work properly to clean up the emissions, the downstream sensor will switch from rich to lean much faster. As its switching rate approaches that of the upstream sensor, the computer knows no change is taking place in the converter. That will turn on the Check Engine light and set the related diagnostic fault code in memory.