It has not been a good time for sleep.

With the coronavirus pandemic, school and work disruptions and a contentious election season contributing to countless sleepless nights, sleep experts have encouraged people to adopt a variety of measures to overcome their stress-related insomnia. Among their recommendations: engage in regular exercise, establish a nightly bedtime routine and cut back on screen time and social media.

But many people may be overlooking another important factor in poor sleep: diet.

A growing body of research suggests that the foods you eat can affect how well you sleep, and your sleep patterns can affect your dietary choices.

Researchers have found that eating a diet that is high in sugar, saturated fat and processed carbohydrates can disrupt your sleep, while eating more plants, fiber and foods rich in unsaturated fat — such as nuts, olive oil, fish and avocados — seems to promote sound sleep.

Much of what we know about sleep and diet comes from large epidemiological studies that, over the years, have found that people who suffer from consistently bad sleep tend to have poorer quality diets, with less protein, fewer fruits and vegetables, and a higher intake of added sugar from foods like sugary beverages, desserts and ultra-processed foods. But by their nature, epidemiological studies can show only correlations. They cannot explain, for example, whether poor diet precedes and leads to poor sleep, or the reverse.

To get a better understanding of the relationship between diet and sleep, some researchers have turned to randomized controlled trials in which they tell participants what to eat and then look for changes in their sleep. A number of studies have looked at the impact of a diverse array of individual foods, from warm milk to fruit juice. But those studies often have been small and not very rigorous.

Some of these trials have also been funded by the food industry, which can bias results. One study funded by Zespri International, the world's largest marketer of kiwi fruit, for example, found that people assigned to eat two kiwis an hour before their bedtime every night for four weeks had improvements in their sleep onset, duration and efficiency. The authors of the study attributed their findings in part to an "abundance" of antioxidants in kiwis. But the study lacked a control group, so it is possible that any benefits could have resulted from the placebo effect.

Other studies funded by the cherry industry have found that drinking tart cherry juice can modestly improve sleep in people with insomnia, supposedly by promoting tryptophan, one of the building blocks of the sleep-regulating hormone melatonin. Tryptophan is an amino acid found in many foods, including dairy and turkey. But it has to cross the blood-brain barrier to have any soporific effects, and in the presence of other amino acids found in food it ends up competing, largely unsuccessfully, for absorption. Studies show that eating protein-rich foods such as milk and turkey on their own actually decreases the ability of tryptophan to cross the blood-brain barrier.

One way to enhance tryptophan's uptake is to pair foods that contain it with carbohydrates. That combination stimulates the release of insulin, which causes competing amino acids to be absorbed by muscles, in turn making it easier for tryptophan to cross into the brain, said Marie-Pierre St-Onge, an associate professor of nutritional medicine at Columbia University Irving Medical Center and the director of the Sleep Center of Excellence at Columbia.

St-Onge has spent years studying the relationship between diet and sleep. Her work suggests that rather than emphasizing one or two specific foods with supposedly sleep-inducing properties, it is better to focus on the overall quality of your diet. In one randomized clinical trial, she and her colleagues recruited 26 healthy adults and controlled what they ate for four days, providing them regular meals prepared by nutritionists while also monitoring how they slept at night. On the fifth day, the subjects were allowed to eat whatever they wanted.

The researchers discovered that eating more saturated fat and less fiber from foods like vegetables, fruits and whole grains led to reductions in slow-wave sleep, which is the deep, restorative kind. In general, clinical trials have also found that carbohydrates have a significant impact on sleep: People tend to fall asleep much faster at night when they consume a high-carbohydrate diet compared to when they consume a high-fat or high-protein diet. That may have something to do with carbs helping tryptophan cross into the brain more easily.

But the quality of carbs matters. In fact, they can be a double-edged sword. St-Onge has found in her research that when people eat more sugar and simple carbs — such as white bread, bagels, pastries and pasta — they wake up more frequently throughout the night. In other words, eating carbs may help you fall asleep faster, but it is best to consume "complex" carbs that contain fiber, which may help you obtain more deep, restorative sleep.

"Complex carbohydrates provide a more stable blood sugar level," St-Onge said. "So if blood sugar levels are more stable at night, that could be the reason complex carbohydrates are associated with better sleep."

One example of a dietary pattern that may be optimal for better sleep is the Mediterranean diet, which emphasizes such foods as vegetables, fruits, nuts, seeds, legumes, whole grains, seafood, poultry, yogurt, herbs and spices and olive oil. Large observational studies have found that people who follow this type of dietary pattern are less likely to suffer from insomnia and short sleep, though more research is needed to confirm the correlation.

But the relationship between poor diet and bad sleep is a two-way street: Scientists have found that as people lose sleep, they experience physiological changes that can nudge them to seek out junk food. In clinical trials, healthy adults who are allowed to sleep only four or five hours a night end up consuming more calories and snacking more frequently throughout the day. They experience significantly more hunger and their preference for sweet foods increases.

In men, sleep deprivation stimulates increased levels of ghrelin, the so-called hunger hormone, while in women, restricting sleep leads to lower levels of GLP-1, a hormone that signals satiety.

"So in men, short sleep promotes greater appetite and desire to eat, and in women there is less of a signal that makes you stop eating," St-Onge said.

Changes also occur in the brain. St-Onge found that when men and women were restricted to four hours of nightly sleep for five nights in a row, they had greater activation in reward centers of the brain in response to pepperoni pizza, doughnuts and candy compared to healthy foods such as carrots, yogurt, oatmeal and fruit. After five nights of normal sleep, however, this pattern of stronger brain responses to the junk food disappeared.

Another study, led by researchers at King's College London, also demonstrated how proper sleep can increase your willpower to avoid unhealthy foods. It found that habitually short sleepers who went through a program to help them sleep longer — resulting in their getting roughly an hour of additional sleep each night — had improvements in their diet. The most striking change was that they cut about 10 grams of added sugar from their diets each day, the equivalent of about two and a half teaspoons.

The takeaway is that diet and sleep are entwined. Improving one can help you improve the other, creating a positive cycle where they perpetuate one another, said Dr. Susan Redline, a senior physician at the Brigham and Women's Hospital and a professor of sleep medicine at Harvard Medical School.

"The best way to approach health is to emphasize a healthy diet and healthy sleep," she added. "These are two very important health behaviors that can reinforce each other."