The Prophet ﷺ offered the fear prayer with those who were behind him, praying two rak'ahs (with them) and two rak'ahs with those who came after them, so the Prophet ﷺ prayed four rak'ahs and the others each prayed two rak'ahs.
عَنِ النَّبِيِّ ﷺ أَنَّهُ صَلَّى صَلاَةَ الْخَوْفِ بِالَّذِينَ خَلْفَهُ رَكْعَتَيْنِ وَالَّذِينَ جَاءُوا بَعْدُ رَكْعَتَيْنِ فَكَانَتْ لِلنَّبِيِّ ﷺ أَرْبَعَ رَكَعَاتٍ وَلِهَؤُلاَءِ رَكْعَتَيْنِ رَكْعَتَيْنِ