  The second law of thermodynamics states that a system in contact with a heat
bath can undergo a transformation if and only if its free energy decreases.
However, the "if" part of this statement is only true when the effective heat
bath is infinite. In this article we remove this idealization and derive
corrections to the second law in the case where the bath has a finite size, or
equivalently finite heat capacity. This can also be translated to processes
lasting a finite time, and we show that thermodynamical reversibility is lost
in this regime. We do so in full generality, that is without assuming any
particular model for the bath, the only parameters defining the bath are its
temperature and heat capacity. We find connections with second order Shannon
information theory, in particular in the case of Landauer erasure. We also
consider the case of non-fluctuating work, and derive finite-bath corrections
to the min and max free energies employed in single-shot thermodynamics.
