An Airlock can also be used in brewing and is a simple 'S' shaped piece of plastic tubing that is half filled with water. When fitted into the top of a carboy by a rubber stopper the airlock allows waste carbon dioxide to escape while preventing outside air from bringing in bacteria that may spoil the batch. The positive pressure of the CO2 inside of the carboy pushes out individual bubbles of carbon dioxide through the water and out to the air.
The same principle, used with water, is found in the lockss used on canals.