We’ve all been there: the lab report left until the last minute, the paper due at 8:00 a.m., the exam that seemed so far away on the calendar but then suddenly is tomorrow. While a little planning goes a long way, all-nighters are inevitable. Don’t fret; here are five tips for doing ’em right.

REST UP

Get some sleep beforehand if you can. Go to bed early the night before; take a nap before you hit the librarythe more rested you are, the better. Sometimes even taking a quick nap during your study session can help. According to a NASA study, a forty-minute nap improves performance by 34 percent and alertness by 100 percent.

FUEL UP

Whenever I think of all-nighters, I immediately think of bottomless coffee. But drinking too much caffeine too fast can actually be counterproductive. Anything more than four cups of coffee, or four hundred milligrams of caffeine, can make you jittery and unfocused. The key is to avoid chugging that latte. Instead, spread out your caffeine intake throughout the night. Keep snacks on hand, too: Granola bars and fresh fruit are quick, healthy options.

CHOOSE A GOOD SPOT

Studying in your bed isn’t a setup for success. You want a place where you feel alert and awake, somewhere that has plenty of light and minimal noise. And stay away from your damn phone: I usually put mine in my backpackout of sight, out of mind.

TAKE BREAKS

Use the fifty-ten rule: After every fifty minutes of studying, take ten minutes to do some kind of activitywalk, stretch, talk to a friend. Studying is a marathon, not a sprint.

GET BACK TO NORMAL

So you finished. Now what? Take it easy and get back to your normal sleep schedule as soon as possible. Don’t overcompensate with caffeine, and don’t go to sleep before sunset. Go to bed a little earlier than normal and try to wake up naturally the next morning.