The energy expenditure from physical activity often cancels out the energy surplus from the occasional caloric splurge, leading to energy balance and weight maintenance.
I don't like the idea of exercising to 'earn' foods or treats, but often a moderate amount physical activity does a great job of mopping up the calories that come from these little extras.
It works out as a pretty fair deal - you can have some flexibility in the diet, so long as there is some physical activity in there.
This explains why you were seemingly able to eat anything and not gain weight in your early twenties had very little to do with metabolism and a lot to do with physical activity.
The main difference from the early twenties to late-twenties/early thirties is the decrease in non-exercise activity thermogenesis (NEAT).
In the early twenties, many people are working on their feet in hospitality, retail, or jobs that require higher levels of physical activity.
As we graduate from study, progress through the workforce and move higher into management, work-related physical activity begins to decrease.
We also become more happy to trade off time for money, so we are more willing to pay for parking near the office than spend 15-minutes walking each way.
The good news is that many people keep up their training or sports regimes during this time, so not all physical activity is lost.
But then as work and family commitments start to rise, there is a decrease in exercise activity thermogenesis (EAT) as available time begins to train becomes more scarce.
A decreased training duration can be offset by increased intensity for events such as running or self-directed gym sessions, but it’s often set duration activities such as sports and classes that are lost removed from the weekly regime.
The decrease in energy expenditure from NEAT and EAT can help create an energy surplus, leading to fat gain.
It’s not a massive surplus, maybe a few hundred calories per week if some training is maintained and food intake remains similar.
But an extra 400kal surplus per week turns into a couple of kilograms of weight gain over the course of a year.