The free-energy principle can explain how neural networks minimize energy costs and are optimized for efficiency.