I would say 1-2 months before flying.
That being said, there are often sales, and you should buy it immediately you see a price you like if you have fixed dates.
The only issue is that these cheap fares have rules that don't allow for free changes.
What flight are you looking at and what is the price?