One of the fundamental laws of physics is the conservation of energy.
The law of conservation of energy states that "the total energy of a closed system, that is, a system that is isolated from its surroundings, is conserved." Even if energy transformation happens, the overall energy in a system is conserved according to the law.
Energy cannot be generated or destroyed; it can only be changed from one state to another.
For example, Heat is used to generate steam which moves the pistons and thereby converting heat energy to mechanical energy.