Sugar is bad; sugar is evil; sugar is the devil. We all know that, although that doesn’t stop us from heaping it over our Weetabix every morning and adding it to tea and coffee.

Too much sugar can lead to weight gain, causes tooth decay and increases the risk of diabetes. But it also has another profound effect – it messes with your sleep, and in such a way that your sleeplessness will leave you with a craving for more sugar.

A 2016 study found that people who have diets high in sugar tend to sleep less deeply and display greater restlessness at night. According to Dr Michael Breus – AKA “the sleep doctor” – a US clinical psychologist who specialises in sleep disorders, too much sugar leads to a tendency to eat later in the day because blood sugar levels are zigzagging out of control. That adversely affects sleep, and your disrupted sleep will, in turn, produce an even greater craving for sugar the next day. The vicious circle is complete.

Having too much sugar at night can be detrimental to our health. “When you eat sugar, your blood sugar levels rise and your pancreas releases insulin, which helps the sugar to be taken back into the cells, giving them fuel to run on,” says the dietitian Alex Evans. “Eating sugar late at night overstimulates you. It gives you energy and makes you ready for activity, but that is not what we’re trying to do at night. We’re designed to shut down towards the end of the day.”

“Sugar uses up a lot of magnesium, which you need for sleep,” says the nutritional therapist Charlotte Watts, author of Good Mood Food and The De-Stress Effect. She points out that you should, in particular, avoid late-night chocolate, which contains caffeine and other stimulants.

Dr Paul Kelley, a researcher into sleep patterns, accepts the link between high sugar intake and disturbed sleep, but cautions that more data is needed before we fully understand the causality. “Poor sleep and eating sugar and fatty foods do go together, but there is evidence on both sides about which direction it goes in,” he says. “Does eating sweet things make you sleep less or does sleeping less make you eat sweet things?”

The less you rely on sugar during the day, the more you are able to achieve healthy sleep patterns at night

He says the average adult needs at least seven hours sleep a night; any less and you will be looking for short-term energy boosts, and the combination of bad diet and poor sleep will damage your health.

“We have a major problem with sleep and a major problem with food, and they interact,” says Kelley. “Sugary foods are likely to disrupt your sleep. The rule of thumb is that you shouldn’t eat in the two hours before you go to sleep.” He recommends avoiding caffeine and switching off the TV an hour before bed.

“There’s a real biochemical drive to eat more sugar,” says Watts. “The body recognises that resources are low, and you need something that acts as a crutch.” She says bingeing on sugary foods can be a sign of loneliness. “When we don’t have enough joy in life, we tend to turn to things that can prop us up instead, and sugar is one of those. Sugar is a massive self-medicator.”

The encouraging news is that the craving can be broken. “Blood sugar is like a rollercoaster, but fibrous foods such as wholemeal and granary bread, and potatoes in their skins can help to control it,” says the dietitian Anna Hardman. “They release sugar over a much longer period and reduce the spikes.” Your overworked pancreas gets a well-earned rest.

Foods high in tryptophan are recommended for enhancing sleep. These include beans, lentils, nuts, whole grains and poultry. Or you could opt for a meal with sleep-inducing carbs and some protein. “Tryptophan helps to make the neurotransmitter serotonin, known as the ‘happy hormone’,” says Evans. “One of the things it does is prepare you for sleep.”

So what should those who have late-night food cravings eat? “Good sources of tryptophan are cottage cheese and turkey,” she says. “Certain plants are seen to have a sleepy effect – lettuce, for example. A turkey and lettuce sandwich on wholegrain bread would give you slow-release carbohydrates from the bread, tryptophan from the turkey, producing your serotonin, and the soporific effect from the lettuce.”

Watts recommends eating well throughout the day, starting with plenty of protein for breakfast, to counteract fluctuating blood-sugar levels. “The less you rely on sugar and caffeine to prop you up through the day, the more you are able to go into healthy sleep patterns at night,” she says.

Healthy eating, exercise and an evening wind-down produce good sleep, and the vicious circle turns virtuous. Sleep well.