Two Statements, One Law
The second law has two classical formulations that appear to concern different machines.
Kelvin-Planck: no cyclic process can take heat from a single reservoir and convert it entirely into work. Clausius: no cyclic process can transfer heat from a colder body to a hotter one with no other effect.
They are logically equivalent: assume a violation of either and you can construct a violation of the other. Couple a Kelvin-Planck violator to an ordinary refrigerator and the pair moves heat from cold to hot with no net work, breaking Clausius.
Analysing arbitrary cycles gives the Clausius inequality:
with equality exactly for reversible cycles. The equality case is the important one: if round every reversible loop, then is the differential of a state function. That function is entropy:
The subscript is essential. is a state function, so to compute for an irreversible process you invent any convenient reversible path between the same endpoints and integrate along that instead.
For an isolated system the inequality becomes the entropy increase principle, , with equality only for reversible change. Combining the first and second laws for a simple system gives the thermodynamic identity:
which contains no at all, every term is a state function differential, which is why it holds for any process whatever, reversible or not.
Mixing two different ideal gases at the same and raises the entropy by , which is strictly positive: mixing is spontaneous and unmixing costs work.
Common pitfall: using with the actual heat of an irreversible process. That underestimates the change every time. Entropy is defined through the reversible heat, so you must construct a reversible path between the same two states and use its heat instead.