Nobody likes skimping on sleep, but chances are you’ve done it. Whether to study for an exam, finish a tough project, or simply because you got stuck in an airport, pulling an all-nighter happens.

There’s no denying that sleep deprivation has negative effects, including bleak moods and poor cognitive function in the short term, and weight gain and increased likelihood of diabetes in the long term. Nedeltcheva AV, et al. (2014). Metabolic effects of sleep disruption, links to obesity and diabetes. DOI: 10.1097/MED.0000000000000082 Short MA, et al. (2015). Sleep deprivation leads to mood deficits in health adolescents. DOI: 10.1016/j.sleep.2015.03.007 Liu Q, et al. (2015). Effects of 72 hours total sleep deprivation on male astronauts’ executive functions and emotion. DOI: 10.1016/j.comppsych.2015.05.015

That’s not all. Check this out: More recent research suggests that sleep deprivation blurs our ability to accurately recognize emotions on the faces of others, particularly happiness. Killgore WDS, et al. (2017). Sleep deprivation impairs recognition of specific emotions. DOI: 10.1016/j.nbscr.2017.01.001

One 2019 study also showed that participants in a sleep deprivation study had decreased motivation and “attentional performance.” Basically, a chronic lack of Zzz’s may leave you with the attention span of a goldfish. Massar SAA, et al. (2019). Sleep deprivation increases the cost of attentional effort: Performance, preference and pupil size. DOI: 10.1016/j.neuropsychologia.2018.03.032

But with all that in mind, there are steps you can take to minimize the damage and treat your body (and brain) as well as possible under bad circumstances. Here’s how to survive the night —and recover ASAP.

Bank sleep ahead of time

While you can’t always anticipate an all-nighter, if you happen to know a stressful time or multi-time zone trip is headed your way, there are a few ways to prep your body.

“If you’re already a sleep-deprived person and then you pull an all-nighter, you’re going to have more cumulative effects,” says Shalini Paruthi, MD, who specializes in sleep medicine at St. Luke’s Sleep Medicine and Research Center.

But if you’ve been sleeping the recommended seven to nine hours a night, you won’t feel as bad after one missed night. Arnal PJ, et al. (2015). Benefits of sleep extension on sustained attention and sleep pressure before and during total sleep deprivation and recovery. DOI: 10.5665/sleep.5244

Get any amount of shut-eye

Yes, we know this is about how to stay up, but if you can, even a 20-minute nap is better than nothing.

“Opt for either a brief nap of less than 20 minutes or a longer nap of 60 to 90 minutes, if possible,” says Natalie Dautovich, PhD, an environmental scholar for the National Sleep Foundation.

“This will allow you to wake up during the lighter stages of sleep and feel more rested.”

Bring on the lights

“We need darkness to have the onset of melatonin, which is the hormone that makes us sleepy,” Dautovich says. “So if you’re trying to stay awake, bright light can be very effective.”

Specifically, light close to your eyes (for instance, a desk lamp or your computer screen) will help kick your brain into high alert.

Keep your room temperature moderate

We sleep best when the room is cool, between 65 and 70 degrees. If you need to stay awake, the solution is to find a not-too-cool, not-too-hot sweet spot. “Make the room temperate or layer on clothing,” Dautovich says.

Keeping the temperature around 75 degrees should keep you alert, and also prevent any heat-related drowsiness.

Skip the sugar and snack on protein and carbs

This probably sounds like a no-brainer, but refined sugar will lead to a crash within a few hours.

“Eating candy to stay awake is not sustained energy,” says Tamara Melton, RDN, co-founder of Diversify Dietetics. “It’s a simple sugar that will spike your energy levels up and then drop you down.”

Instead, focus on foods that provide long-lasting energy. “Eat something with lean protein,” Melton says. Greek yogurt and berries or an apple and peanut butter make great choices.

Just make sure you avoid heavy foods. “Anything really high in fat — like fettuccini alfredo or fried chicken — will not promote staying awake,” Melton says.

Instead of one big meal, snack a little throughout the night so you’re less likely to suffer an energy crash.

Drink a little coffee — and a lot of water

The FDA says that, for most adults, up to 400 milligrams of caffeine per day (about four cups of coffee) is safe. If you’re staying up all night, spread that out. FDA. (2018). Spilling the beans: How much caffeine is too much. https://www.fda.gov/consumers/consumer-updates/spilling-beans-how-much-caffeine-too-much

“You want to aim for 100 to 200 milligrams of caffeine, or a cup or two,” Melton says. Have your coffee with a snack to allow a slower release of caffeine into your system.

The key is to not OD on caffeine. “Often when you’re pulling an all-nighter, you need to concentrate,” Melton says. “More than two cups of coffee, and you might get jittery and your focus will decrease.”

After 3 or 4 hours, Melton says it’s okay to have another one to two cups of java. “Just know that it won’t work as well because you’re even more tired at that point,” Melton says.

And once you’re done with coffee, start chugging H2O. “When you’re hydrated you can concentrate better and every part of your system just works better,” Melton says.

Chew gum

Several studies have shown chewing gum can increase alertness, improve intellectual performance, and even enhance productivity. Allen AP, et al. (2015). Chewing gum: Cognitive performance, mood, well-being, and associated physiology. DOI: 10.1155/2015/654806

Get up and move

“Take short breaks every 45 minutes or so to walk around,” Paruthi says. If you’re drinking lots of water, as Melton suggests, it should be easy to build in a bathroom break about every hour.

Paruthi also says you should give your eyes a break occasionally to help stay alert. “If you’re on your computer screen, try looking up at a point in the distance to relax your eye muscles every now and then.”

Try aromatherapy

If you’re prepping for a test or presentation during your all-nighter, give essential oils a shot. A 2018 study found that people who inhaled lavender or rosemary essential oils had better short-term memory than a control group. Filiptsova OV, et al. (2018). The effect of the essential oils of lavender and rosemary on the human short-term memory. DOI: 10.1016/j.ajme.2017.05.004

Don’t drive

According to a 2017 study, 6,000 deaths are caused by drowsy driving in the U.S. each year. It’s best not to risk it. “This means planning ahead,” Paruthi says. Higgins, JS. (2017). Asleep at the wheel – the road to addressing drowsy driving. DOI: 10.1093/sleep/zsx001

“If you’re going to have to stay up, ask a neighbor or friend to drive you to work the next morning.” Paruthi suggests that you avoid driving unless you’ve been able to sleep for at least four hours.

Nap if you can, but don’t overdo it

“You want to avoid a drastic difference in your sleep time, so going to bed mid-morning and waking up mid-evening might throw off your rhythm for the next night,” Dautovich says.

Stick to the same nap schedule we talked about earlier: 20, 60, or 90 minutes. After your nap, no matter how tempting, try to stay awake as close as possible until your normal bedtime so you can get back on track.

Go easy on the caffeine

Though you may want an IV of coffee and Red Bull — resist. “Caffeine early in the day is alright, but if you’re still consuming it by 4 p.m., it may make it harder to fall asleep,” says Robert Rosenberg, DO, author of Sleep Soundly Every Night, Feel Fantastic Every Day.

Eat fruits, veggies, and drink (even more) water

“When people are sleep-deprived, they start to look for comfort food and don’t make good choices,” Melton says. In fact, research shows that sleep deprivation is associated with a higher body mass index in young adults. Grandner MA, et al. (2015). The relationship between sleep duration and body mass index depends on age. DOI: 10.1002/oby.21247

Another study found that sleep deprivation can give you a serious case of the munchies, similar to if you had smoked a joint. Hanlon, EC. (2016). Sleep restriction enhances the daily rhythm of circulating levels of endocannabinoid 2-arachidonoylglycerol. DOI: 10.5665/sleep.5546

“Fruits and veggies are helpful because those foods are rich in antioxidants and phytochemicals, which can help protect your cells since they’re not functioning at their best,” Melton explains.

And, just like you did throughout the night, stick to lean proteins, healthy carbs, and lots of water, she adds.

Do something active

This is not the day to try a tough new workout, but a little activity might benefit you.

“A light workout could be energizing and could help you stay awake,” Dautovich says. “We also know that physical activity may help you sleep better later.”

Don’t overeat or drink alcohol

It’s easy to overeat when you’re sleep-deprived because, well, eating feels good. “But at a certain point, having too big a meal can make sleeping uncomfortable,” Melton says. “Eat something balanced that you know will keep your GI tract in a happy place.”

And it should be obvious, but drinking alcohol does your body zero favors.

“Sleep deprivation plus alcohol is a recipe for disaster,” Rosenberg says. Scientists have known for decades that alcohol disrupts normal sleeping patterns, so if you want a solid recovery night, a glass of wine won’t help. Ebrahim IO, et al. (2013). Alcohol and sleep I: Effects on normal sleep. DOI: 10.1111/acer.12006

Get a little extra sleep

Unlike chronic sleep deprivation, you can undo the damage of one bad night with 10 hours of sleep the following night, Rosenberg says. Studies have shown that recovery sleep can also have a positive effect on motor skills. Sprenger A, et al. (2015). Deprivation and recovery of sleep in succession enhances reflexive motor behavior. DOI: 10.1093/cercor/bhv115

If you need to pull an all-nighter, your healthy behavior matters even more.

Stick to lean proteins, drink lots of water, and avoid unhealthy comfort foods you may crave the following day. Plan for recovery sleep that night and give yourself a break.

“There is no long-term damage from one night of missed sleep,” Rosenberg says. While chronic sleep deprivation is a serious health issue, a single all-nighter is just an annoyance.