People who are overweight cut their life expectancy by two months for every extra kilogramme of weight they carry, research suggests.
A major study of the genes that underpin longevity has also found that education leads to a longer life, with almost a year added for each year spent studying beyond school.
Other key findings are that people who give up smoking, study for longer and are open to new experiences might expect to live longer.
Scientists at the University of Edinburgh analysed genetic information from more than 600,000 people alongside records of their parents' lifespan.
Because people share half of their genetic information with each of their parents, the team were able to calculate the impact of various genes on life expectancy.
Lifestyle choices are influenced to a certain extent by our DNA - genes, for example, have been linked to increased alcohol consumption and addiction. The researchers were therefore able to work out which have the greatest influence on lifespan.
Their method was designed to rule out the chances that any observed associations could be caused by a separate, linked factor. This enabled them to pinpoint exactly which lifestyle factors cause people to live longer, or shorter, lives.
They found that cigarette smoking and traits associated with lung cancer had the greatest impact on shortening lifespan.
For example, smoking a packet of cigarettes per day over a lifetime knocks an average of seven years off life expectancy, they calculated. But smokers who give up can eventually expect to live as long as somebody who has never smoked.
Body fat and other factors linked to diabetes also have a negative influence on life expectancy.
The study also identified two new DNA differences that affect lifespan. The first - in a gene that affects blood cholesterol levels - reduces lifespan by around eight months. The second - in a gene linked to the immune system - adds around half a year to life expectancy.
The research, published in Nature Communications, was funded by the Medical Research Council.
Data was drawn from 25 separate population studies from Europe, Australia and North America, including the UK Biobank - a major study into the role of genetics and lifestyle in health and disease.
Professor Jim Wilson, of the University of Edinburgh's Usher Institute, said: "The power of big data and genetics allow us to compare the effect of different behaviours and diseases in terms of months and years of life lost or gained, and to distinguish between mere association and causal effect."
Dr Peter Joshi, Chancellor's Fellow at the University of Edinburgh's Usher Institute, said: "Our study has estimated the causal effect of lifestyle choices. We found that, on average, smoking a pack a day reduces lifespan by seven years, whilst losing one kilogram of weight will increase your lifespan by two months."
Explore further: Inherited gene changes take years off life expectancy, study finds
Peter K. Joshi et al, Genome-wide meta-analysis associates HLA-DQA1/DRB1 and LPA and lifestyle factors with human longevity, Nature Communications (2017). DOI: 10.1038/s41467-017-00934-5