The relationship between thermodynamics and statistical physics is valid in the thermodynamic limit when the number of particles becomes very large. Here we study thermodynamics in the opposite regime at both the nano scale, and when quantum effects become important. Applying results from Single shot quantum information theory we construct a theory of thermodynamics in these extreme limits. In the quantum regime, we find that the standard free energy no longer determines the amount of work which can be extracted from a resource, nor which state transitions can occur spontaneously. We derive a general criteria for thermodynamical state transitions, and also find two free energies: one which determines the amount of work which can be deterministically extracted from a small system in contact with a heat bath, and the other which quantifies the reverse process. They imply that generically, there are additional constraints which govern spontaneous thermodynamical processes. We find that there are fundamental limitations on work extraction from nonequilibrium states, due to both finite size effects which are present at the nano scale, as well as quantum coherences. This implies that thermodynamical transitions are generically irreversible at this scale, and we quantify the degree to which this is so, and find the condition for reversibility to hold. There are particular processes which approach the ideal efficiency, provided that certain special conditions are met. As one application of these methods, we analyse the efficiency of small heat engines and find that they are irreversible during the adiabatic stages of the cycle.