When it comes to booking affordable air fare, it’s all about timing.

“The worst thing you can do is book the ticket really early or really late,” says Jeff Klee, chief executive of CheapAir.com. “You end up paying the most.”

The airfare shopping recently sifted through more than 560 million fare search records in more than 11,000 domestic markets to find the perfect time to snag the lowest airfare.

While the results vary depending on the destination, airport and airline, Klee says in general. Fliers end up paying the most if they book a flight one to 11 days before their departure date. “The average ticket price the day before on a domestic flight is $650 and when you buy at the optimal time it’s closer to $400.”

But early bookers also don’t get the bargain worm. The research shows that outside of last- minute purchases, the most expensive time to buy a flight was 208, 209 and 210 days before the travel date, and was the farthest back the data went.

According to CheapAir, the best time to book your flight is 49 days or seven weeks in advance for a domestic flight, and 81 days or 11 weeks before an international flight. 

When airlines first open up a flight they tend to keep prices steady and don’t offer that many discounts, according to Klee. Two to three months before the take-off date, airlines start to focus on filling seats and will start discounting ticket prices. But travelers have to walk a fine line because as the flight date gets closer, they run the risk of having all the cheap tickets sold out and the only available seats are the pricey ones, says Klee. “It’s best to buy during the sweet spot in the middle. You don’t want to book to early or too late.”

When you fly also has a bearing on the price you’ll pay.  The least expensive day to fly is Tuesday and Sunday is the most expensive. CheapAir found the typical price difference is $58 for a round trip flight. Wednesday is also a cheaper day to fly while Friday is the second most expensive day to board an airplane.

Although some travel experts claim the day airfare is purchased will weigh on cost, CheapAir’s research doesn’t prove that theory. “It didn’t make a difference at all on each day of the week,” says Klee. “There was nothing statistically significant [in terms of the price] which was a little surprising.”

Even though the research showed that on average seven weeks prior to departure can land the best airfare price, Klee says there are a lot of variances depending on the market and the destination. In some instances buying on the first day of a sale was the best bargain, while other examples showed waiting to the last minute yielded the best deal. “Even though 49 days is the average every situation is really different. We hoped to get some conclusion and that it would be a little more standard across the board but the reality is that doesn’t exist.”

The best strategy is to keep a watchful eye on airline tickets once a destination and date is determined. “If you see fares going up then it’s unlikely they are going to come down again,” says Klee. If it’s early and the prices are staying the same, then there’s a good chance they will come down later, he says.