Holiday travel can be a nightmare, even before you get to the airport. Part of that is because, when we’re talking about Thanksgiving and Christmas, lots of people are traveling, all at the same time. This means that flights can be hard to book and that they can get expensive if you don’t book them at the right time.

Depending on where you’re going, there are different best days and times to book a flight. For Thanksgiving travel, you’re better off planning your flight and getting your tickets by Halloween. For Christmas, aim to have your tickets by Thanksgiving.

The days that you’re planning on flying out or returning home can matter as well. The Saturday and Wednesday just before Thanksgiving, or the Sunday after it, tend to be busy and expensive. Black Friday, though, tends to be pretty good for holiday travel.

Likewise, Christmas travel will be the least expensive if you travel on Christmas Eve, Christmas Day, or New Year’s Eve. The next best bet is departing Tuesday, Dec. 20, and returning on Thursday, Jan. 5.

The trick to planning holiday travel is to do just that: plan ahead. The earlier you know when you’re going to fly to see family or friends, the easier it is to plan for it. Sure, flying home on Black Friday may not be ideal, but if flights are cheaper and less busy, why not take advantage of it?

If you need to save money on travel, it’s important to be willing to make some sacrifices of convenience. For example, some great travel deals were spotted last year on Cyber Monday, but travelers had to book flights that departed at very early or very late hours.

The first step to figuring out your travel plans is to know how long you want to be somewhere. This will give you an idea of when to schedule your flights and perhaps offer you more flexibility.