In terms of how far in advance, it is recommended to book when you spot a cheap flight ticket deal 1-3 months in dance for local flights and about 2-8 months for international flights. If you are planning to book in peak summer, you should add 1-2 months onto these recommendations, but if you are travelling during the low season, there are high chances that cheap international airfare deals will pop up closer to your departure date.
Generally, prices tend to jump in the last 1-2 months before departure, so it is not advisable to cut it too close. On the flip side, sometimes when you book too early and settle on a price that is not too great, you could be missing out on future cheap airfare deals. So, it is important to consider other factors such as travelling on certain days of the week, flying from certain destinations, and using apps among others.