Quantum operations provide a general description of the state changes allowed by quantum mechanics. The reversal of quantum operations is important for quantum error–correcting codes, teleportation and reversing quantum measurements. We derive information–theoretic conditions and equivalent algebraic conditions that are necessary and sufficient for a general quantum operation to be reversible. We analyse the thermodynamic cost of error correction and show that error correction can be regarded as a kind of `Maxwell demon', for which there is an entropy cost associated with information obtained from measurements performed during error correction. A prescription for thermodynamically efficient error correction is given.