The study, which was published in the journal Mayo Clinic Proceedings, analyzed data from nearly 400,000 people in the UK Biobank, a biomedical database and research resource, from March 13, 2006 to October 1, 2010. None of the participants had cardiovascular disease at the start of the study.

The researchers assigned each study participant a lifestyle score based on four factors:

SmokingAlcohol consumptionPhysical activityDiet

They then gave them a sleep score based on things like sleep duration, when they slept, insomnia, snoring, and daytime dozing.

During the study period, 10,218 people developed heart disease. The researchers discovered that those who had poor sleep patterns and bad lifestyle habits had a 25% increased risk of heart disease and a 29% higher risk of a heart attack. That risk was lower in those who had poor lifestyle habits but good sleep patterns. People with better sleep habits were linked to an 18% higher risk of cardiovascular disease and 17% higher risk of a heart attack.

“Our results indicate that adherence to a healthy sleep pattern may attenuate the cardiovascular disease risk associated with an unfavorable lifestyle,” the researchers wrote.

Lu Qi, MD, PhD, study co-author and chair and professor in the department of epidemiology at Tulane University, told Verywell that he and his fellow researchers wanted to see how much of an impact sleep could have on certain lifestyle factors.

“Growing evidence indicates that sleep behaviors may affect health and sleep is tightly related to other lifestyle factors such as dietary intake, physical activity, and obesity,” he said. “We assumed that sleep patterns may modify the relation between other lifestyle factors and health outcomes such as heart disease.

Why Might Sleep Help Offset Poor Heart Health Choices?

The study didn’t look at why this link exists—it simply found an association.

However, Qi points out that certain poor lifestyle factors can cause an increase in things like LDL (bad) cholesterol, blood pressure, and bodily inflammation. But, he noted, sleep works against those.

“A healthy sleep pattern can lower these metabolic risk factors,” he said. “It is not surprising the adverse relations of smoking, high alcohol consumption, physical inactivity, and an unhealthy diet could be attenuated among those with a healthy sleep pattern.”

Paul Natterson, MD, a cardiologist at Providence Saint John’s Health Center in California, told Verywell that “there’s a real impact on vascular health, the health of blood vessels, and inflammation associated with things like tobacco use and inactivity.”

Natterson said there are also “very well established associations” that lack of sleep or poor quality sleep can impact the ability of the heart to function well.

“Poor sleep can have an additional inflammatory impact on blood vessels,” he said, pointing out that the opposite can be true. Meaning, if you get more sleep, you lower your likelihood of having an inflammatory impact on your blood vessels.

Getting Enough Sleep Can’t Wipe Out Bad Habits

Experts stress the importance of not relying on sleep to counteract the impact of bad heart habits. “Even among people with a healthy sleep pattern, the risk of heart disease associated with other unhealthy lifestyle remained, and could not be entirely eliminated,” Li said.

Natterson agrees. “While a good night’s sleep may help you be a little better off than if you had poor sleep habits, you’re not entirely counteracting the impact of an unhealthy lifestyle,” he said. “It’s best to try to sleep well and follow healthy lifestyle habits for your heart health.”

The American Heart Association has a list of lifestyle and dietary recommendations to help you lower your risk of heart disease. Those include:

Use up at least as many calories as you take inAim for 150 minutes of moderate-intensity exercise a week, or 75 minutes of vigorous-intensity activity a weekEat a wide variety of fruits and vegetablesStock up on whole grainsEat healthy sources of protein like legumes, nuts, fish, and seafoodFocus on minimally processed foodsLimit how much added sugar you eatEat foods with little or no saltLimit or eliminate alcohol from your lifeDon’t smoke, vape, or use tobacco or nicotine products