Hormones also are enormous contributors. Cortisol is the stress hormone. Elevated cortisol levels and over time your body will stubbornly hang onto fat stores.
Thyroid hormones/metabolic rate is also important. As we age we lose testosterone and estrogen production. Metabolic rate slows gradually. So diet must modify as far as caloric intake alongside these changes. People who do not modify amount of caloric intake while metabolic rate declines are the ones who gradually gain weight with age. It literally sneaks up on you because metabolic rate declines with all other things being equal.
I'm female of course and in my 50s. So menopause is another issue for me. I still weigh as of this morning, what I weighed in high school, and wear a size 4. But I get on the scale every morning, walk every day, eat sparingly (protien/veggies/berries), avoid carbs and sugar, and drink alcohol in moderation.
I feel my very best 15-20 lbs lighter than where I am now, in a size 0. My current BMI is 21 right now, but I feel best at BMI 19, so I have lost some ground over the past 2 years. As others have said, one must be quite mindful about diet. My husband gained 20 lbs after we married (so did I), but he is now back to his weight when we met (6'3" and 175). I am coming back down too but the hormonal/metabolic riddle has been more for me to solve.
His BMR (basal metabolic rate) is also higher, becsuse he is younger (48) and male. He thinks I should eat the same as he does, and its taken a bit for him to grasp that my body does not operate the same as his. I CANNOT eat as frequently or the same volume as him, nor can I consume the same amount of alcohol.
Everything is discipline. Predominantly around diet but exercise and alcohol moderation in also very important. I have fortunate genetics, and so does my husband, but as we age that only gets us so far. Discipline is what makes the difference.