Most of us gain a little weight as we age, and this may not be a bad thing — as long it’s gradual and not excessive. It can extend your life, a recent study finds.

Few people can eat the way they did at age 20 when they are in their thirties and forties without gaining weight. It's not just that you are likely to be less active; reduced muscle mass and a slower metabolism also contribute to the upward creep on the scale as we age.

The people who lived the longest were those who were a normal weight when they entered adulthood and gradually became overweight, but never obese, later in life.

To trace the effect weight gain has throughout adulthood on life expectancy, Ohio State University researchers used information collected in the original group of people who participated in the Framingham Heart Study and some of their children.

The Framingham study began in 1948 and followed 5,200 people from the time they were age 30 to 52 through 2010. From 1971 to 2014, data on the children of these original participants were also included in the study. Most members of the original study had died by 2014, so information on changes in body mass index (BMI) throughout adulthood provided a good way to look at the connection between weight and longevity.

The people who lived the longest — in both generations — were those who were a normal weight when they entered adulthood and gradually became overweight, but never obese, later in life.

People whose weight was stable over the course of their lives enjoyed the second longest longevity, followed by people who were overweight but whose weight remained stable. Those who began adulthood obese and continued to gain weight had the lowest life expectancy.

“The main message is that for those who start at a normal weight in early adulthood, gaining a modest amount of weight throughout life and entering the overweight category in later adulthood can actually increase the probability of survival,” explained Ohio State researcher, Hui Zheng, in a statement.

The news wasn’t so good for the younger generation. More young people are starting adulthood with BMIs in the overweight or obese range and are more likely to have shorter life expectancy.

The study is published in Annals of Epidemiology.