The biggest factor is the route that you're flying.
It makes sense when you understand how airline fares work. Airlines usually have dozens of fares that apply to any particular flight. Each fare has restrictions to specific inventory buckets, advance purchase days, days of the week, times of the day, routing options, date ranges, etc. The price you see when you search for flights is the best available fare whose criteria match. As the cheaper inventory buckets sell out, only the more expensive fares remain. As it gets closer to the dates, the cheaper fares with longer advance purchase requirements go away, leaving just more expensive ones.
Some of the more common advance purchase days I've seen include 0, 3, 7, 10, 14, 21 and 30. Sometimes, the cheapest fares don't require any advance purchase (usually on routes where low cost carriers compete), so you can still get good prices at the last minute.
Personally, I start watching for low fares as soon as I know when I need to fly. I usually don't find really good fares until 1-3 months out (but there are always exceptions). Once I get 1-2 months out, I get a lot less picky about how good of a fare I really need. I seldom go beyond 1 month out, because it's much more rare to catch good fares but it's very common to have considerably higher fares. If I were going to hold out for a better fare in the last month, I would take a very close look at fares to see which ones have what advance purchase requirements. If I see fares that are near the current prices that only require 0, 3 or 7 days, I might wait longer.