The study of the flow of energy during chemical reactions or phase changes is chemical thermodynamics. The energy involved in a chemical system is most often thermal energy. Heat is thermal energy that is transferred from one location to another. Any system that involves a transfer of heat is studied under the domain of thermodynamics. A refrigerator or air conditioner uses the principles of thermodynamics to move heat. An internal combustion engine in a car uses the principles of thermodynamics to generate motion, called useful work, by using heat.
Thermodynamics uses systems and surroundings to analyze the movement of energy. A system is the part of the universe that is under consideration. For example, a piston or the gas within a piston can be defined as a system. Anything that is not the system is the surroundings, the part of the universe that is in immediate contact with a system. Systems are defined as needed by scientists. Systems are most often defined so that the energy and mass moving into and out of a system can be easily tracked.
A system that allows for the flow of both energy (heat) and mass in and out of it is called an open system. A system that allows for the flow of energy (heat) but blocks the movement of mass is called a closed system. A system that allows neither energy (heat) nor mass to flow is called an isolated system.
The law of conservation of energy is the backbone of thermodynamics. Energy is conserved when a system and its surroundings are studied as a whole. Because the system plus its surroundings describe the entire universe, this means energy is conserved in the universe: