Bargain-conscious travelers have been trying to answer the question for years and are still stymied: How far in advance do you have to book to get the best airfare?



According to new research by CheapAir.com based on the travel site's review of 560 million airfares, the optimal time to book a domestic flight is 49 days in advance. If you're flying overseas, you should book almost three months -- 81 days, to be precise -- before you travel.



Too much planning for you? Don't worry. While the average domestic flight was the cheapest 49 days out, it didn't start to rise dramatically in price until about two weeks before the departure date. But if you wait until the day or two before you want to travel, get ready for some serious pocketbook pain. Domestic flights that would normally cost less than $400 jump to about $625.



Notably, it's also bad for your pocketbook to book too far in advance, according to CheapAir. People who booked 210 days before the flight ended up paying an average of $475 for a domestic ticket. There are exceptions and caveats, however. If you're booking for a high-traffic time, like Thanksgiving, it can make sense to book well in advance. The optimal time to buy a flight for Thanksgiving weekend in 2012, for instance, was 96 days in advance.



If you're taking an international flight, by contrast, you might score a real bargain by being spontaneous. For example, the best price CheapAir found for a Los Angeles-to-Tokyo flight was when the traveler booked one day before the flight.



Other factoids of note: Booking a flight on a Tuesday or Wednesday is not likely to save any money. But flying on a Tuesday or Wednesday will.



And, of course, while this study focuses on average ticket prices, there are a lot of one-time deals that can make booking at any given time either a bargain or a bust. CheapAir tries to deal with the frustrations of variable airline pricing by offering a customer payback program. If you book a flight through the site and find that your specific itinerary has dropped in price, it offers you up to a $100 credit for another flight. And what if another airline offers a better deal in the meantime? Unless you're traveling on one of the rare airlines, such as Southwest, that will allow you to change your ticket without penalty, you're out of luck.























