JETLAG IS THE BANE of every traveler everywhere. It cuts into our travel, it sends us to bed earlier than we’d like, and it wastes our waking hours on the moments we spend in our beds staring up at the dark hotel ceiling in the middle of night. And then, when you get back home, it serves as a sort of secondary post-trip hangover, just to make leaving the world of travel behind that much worse.

Fortunately for us, though, science has turned its all-seeing eye on jetlag, and has determined what causes it, and as such, we now have the tools we need to fight jetlag and make our trips and our returns home that much less painful. Here’s how to do it.

Before you leave

Your body tells you when to wake up and when to go to sleep based on your circadian rhythms, which are, for the most part, based on the amount of light you’re exposed to, and also a little bit on when you eat. These rhythms haven’t had the chance or reason to evolve to deal with rapid travel around the world, so when you suddenly change your location, it throws the rhythms off.

So the first thing you can do — if you’re traveling east — for the three days before your trip, wake up an hour earlier each day and expose yourself to the sun or some other bright light. This will allow your body to start to adjust before you leave. If you’re traveling west, do the reverse, and wake up an hour later each day (though typically, as the study that discovered this trick noted, westward travel is easier on the rhythms anyway).

When you’re on the plane

The first thing to do when you get on the plane is to reset your watch to the local time of whatever your destination is. The resetting itself doesn’t do anything (obviously), but if you use local time at your destination as a guide to when you should be eating and sleeping while you’re on the plane, then your body will feel less jarred when you land and are suddenly on that schedule anyway.

Next, you need to control the sunlight on the plane. Sunlight messes with your head if you’re trying to sleep, so it’s best to sit in a seat on the side of the plane where the sun isn’t shining in your face. Sure, you can pull that little plastic cover down, but you can’t make everyone else do the same thing. So it’s better to choose a seat on the shadow side of the plane. You can figure out which side that is using the site Sunflight. Most airlines let you choose your seat now anyway.

In terms of sleeping on the plane, you’re trying to sleep when you would normally sleep at your destination, so you want to keep in-flight naps during the “daytime” to a minimum. Watch a movie, play a game, read a book, walk up and down the cabin, and avoid self-medicating with stuff like alcohol, sleeping pills, or caffeine. It’s better to just stay hydrated instead.

Once you get there

Sleep scientist Richard Wiseman suggests monitoring your exposure to sunlight once you’ve arrived to: at times when you’re trying to sleep, avoid sunlight, but at times when you’re trying to stay awake, get out in it. If you use apps like Entrain, you can figure out exactly when you should be seeking sunlight, and when you should be avoiding it. If you can’t avoid the sunlight, try using sunglasses instead. If you have to nap, do it around midday rather than in the morning or late afternoon so as to not throw yourself off too badly.

If you’re still having trouble keeping a regular sleep pattern, you can talk to a doctor about the possibility of using melatonin supplements to help regulate your sleep during the trip. But obviously you should not self-medicate.