A dog's mouth is a cooling station for its entire body. The trick is circulation. As moisture evaporates from the tongue and respiratory passages, it absorbs heat from nearby tissues and blood; that cooled blood then travels through the body, collecting heat from elsewhere.
The machinery is more elegant than it looks. Evaporation requires energy, supplied in part as heat from the wet surfaces of the mouth and airways. Blood vessels close to those surfaces help transfer heat from circulating blood to the sites of evaporation. Thermoregulation depends on this exchange: the heart keeps blood moving between warmer tissues and the places where heat can escape. Each breath helps. Unlike people, dogs rely far less on sweating across the skin, although their paw pads do contain sweat glands. Panting works best when evaporated moisture can leave the airways; hot, humid conditions make that harder.
A pant, though, is not always a request for a cooler room. Exercise raises heat production, while excitement and stress can change breathing even when temperature is not the main issue. Context matters here. Persistent or unusually heavy panting, especially with weakness, collapse or distress, calls for prompt veterinary attention; heatstroke is an emergency. Move an overheated dog to a cool place and seek veterinary help without delay. For all its noise, the open mouth tells only part of the story: beneath it, a quiet river of blood carries the relief away.