An airlock is a device that allows air or gas to leave the fermenting vessel while preventing oxygen and bugs/debris from entering the vessel.
There are different types of airlocks, however, the most common is a bubble airlock, which holds water inside it and as the gas escapes you can see bubbles or activity. Depending on how active the yeast is and the production of gas is, these bubbles will be more or less frequent. The water allows the gas to push itself out, but does not allow anything in.
Note: The airlock isn’t always the best way to determine the fermentation activity. So, if you find that it isn't bubbling, it doesn't mean that the beer isn't fermenting. For more information on what to do if you don't see bubbling, see here.
There are also carbon block airlocks. They are usually a densely compact block of carbon, which allows gas to escape through its tiny holes and also absorbs some of it, while not allowing anything back in the other way.