Not getting enough sleep can lead to a vicious circle of over-eating and further sleep deprivation, but it may be possible to create a virtuous circle - where healthy eating actually improves your sleep.
Tania Whalen finds it impossible to get enough sleep between her shifts, working early mornings and nights as a fire brigade dispatcher in Melbourne, Australia. So to help her power through a long night of answering emergency calls and sending out crews she would often take snacks to work.
"It might be a muffin or some biscuits that you could eat in a break just because you felt a bit peckish or to lift your energy a bit," she says.
Tania was also a regular at the fire station vending machine, buying crisps or chocolate most night shifts. It was a diet she knew wasn't doing her much good - she was piling on the pounds - and yet it was difficult to resist.
And Tania's behaviour was not unusual. When people haven't had enough rest, they crave food.
"Some rather fiendish changes unfold within your brain and your body when sleep gets short, and set you on a path towards overeating and also weight gain," says Prof Matthew Walker, director of the Center for Human Sleep Science at the University of California.
When we're awake for longer, we do need more energy, but not that much - sleep is a surprisingly active process and our brains and bodies are working quite hard, Prof Walker says. Despite that, when deprived of sleep we tend to overeat by more than twice or three times the amount of calories we need.
That is because sleep affects two appetite-controlling hormones, leptin and ghrelin. Leptin will signal to your brain that you've had enough to eat. When leptin levels are high, our appetite is reduced. Ghrelin does the opposite - when ghrelin levels are high, you don't feel satisfied by the food that you ate.
In experiments it has been shown that when people are deprived of sleep these two hormones go in opposite directions - there's a marked drop in leptin, which meant an increase in appetite, while grehlin rockets up, leaving people unsatisfied.
It's like double jeopardy, Prof Walker says. "You're getting punished twice for the same offence of not getting sufficient sleep."
Why might this be happening? Prof Walker thinks there is an evolutionary explanation. Animals rarely deprive themselves of sleep, unless they are starving and need to stay awake to forage for food. So when we don't have sufficient sleep, from an evolutionary perspective, our brain thinks that we may be in a state of starvation and will increase our food cravings to drive us to eat more.
And not having enough sleep doesn't only affect how much we eat, but also what we eat.
A small study carried out by Prof Walker showed that participants were more likely to crave sugary, salty and carbohydrate-heavy foods when they were sleep-deprived.
None of which is good news for tired night-shift workers like Tania Whalen. In fact, the situation may be even worse for them since it's not just what they're eating that is a problem, but when they're eating it too.
Our bodies are primed to follow a regular 24-hour rhythm, says Dr Maxine Bonham, an associate professor of nutrition dietetics and food at Monash University, Melbourne. "We expect to work and eat and exercise during the day, and we expect to sleep at night, and our body is geared to do that. So when you work a night shift, you're doing everything in opposition to what your body's expecting."
And that means we struggle to process food when we eat night-time meals.
Eating at night can lead to higher glucose levels and more fatty substances in the blood, as the body is less able to break down and metabolise nutrients in the small hours, says Dr Bonham.
Shift workers are known to be more at risk of weight gain, type-2 diabetes and cardiovascular disease.
People who work at night are also more likely to be overweight. They may eat out of boredom or to stay awake, and there may not be anything healthy for them to eat, just a vending machine or takeaway food.
All this has inspired Dr Bonham and her colleagues to set up an experiment to see if they can help people who work night shifts lose excess weight and improve their overall health.
They've recruited some 220 shift workers who want to lose weight, and have been putting them on a variety of diets for a six-month period. Tania Whalen, the fire brigade dispatcher, signed up to follow a fasting programme: for two days each week, she had to consume just 600 calories in 24 hours.
"It was tough," Tania says. "I was quite worried that I wouldn't be able to do it. Some weeks it felt like a 12-hour shift took 20 hours."
But she stuck with it, distracting herself by reading, playing games, going for walks and drinking gallons of peppermint tea.
The study's results are not yet in, but Tania feels like it's been a positive experience that's prompted her to make other changes - for example, she now walks 5km every day. "I certainly have more energy and more desire to move, and I have lost a considerable amount of weight," she says.
Interestingly, Tania thinks it has helped her sleep better, too. "Even in the limited hours that I get, I don't toss and turn as much and I've stopped snoring mostly, or so my husband tells me."
It's not clear whether this improvement is down to the new diet, the exercise, the weight loss, or something else entirely, but it does raise the question of whether what you're eating can affect how you're sleeping.
Until now we've been talking about how sleep - or a lack of it - can affect what you eat. But what if you could eat your way to a good night's sleep?
Dr Marie-Pierre St-Onge is a nutrition and sleep researcher in New York. She had spent years studying the impact of insufficient sleep on diet when, in 2015, she was contacted by the committee drawing up the Dietary Guidelines for Americans. Should they be advising people on what to eat to improve their sleep, they asked?
"My first reaction was, 'Why didn't I think of that?'"
Melatonin, the hormone that promotes sleep and which rises in the evening, comes from a dietary amino acid called tryptophan. "So, if the hormone that regulates your sleep is produced entirely from an amino acid that must be consumed in the diet, then it makes sense that diet would be important in regulating sleep," she says.
And yet Dr St-Onge couldn't find any studies focusing on this relationship. So she and her team began looking at research into other health matters, which had recorded participants' sleep and dietary habits. Examining that data, a clear pattern emerged, she says.
Individuals who followed a Mediterranean-style diet - eating lots of fruits and vegetables, fish and whole grains - had a 35% lower risk of insomnia than those who didn't, and were 1.4 times more likely to have a good night's sleep.
So what is so sleep-inducing about that diet? Foods such as fish, nuts and seeds are high in melatonin-producing tryptophan. And a number of small studies have shown that some specific foods such as tomatoes, tart cherries and kiwi fruit, which contain melatonin, may help people fall asleep more easily and stay asleep for longer.
There are also foods to avoid before bed. Most people know about caffeine, which is a stimulant, but perhaps they don't realise salty foods can make you thirsty, which can disturb your sleep. Dr St-Onge's study also suggests eating sugary foods may lead to a more disturbed night. Her team is looking into why that may be.
Studies examining the influence of food on sleep are still few in number, and small in size, so Dr St-Onge says little can be taken as scientific fact. However, they do raise the possibility that eating certain foods can lead to better sleep.