The third law of thermodynamics in the form of the unattainability principle states that exact ground-state cooling requires infinite resources. Here, we investigate the amount of nonequilibrium resources needed for approximate cooling. We consider as a resource any system out of equilibrium, allowing for resources beyond the independent and identically distributed assumption and including the input of work as a particular case. We establish in full generality a sufficient and a necessary condition for cooling and show that, for a vast class of nonequilibrium resources, these two conditions coincide, providing a single necessary and sufficient criterion. Such conditions are expressed in terms of a single function playing a role for the third law similar to the one of the free energy for the second law. From a technical point of view, we provide new results about the concavity or convexity of certain Renyi divergences, which might be of independent interest.