Short answer
A Hijri month is 29 or 30 days. If travel leaves you with only 28 fasts when Eid arrives where you are, celebrate Eid with the local Muslims and make up one day afterwards. If you have done 30 and the place you are in is still fasting, fast with them and celebrate Eid with them, even though it makes 31 for you.
A traveller follows the community where he is for the start of Eid. If he has fasted fewer than 29 days, he makes up the missing days, since a month is never less than 29. If the local people are still fasting on what would be his 31st day, he fasts with them.
The four schools agree on this.
Explanation
The Prophet ﷺ said the month is twenty-nine nights, so do not fast until you see the moon, and if it is hidden, complete thirty. So Ramadan is never 28 days and never 31. But when you start Ramadan in one country and end it in another, your own count can come out differently.
If you end with 28 fasts. For example, you began a day late at home and then flew to a country that sighted Eid a day early. Celebrate Eid with the people where you are, since fasting on their Eid day is not allowed, and make up one fast after Eid. You owed at least 29.
If you reach 30 and they are still fasting. For example, you started a day early and then flew to a country that began a day later. Fast the extra day with the local Muslims and celebrate Eid with them. The principle is that you fast and celebrate Eid with the Muslims where you are, so the extra day is fasted with them.
- Your extra day is not wasted: it is rewarded.
- If you are only passing through, follow the place where you are when the day begins.
- Zakat al-fitr is still paid before the Eid prayer you attend.
Moon sighting is a question on which sincere scholars differ, especially on local versus global sighting. Follow the trusted authority where you are, and do not argue about it. See fasting while travelling and the moon sighting calculator.
The evidence
Quran, Surah Al-Baqara 2:185
شَهْرُ رَمَضَانَ ٱلَّذِىٓ أُنزِلَ فِيهِ ٱلْقُرْءَانُ هُدًۭى لِّلنَّاسِ وَبَيِّنَٰتٍۢ مِّنَ ٱلْهُدَىٰ وَٱلْفُرْقَانِ ۚ فَمَن شَهِدَ مِنكُمُ ٱلشَّهْرَ فَلْيَصُمْهُ ۖ وَمَن كَانَ مَرِيضًا أَوْ عَلَىٰ سَفَرٍۢ فَعِدَّةٌۭ مِّنْ أَيَّامٍ أُخَرَ ۗ يُرِيدُ ٱللَّهُ بِكُمُ ٱلْيُسْرَ وَلَا يُرِيدُ بِكُمُ ٱلْعُسْرَ وَلِتُكْمِلُوا۟ ٱلْعِدَّةَ وَلِتُكَبِّرُوا۟ ٱللَّهَ عَلَىٰ مَا هَدَىٰكُمْ وَلَعَلَّكُمْ تَشْكُرُونَ ﴿١٨٥﴾
The month of Ramadhan [is that] in which was revealed the Qur'an, a guidance for the people and clear proofs of guidance and criterion. So whoever sights [the new moon of] the month, let him fast it; and whoever is ill or on a journey - then an equal number of other days. Allah intends for you ease and does not intend for you hardship and [wants] for you to complete the period and to glorify Allah for that [to] which He has guided you; and perhaps you will be grateful.
Fasting is tied to the sighting of the month where you are.
Sahih al-Bukhari 1907
Sahih... الشهر تسع وعشرون ليلة فلا تصوموا حتى تروه فإن غم عليكم فأكملوا العدة ثلاثين ...
"The month is twenty-nine nights, so do not fast until you see it, and if it is hidden from you, complete thirty."
A month is 29 or 30 days, never 28 or 31.
Where the ruling is recorded
- Radd al-Muhtar (Ibn Abidin), Kitab al-Sawm, chapter on sighting the crescent. A person who travels follows the place he reaches; if he has fasted 28, he makes up a day.
- al-Fatawa al-Hindiyya, Kitab al-Sawm, chapter on sighting the crescent. The month is not less than 29 days.
Checked by our team. For a more accurate answer to your own situation, consult a scholar. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.