In thermodynamics, the internal energy U is an energy form that results from the random motion of microscopic particles in a system. This thermal energy increases with increasing temperature T.

In 1842, Julius Robert von Mayer formulated the first law of thermodynamics:

The change in the internal energy of a system, dU, is equal to the amount of heat, dQ, added to the system plus the external work, dW, done on the system: Note that this simple formulation assumes that there are no changes in kinetic or potential energy for the system and that no mass flows in or out of the system.

By 1824, Nicolas Léonard Sadi Carnot had discovered the limitations on the conversion of thermal energy into work by the second law of thermodynamics, which is usually formulated today as:

In a closed thermodynamic system, entropy, S, always increases or, for a reversible process, remains constant: It is impossible to convert heat completely into work in a cyclic process (Kelvin statement); and heat generally cannot flow spontaneously from a material at lower temperature to a material at higher temperature (Clausius formulation). The latter explanation was used by Wilhelm Ostwald in 1892, see Links:  Carnot described a process, however, for obtaining the maximum work from a heat engine (like the engine in a car). This process is known as the Carnot Cycle. The reversible Carnot Cycle describes a continuously operating machine. The pressure-volume diagram (p-V) for an ideal gas within a Carnot Cycle shows on the left side two isothermal (constant temperature) lines and two isentropic (constant entropy) lines. Heat is added and removed in some steps, and work is extracted from the piston movement. The Carnot Cycle consists of four steps. The first step (1→2) consists of reversible, isothermal expansion at a hot temperature. This expansion is driven by the heat supplied from an outside heat source, Qh = ThS. The second step (2→3) is an isentropic (reversible adiabatic) expansion. The continued expansion of the gas causes it to cool to temperature Tc. The third step of the cycle (3→4) is the reversible, isothermal compression of the gas at the cooler temperature. The heat removed in this step is Qc = TcS. The final step (4→1) is an isentropic compression to the original state. When passing through the isotherms, heat is added (Qh = ThS) or removed (Qc = TcS) to keep the temperature constant.

From the first law of thermodynamics, the difference between Qh and Qc is the work, W, done by the system during the cycle. The efficiency, η, is the ratio of the work done by the system (W) to the heat put into the system (Qh = Th ∆S); thus the efficiency depends only on the temperatures Th and Tc: Note that one must use temperatures in the Kelvin scale for this equation. For example, if the coolant temperature is 20 °C (293 K) and the heating temperature is that of boiling water at 100 °C (373 K),
then 1 – 293/373 gives an efficiency of 21%. Real cycles have a lower efficiency than a Carnot Cycle.