With every pang of hunger or craving, we have a choice: to eat foods that we're told are good for us, or seek out comfort foods. Those choices aren't easy or always possible, but research shows eating healthier foods can have considerable health benefits – especially in the long run.

A new study analyzing food intake data and health outcomes of nearly half a million UK residents has found that switching to a healthy diet – and sticking to it – can add up to 10 years to your life. Great news! If you can afford it.

The team, led by Lars Fadnes, a public health researcher at the University of Bergen in Norway, modeled life expectancy for some 467,354 people who documented their eating habits as part of the long-running UK Biobank study, which started in 2006.

The researchers grouped participants based on their eating patterns, and noted how they shifted over time. They identified average and unhealthy eaters, as well as people whose food intake matched the UK's Eatwell Guide and others who consumed a diet the researchers dubbed the longevity diet.

After adjusting for smoking, alcohol, and physical activity, the researchers found men and women aged 40 who made a sustained change from eating unhealthily to following the Eatwell Guide recommendations gained roughly 9 years in life expectancy.

Those who ditched sugary drinks and processed meats in favor of a diet rich in whole grains, nuts, fruits, vegetables, and moderate amounts of fish (the so-called longevity diet) added an extra 10 years to their life expectancy.

Smaller life expectancy gains were seen among people who ate an average diet to begin with, and those who improved their eating habits later in life.

"The bigger the changes made towards healthier dietary patterns, the larger the expected gains in life expectancy are," the team explains in their published paper.

"Unsurprisingly, predicted gains in life expectancy are lower when the dietary change is initiated at older ages, but these remain substantial."

People aged 70 years old could still extend their life expectancy by around 4 to 5 years if they made a sustained change to eating healthily, either in accordance with the Eatwell Guide or the 'longevity diet', the researchers found.

"It's exciting, but not surprising, to see the enormous health benefits of making dietary changes," population nutrition researcher and study author Katherine Livingstone, of Deakin University, told ScienceAlert.

"This work is important as it demonstrates that its never too late to make small and sustained changes towards a healthier diet."

Other studies before this have shown how various healthy eating patterns mirroring dietary guidelines are linked to a lower risk of early death among US citizens.

While this new analysis looks at the UK, expanding the geographical range of such studies, the same caveats apply as with any population-level data.

For example, the UK Biobank doesn't measure consumption of rice, which is particularly important for many migrant groups, so the results won't generalize to everyone.

The pool of data in the UK Biobank also predominantly describes people of a White European, middle- to upper-class socioeconomic background.

The researchers also acknowledge that while their analysis looked at sustained dietary changes, "maintaining lifestyle changes over time with dietary improvements can be challenging, and for many, dietary patterns fluctuate over time."

For others, the challenge is not motivation, but access. Health authorities may recommend people eat a healthy diet, but access to affordable, nutritious food is a systemic problem and public health issue that government policies can help fix.

The researchers emphasize the role of food taxes and subsidies, which aim to make healthy food more affordable than unhealthy options. A 2017 study estimated that such policies to tax unhealthy items such as sugary drinks while subsidizing healthy options could save 60,000 lives in the US every year.

Improving food environments in schools and workplaces by removing vending machines and offering more healthy options could also make a real difference to people's health – not to mention the planet.

The study has been published in Nature Food.