A proper diet is essential for overall health and longevity. Adding more evidence to the link, researchers have found that switching to a healthier diet in the 40s can extend life expectancy by 10 years.

Switching from a typical Western diet to a healthier eating habit and sticking to the regimen can increase life expectancy by 10.8 and 10.4 years in men and women respectively, according to a study published in the journal Nature Food.

The study examined data from around half a million volunteers between the ages of 40 to 69 from the U.K. Biobank. The team looked at the eating habits of the participants and changes in their diet over the years. The participants were followed up for at least 30 years.

The results showed that middle-aged people who shifted from an unhealthy diet to a healthy diet and maintained the pattern could add a decade more to their lives.

The participants who switched to healthier diets later in life also showed improvements but not as much as people in their 40s. For example, changing to a healthier diet at the age of 70 could bring in about half of the life expectancy gain predicted for people in their 40s.

With bigger changes toward healthier dietary patterns, the expected gains in life expectancy were greater.

Researchers also identified the food groups associated with improved longevity. Nuts, legumes and whole grains were found to be most beneficial while food items such as sugar-sweetened beverages and red meat should be limited.

"Consuming less sugar-sweetened beverages and processed meats and eating more whole grains and nuts were estimated to result in the biggest improvements in life expectancy," the researchers wrote.

The findings highlight how consistent dietary changes can affect life expectancy. Researchers hope the results will help government shape better health policies in the future. They recommend implementing policies that impose taxes on unhealthy foods and provide subsidies for healthy alternatives.