Most airlines allow flying up to 36 weeks, but the safest window is 14 to 28 weeks. Always consult your doctor for medical clearance before booking any tickets.
We went for a short trip in my second trimester and the flight was very comfortable. Just get that doctor's note and carry your prenatal medical files with you.
I flew during my 5th month and it was totally fine. I just wore compression socks and kept hydrating, but please check with your own gynac as every case is unique.
Beta, if there is no emergency, avoid long flights. But if you must go, 4th to 6th month is best and keep walking in the aisle so your legs don't swell.