Fish have gills because these organs are used to extract oxygen from the surrounding water in which a fish lives. Gills are different from lungs because gills generally work unidirectionally: water moves in one direction across the gills in order for the organs to extract oxygen.
Gills are specialized organs adapted to harvest the dissolved oxygen content of water, which is generally much lower than the oxygen content of air. Through the use of many small structures located on either side of the fish's throat, fish gills absorb the dissolved oxygen from the surrounding water by ram ventilation, buccal pumping or a combination of these methods to pass water over the gills.
Ram ventilation occurs in fish that lack the buccal, or cheek, muscles to pump water over the gills that would take over when the fish stops swimming. Ram ventilation requires the fish to constantly swim forward to avoid drowning.
Buccal pumping occurs in fish that possess cheek muscles to pump water over the gills. This adaptation is especially useful for bottom-dwelling and ambush fish, which must remain still to hunt and to hide from other predators. While swimming, fish that have sufficient buccal muscles can use both ram ventilation and buccal pumping to breathe.