The concept of function arises at all levels of biological study and is often loosely and variously defined, especially within ecology. This has led to ambiguity, obscuring the common structure that unites levels of biological organisation, from molecules to ecosystems. Here we build on already successful ideas from molecular biology and complexity theory to create a precise definition of biological function which spans scales of biological organisation and can be quantified in the unifying currency of biomass, enabling comparisons of functional effectiveness (irrespective of the specific function) across the field of ecology. We give precise definitions of ecological and ecosystem function that bring clarity and precision to studies of biodiversity-ecosystem function relationships and questions of ecological redundancy. To illustrate the new concepts and their unifying power, we construct a simple community-level model with nutrient cycling and animal-plant mutualism, emphasising the importance of its network structure in determining overall functioning. This type of network structure is that of an autocatalytic set of functional relationships, which also appears at biochemical, cellular and organism levels of organisation, creating a nested hierarchy. This enables a common and unifying concept of function to apply from molecular interaction networks up to the global ecosystem.