Physiological needs evoke motivational drives to produce natural behaviours for survival. However, the temporally intertwined dynamics of need and motivation have made it challenging to differentiate these two components in previous experimental paradigms. Based on classic homeostatic theories, we established a normative framework to derive computational models of neural activity and behaviours for need-encoding and motivation-encoding neurons during predicted gain and loss events. We further developed simple and intuitive experimental paradigms that enabled us to distinguish the distinct roles of subpopulations of neurons in the hypothalamus. Our results show that AgRP neurons and LHLepR neurons are consistent with need and motivation, respectively. Our study provides a parsimonious understanding of how distinct hypothalamic neurons separately encode need and motivation to produce adaptive behaviours for maintaining homeostasis.