For a fire to sustain itself three things are necessary, a fuel supply, oxygen and a sufficiently high temperature. Fire extinguishers work by cutting off the supply of oxygen and reducing the temperature. Some fire extinguishers can also cut the supply of fuel to the fire.
There are many different types of fire extinguishers each of which is appropriate for a particular type of fire. Water is extensively used as a fire extinguisher.
It works by reducing the temperature as the heat is absorbed by the water and it gets converted to water vapor. Water cannot be used in cases where electricity is the cause of the fire as water conducts electricity, it also cannot be used when the fuel can float on water or the fuel reacts with water to cause an explosion.
In these cases foam based extinguishers or dry powder extinguishers and carbon dioxide extinguishers can be used. Foam and powder based extinguishers cut the supply of oxygen to the fuel. These also release carbon dioxide at high temperatures that works to smother the fire. Carbon dioxide extinguishers also cut the supply of oxygen with carbon dioxide. Also, as the carbon dioxide is stored in the extinguisher under very high temperatures, it has a very cold temperature when it emerges which acts to reduce the temperature below that required to sustain the fire.