According to How Stuff Works, fire extinguishers use carbon dioxide to displace the oxygen necessary for a fire to burn, extinguishing the blaze. Fires need oxygen, fuel, and heat to ignite, and removing any one of those three components can put out a fire.
Carbon dioxide extinguishers work because carbon dioxide molecules are heavier than oxygen molecules. When the liquid carbon dioxide inside the extinguisher expands into a gas, the carbon dioxide pushes out any oxygen surrounding the fire. Without oxygen available to fuel the chemical reaction, the fire goes out quickly. This property can also make them dangerous in confined spaces since the carbon dioxide also pushes out any oxygen that the user needs to breathe.
In addition to carbon dioxide extinguishers, fire extinguishers use other methods to put out fires. Wet extinguishers spray a liquid that absorbs heat, similar to pouring water on a campfire. These extinguishers are not suitable for chemical or electrical fires since the liquid can conduct electricity and cause flammable agents to spread. Other extinguishers coat the fuel, forming a barrier between the flammable material and the oxygen in the surrounding air. These are suitable for all types of fires, but the chemicals involved can be expensive and dangerous.