We know from personal experience that we may be distracted during prayer, and such distraction could lead us to forget, while praying, how much of our prayer we have completed. Distraction does not affect prayer validity, but when we are not sure how many rak’ahs we have done, how to complete our prayer? The answer is simple: If you wonder whether you have done two or three rak’ahs, you are certain that you have done two, but you are doubtful about the third. You remove the doubt by completing your prayer on the basis of what is certain, which is two rak’ahs. Before you finish, you add two prostrations, or sujood, to compensate for the confusion.
The Prophet, peace be upon him, provides guidance on different situations of forgetfulness during prayer. Abu Hurairah reports: “God’s Messenger led us in Asr prayer (which is four rak’ahs) but he finished after completing only two rak’ahs. Dhul-Yadayn stood up and said: ‘Messenger of God! Has prayer been reduced or you have forgotten?’ The Prophet, peace be upon him, said: ‘Neither thing happened.’ Dhul-Yadayn said: ‘Messenger of God! Either alternative did happen.’ The Prophet, peace be upon him, turned to the people and asked: ‘Is Dhul-Yadayn correct?’ They replied in the affirmative. The Prophet, peace be upon him, therefore, completed his prayer and added two prostrations after he finished with Salam, without standing up.” (Related by Malik and Muslim.)
We note here that a short discussion took place but it did not invalidate the prayer, although ordinary speech during prayer will invalidate it. The reason is that the discussion was concerned with the prayer being offered and ensuring that it was done properly. Had the spoken words been concerned with anything outside prayer, they would have invalidated it.
There are other Hadiths stating that the Prophet, peace be upon him, forgot some part of his prayer, but we will quote two only: Abdullah ibn Mas’ud reports: “The Prophet, peace be upon him, once offered Dhuhr prayer in five rak’ahs instead of four. After he finished some of his companions asked: ‘Has prayer been increased?’ He asked: ‘What do you mean?’ They told him that he prayed five rak’ahs. He, therefore, offered two prostrations after he had finished his prayer.” (Related in all six collections.) Abdullah ibn Buhaynah reports: “Once the Prophet, peace be upon him, completed two rak’ahs and stood up for the third without sitting for Tashahhud. When he completed his prayer, he did two prostrations then finished his prayer with Salam.” (Related by Malik, Al-Bukhari and Muslim.)
We should note that the two prostrations mentioned in all three Hadiths are known as Sujood Al-Sahv, while finishing prayer refers to the Salam when one has completed all his prayer and ends it.