In a thermodynamic system, differences in pressure, density, and temperature all tend to equalize over time. For example, consider a room containing a glass of melting ice as one system. The difference in temperature between the warm room and the cold glass of ice and water is equalized as heat from the room is transferred to the cooler ice and water mixture. Over time the temperature of the glass and its contents and the temperature of the room achieve balance. The entropy of the room has decreased. However, the entropy of the glass of ice and water has increased more than the entropy of the room has decreased. In an isolated system, such as the room and ice water taken together, the dispersal of energy from warmer to cooler regions always results in a net increase in entropy. Thus, when the system of the room and ice water system has reached temperature equilibrium, the entropy change from the initial state is at its maximum. The entropy of the thermodynamic system is a measure of how far the equalization has progressed.

There are many irreversible processes that result in an increase of the entropy. See: Entropy production. One of them is mixing of two or more different substances, occasioned by bringing them together by removing a wall that separates them, keeping the temperature and pressure constant. The mixing is accompanied by the entropy of mixing. In the important case of mixing of ideal gases, the combined system does not change its internal energy by work or heat transfer; the entropy increase is then entirely due to the spreading of the different substances into their new common volume.

From a *macroscopic perspective*, in classical thermodynamics, the entropy is a state function of a thermodynamic system: that is, a property depending only on the current state of the system, independent of how that state came to be achieved. Entropy is a key ingredient of the Second law of thermodynamics, which has important consequences e.g. for the performance of heat engines, refrigerators, and heat pumps.

According to the Clausius equality, for a closed homogeneous system, in which only reversible processes take place,

∮
δ
Q
T
=
0.
With T being the uniform temperature of the closed system and delta Q the incremental reversible transfer of heat energy into that system.

That means the line integral
∫
L
δ
Q
T
is path independent.

So we can define a state function *S*, called entropy, which satisfies

d
S
=
δ
Q
T
.
For simplicity, we examine a uniform closed system, whose thermodynamic state is determined by its temperature *T* and pressure *P*. A change in entropy can be written as

d
S
=
(
∂
S
∂
T
)
P
d
T
+
(
∂
S
∂
P
)
T
d
P
.
The first contribution depends on the heat capacity at constant pressure *C*_{P} through

(
∂
S
∂
T
)
P
=
C
P
T
.
This is the result of the definition of the heat capacity by δ*Q* = *C*_{P}d*T* and *T*d*S* = δ*Q*. For rewriting the second term we use one of the Maxwell relations

(
∂
S
∂
P
)
T
=
−
(
∂
V
∂
T
)
P
and the definition of the volumetric thermal-expansion coefficient

α
V
=
1
V
(
∂
V
∂
T
)
P
so that

d
S
=
C
P
T
d
T
−
α
V
V
d
P
.
With this expression the entropy *S* at arbitrary *P* and *T* can be related to the entropy *S*_{0} at some reference state at *P*_{0} and *T*_{0} according to

S
(
P
,
T
)
=
S
(
P
0
,
T
0
)
+
∫
T
0
T
C
P
(
P
0
,
T
′
)
T
′
d
T
′
−
∫
P
0
P
α
V
(
P
′
,
T
)
V
(
P
′
,
T
)
d
P
′
.
In classical thermodynamics the entropy of the reference state can be put equal to zero at any convenient temperature and pressure. For example, for pure substances, one can take the entropy of the solid at the melting point at 1 bar equal to zero. From a more fundamental point of view, the third law of thermodynamics suggests that there is a preference to take *S* = 0 at *T* = 0 (absolute zero) for perfectly ordered materials such as crystals.

In order to determine *S*(*P,T*) we followed a specific path in the *P-T* diagram: first we integrated over *T* at constant pressure *P*_{0}, so that d*P*=0, and in the second integral we integrated over *P* at constant temperature *T*, so that d*T*=0. As the entropy is a function of state the result is independent of the path.

The above relation shows that the determination of the entropy requires knowledge of the heat capacity and the equation of state (which is the relation between *P*,*V*, and *T* of the substance involved). Normally these are complicated functions and numerical integration is needed. In simple cases it is possible to get analytical expressions for the entropy. In the case of an ideal gas, the heat capacity is constant and the ideal gas law *PV = nRT* gives that *α*_{V}*V* = *V/T* = *nR/p*, with *n* the number of moles and *R* the molar ideal-gas constant. So, the molar entropy of an ideal gas is given by

S
m
(
P
,
T
)
=
S
m
(
P
0
,
T
0
)
+
C
P
ln
T
T
0
−
R
ln
P
P
0
.
In this expression *C*_{P} now is the *molar* heat capacity.

The entropy of inhomogeneous systems is the sum of the entropies of the various subsystems. The laws of thermodynamics hold rigorously for inhomogeneous systems even though they may be far from internal equilibrium. The only condition is that the thermodynamic parameters of the composing subsystems are (reasonably) well-defined.

Nowadays the entropy values of important substances can be obtained via commercial software in tabular form or as diagrams. One of the most common diagrams is the temperature-entropy diagram (Ts-diagram). An example is Fig.2 which is the Ts-diagram of nitrogen. It gives the melting curve and saturated liquid and vapor values together with isobars and isenthalps.

We now consider inhomogeneous systems in which internal transformations (processes) can take place. If we calculate the entropy *S*_{1} before and *S*_{2} after such an internal process the Second Law of Thermodynamics demands that *S*_{2} ≥ *S*_{1} where the equality sign holds if the process is reversible. The difference *S*_{i} = *S*_{2} - *S*_{1} is the entropy production due to the irreversible process. The Second law demands that the entropy of an isolated system cannot decrease.

Suppose a system is thermally and mechanically isolated from the environment (isolated system). For example, consider an insulating rigid box divided by a movable partition into two volumes, each filled with gas. If the pressure of one gas is higher, it will expand by moving the partition, thus performing work on the other gas. Also, if the gases are at different temperatures, heat can flow from one gas to the other provided the partition allows heat conduction. Our above result indicates that the entropy of the system *as a whole* will increase during these processes. There exists a maximum amount of entropy the system may possess under the circumstances. This entropy corresponds to a state of *stable equilibrium*, since a transformation to any other equilibrium state would cause the entropy to decrease, which is forbidden. Once the system reaches this maximum-entropy state, no part of the system can perform work on any other part. It is in this sense that entropy is a measure of the energy in a system that cannot be used to do work.

An irreversible process degrades the performance of a thermodynamic system, designed to do work or produce cooling, and results in entropy production. The entropy generation during a reversible process is zero. Thus entropy production is a measure of the irreversibility and may be used to compare engineering processes and machines.

Clausius' identification of *S* as a significant quantity was motivated by the study of reversible and irreversible thermodynamic transformations. A heat engine is a thermodynamic system that can undergo a sequence of transformations which ultimately return it to its original state. Such a sequence is called a cyclic process, or simply a *cycle*. During some transformations, the engine may exchange energy with its environment. The net result of a cycle is

- mechanical work done by the system (which can be positive or negative, the latter meaning that work is done
*on* the engine),
- heat transferred from one part of the environment to another. In the steady state, by the conservation of energy, the net energy lost by the environment is equal to the work done by the engine.

If every transformation in the cycle is reversible, the cycle is reversible, and it can be run in reverse, so that the heat transfers occur in the opposite directions and the amount of work done switches sign.

Consider a heat engine working between two temperatures *T*_{H} and *T*_{a}. With *T*_{a} we have ambient temperature in mind, but, in principle it may also be some other low temperature. The heat engine is in thermal contact with two heat reservoirs which are supposed to have a very large heat capacity so that their temperatures do not change significantly if heat *Q*_{H} is removed from the hot reservoir and *Q*_{a} is added to the lower reservoir. Under normal operation *T*_{H} > *T*_{a} and *Q*_{H}, *Q*_{a}, and *W* are all positive.

As our thermodynamical system we take a big system which includes the engine and the two reservoirs. It is indicated in Fig.3 by the dotted rectangle. It is inhomogeneous, closed (no exchange of matter with its surroundings), and adiabatic (no exchange of heat *with its surroundings*). It is not isolated since per cycle a certain amount of work *W* is produced by the system given by the First law of thermodynamics

W
=
Q
H
−
Q
a
.
We used the fact that the engine itself is periodic, so its internal energy has not changed after one cycle. The same is true for its entropy, so the entropy increase *S*_{2} - *S*_{1} of our system after one cycle is given by the reduction of entropy of the hot source and the increase of the cold sink. The entropy increase of the total system *S*_{2} - *S*_{1} is equal to the entropy production *S*_{i} due to irreversible processes in the engine so

S
i
=
−
Q
H
T
H
+
Q
a
T
a
.
The Second law demands that *S*_{i} ≥ 0. Eliminating *Q*_{a} from the two relations gives

W
=
(
1
−
T
a
T
H
)
Q
H
−
T
a
S
i
.
The first term is the maximum possible work for a heat engine, given by a reversible engine, as one operating along a Carnot cycle. Finally

W
=
W
m
a
x
−
T
a
S
i
.
This equation tells us that the production of work is reduced by the generation of entropy. The term *T*_{a}*S*_{i} gives the *lost work*, or dissipated energy, by the machine.

Correspondingly, the amount of heat, discarded to the cold sink, is increased by the entropy generation

Q
a
=
T
a
T
H
Q
H
+
T
a
S
i
=
Q
a
,
m
i
n
+
T
a
S
i
.
These important relations can also be obtained without the inclusion of the heat reservoirs. See the Article on entropy production.

The same principle can be applied to a refrigerator working between a low temperature *T*_{L} and ambient temperature. The schematic drawing is exactly the same as Fig.3 with *T*_{H} replaced by *T*_{L}, *Q*_{H} by *Q*_{L}, and the sign of *W* reversed. In this case the entropy production is

S
i
=
Q
a
T
a
−
Q
L
T
L
and the work needed to extract heat *Q*_{L} from the cold source is

W
=
Q
L
(
T
a
/
T
L
−
1
)
+
T
a
S
i
.
The first term is the minimum required work, which corresponds to a reversible refrigerator, so we have

W
=
W
m
i
n
+
T
a
S
i
i.e., the refrigerator compressor has to perform extra work to compensate for the dissipated energy due to irreversible processes which lead to entropy production.