People just aren’t getting enough rest. With a Starbucks on almost every corner, people underestimate the importance of sufficient sleep and rely on a cup or two of coffee to make it throughout the day. In a new study, researchers have found yet again that getting the proper amount of sleep can keep you from developing poor cognitive function later in life.

The study conducted by the University of Warwick, published in PLOS ONE, involved about 4,000 men and over 4,800 women. Researchers observed the quantity versus quality of sleep in different age groups. For adults ages 50 to 64, getting the right amount of sleep was helpful in avoiding brain damage. Adults who slept more than the recommended six to eight hours of sleep showed signs of lower cognitive function. For older adults 65 years and up, the quality of sleep was more important than the quantity. Too much sleep was also noted to be damaging.

"Sleep is important for good health and mental wellbeing. Optimizing sleep at an older age may help to delay the decline in brain function seen with age, or indeed may slow or prevent the rapid decline that leads to dementia," Francesco Cappuccio, a co-researcher, said in a press release.

If you feel groggy in the morning, it could be that you are getting too little sleep or too much sleep. The National Sleep Foundation says that seven to eight hours of sleep is sufficient, but based off of your age and how you feel, it can vary. Getting a lack of sleep can put you at risk for several chronic diseases such as diabetes, cardiovascular disease, obesity, and depression.

If you are having trouble getting a good night’s rest, the Centers for Disease Control and Prevention offers a few tips that can help you. Try going to bed and waking up around the same time every day. It is recommended one avoid large meals before going to bed and turn off lights and the television. Consistent trouble with sleep could be associated with sleep disorders such as insomnia, narcolepsy, restless leg syndrome, or sleep apnea.

People suffering with insomnia can’t get to sleep at night and tend to fall asleep during the day. Narcolepsy causes excessive daytime sleepiness. Restless leg syndrome causes pains in your legs, making it very difficult to go to sleep. Sleep apnea causes heavy breathing during the middle of your sleep and causes you to stop breathing for short periods. If you have any of these syndromes, you should seek treatment immediately.

Source: Miller MA, Wright H, Ji C, Cappuccio F. Cross-Sectional Study of Sleep Quantity and Quality and Amnestic and Non-Amnestic Cognitive Function in an Ageing Population: The English Longitudinal Study of Ageing (ELSA). PLOS ONE. 2014.