Smokers who quit by around age 40 can stave off an early death, according to a landmark study that fills key gaps in our knowledge of smoking-related health ills.

While smokers who never stop lose about a decade of life expectancy, those who quit between ages 35 and 44 gained back nine of those years, the study found.

Moreover, the benefits of dropping the habit extend deep into middle age. Smokers who quit between 45 and 54 gained back six otherwise lost years, and those who quit between 55 and 64 gained four years. Quitting young, before age 35, erased the entire decade of lost life expectancy.