1. Energetics are a key driver of animal decision-making, as survival depends on the balance between foraging benefits and movement costs. This fundamental perspective is often missing from habitat selection studies, which mainly describe correlations between space use and environmental features, rather than the mechanisms behind these correlations. To address this gap, we present a new modelling framework, the energy selection function (ESF), to assess how moving animals choose habitat based on energetic considerations. 2. The ESF considers that the likelihood of an animal selecting a movement step depends directly on the corresponding energetic gains and costs. The parameters of the ESF measure selection for energetic gains and against energetic costs; when estimated jointly, these provide inferences about foraging and movement strategies. The ESF can be implemented easily with standard conditional logistic regression software, allowing for fast inference. We outline a workflow, from data-gathering to statistical analysis, and use a case study of polar bears (Ursus maritimus) as an illustrative example. 3. We show how defining gains and costs at the scale of the movement step allows us to include detailed information about resource distribution, landscape resistance, and movement patterns. We demonstrate this in the polar bear case study, in which the results show how cost-minimization may arise in species that inhabit environments with an unpredictable distribution of energetic gains.4. The ESF combines the energetic consequences of both movement and resource selection, thus incorporating a key aspect of evolutionary behaviour into habitat selection analysis. Because of its close links to existing habitat selection models, the ESF is widely applicable to any study system where energetic gains and costs can be derived, and has immense potential for methodological extensions.