Praise be to Allah.
The first hadeeth was narrated from ‘Abd-Allaah ibn ‘Umar by al-Bukhaari (619) and Muslim (650). It says: “Praying in congregation is twenty seven times better than praying alone”.
The second hadeeth was narrated from Abu Sa’eed al-Khudri, and was narrated by al-Bukhaari (619). It says: “Praying in congregation is twenty-five times better than praying alone.”
The scholars have reconciled between these two hadeeth. Al-Nawawi (may Allaah have mercy on him) said:
They may be reconciled in three ways:
1 – There is no contradiction because mentioning a smaller number does not rule out the larger number. Taking numbers literally is not acceptable according to the scholars of usool.
2 – He first spoke of the smaller number then Allaah told him of the greater bounty so he spoke of that.
3 – It may vary according to the circumstances of the worshippers and the prayer. So for some of them it may be twenty-five and for some it may be twenty-seven, depending on how complete their prayer is, whether it is done in the proper manner and with proper focus and humility (khushoo’), the number of people present, how good they are, how good the environment is, etc. And Allaah knows best.
And there are other ways of reconciling the two hadeeth, some of which are based on the above. Al-Haafiz Ibn Hajar suggested another way in Fath al-Baari (2/132) which was not mentioned by al-Nawawi, which is twenty-seven applies to the prayers in which Qur’aan is recited out loud and twenty-five applies to the prayers in which it is recited silently.
And Allaah knows best.