Calculating the optimal timeframe to book a flight can have you feeling like a mathematician, financial analyst, and travel agent all in one. Do you book the tickets a few months out? Two weeks before your trip? Four hours before you have to be at the airport?

Add in the pandemonium of holiday travel, and booking becomes almost as stressful as navigating the damn airport.

But fear not, eager globetrotters: Travel-booking site Kayak has crunched the numbers to find the least expensive times to fly, according to 2016 data. Here's the breakdown for Thanksgiving, Christmas, and New Year's. Kayak calculated the data according to 2016 dates, but we presented the information here with relative days, so you can line up the calendar every year regardless of the specific numerical dates the holidays fall on.

## Cheapest time to book a flight around Thanksgiving

To get the cheapest flight around the most gluttonous of holidays, you want to book two weeks in advance. It's actually more expensive to purchase three months away. On average, people spent about \$362 on tickets.

The cheapest departure date was, obviously, Thanksgiving itself, followed by returning that night (\$163) or the day after (\$261). But if that doesn’t work for your plans, here are the next-best alternatives:

• Depart the Monday before, return Thanksgiving (\$286)
• Depart the Wednesday before, return the Friday after (\$298)
• Depart the Monday before, return the Friday after (\$300)
• Depart Thanksgiving, return Tuesday of the next week (\$304)

## Cheapest time to book a flight around Christmas

To get a Christmas flight that won’t break the bank, book one month to six weeks out. People who booked in either timeframe spent around \$276 on flights. Book any earlier, and you can expect to pay more for your tickets. Naturally, if you fly in and out on Christmas Day, you’ll get a cheap ticket (\$234). Same goes for flying in on Christmas Eve, then out on Christmas Day (\$346). While flying out on the 25th is still your best bet, these flights give you some more flexibility:

• Depart Dec. 25 (Christmas Day), return Dec. 27 (\$338)
• Depart Dec. 20, return Dec. 25 (Christmas Day) (\$351)
• Depart Dec. 21, return Dec. 25 (Christmas Day) (\$354)
• Depart Dec. 25 (Christmas Day), return Dec. 26 (\$359)
• Depart Dec. 25 (Christmas Day), return Dec. 28 (\$352)

## Cheapest time to book a flight around New Year's

Save money on your New Year’s travel, and put it where it really counts. The optimal time to book is two weeks before (flights average \$422). Prices are actually steeper the earlier you book (one month to three months out averages \$434-455). If you've caught on to the trend, the cheapest time to fly is New Year's Eve, returning on New Year's Day (\$346). Here are some more cost-effective departure and return dates, according to Kayak’s 2016 metrics:

• Depart Dec. 31, return Jan. 2 (\$349)
• Depart Dec. 31, return Jan. 3 (\$360)