The Messenger of Allah ﷺ said, "When one of you stands to pray, Satan comes to him and confuses him until he does not know how much he has prayed. So when one of you experiences this, let him perform two prostrations while he is sitting."
أن رسول الله ﷺ قال: إن أحدكم إذا قام يصلي، جاءه الشيطان، فلبس عليه. حتى لا يدري كم صلى؟ فإذا وجد أحدكم فليسجد سجدتين، وهو جالس.
Malik narrated it in the Chapter on Forgetfulness (1) from Ibn Shihab, from Abu Salama bin Abdul-Rahman bin Awf, from Abu Hurairah, as mentioned. Bukhari narrated it in the Chapter on Forgetfulness (1232) from Abdullah bin Yusuf, and Muslim narrated it in the Chapter on Mosques (82) from Yahya bin Yahya, both of them from Malik with the same wording.A similar report was also narrated from Abu Saeed Khudri, with this wording, "When one of you prays and does not know whether he added or omitted, let him prostrate twice while sitting. If Satan comes to him and says, 'You have broken your prayer,' let him say, 'You have lied,' unless he detects a smell with his nose or a sound with his ear." Abu Dawud (1029), Tirmidhi (396), and Ibn Majah (1204) all narrated it through the route of Ismail bin Ibrahim (known as Ibn Ulaya) from Hisham Dastawai, from Yahya bin Abu Kathir, from Ayyad (that is, Ibn Hilal), from Abu Saeed Khudri, as mentioned, and the wording given is that of Abu Dawud. Tirmidhi and Ibn Majah abbreviated it, saying, "When one of you prays and does not know how many prostrations he performed, let him prostrate twice while sitting."Tirmidhi said, "Hasan." I say, rather its chain is daif, for Ayyad bin Hilal, also said to be Ibn Abu Zuhayr, as Ibn Hibban recorded his biography in al-Thiqat (5/266), was not deemed reliable by anyone else. Yahya bin Abu Kathir was the only one who narrated from him, and for this reason al-Hafiz said in al-Taqrib, "Unknown," and gave his biography under the name Ayyad bin Hilal.Tirmidhi said, "This hadith has also been narrated from Abu Saeed through a route other than this one." I say, he means the hadith of Abu Saeed that will be mentioned later concerning building upon certainty, followed by the two prostrations of forgetfulness, which is the position held by the majority of scholars of knowledge. However, Hasan Basri and some of the early scholars took the apparent meaning of these hadiths, saying that if the one praying doubts and does not know whether he added or omitted, he need only perform two prostrations.The majority said that the hadith of Abu Hurairah is general in meaning and is explained by the hadith of Abu Saeed Khudri that follows, which is, "When one of you is in doubt during his prayer and does not know how many he has prayed, three or four, let him set aside the doubt and build upon what he is certain of, then let him prostrate twice before finishing with the greeting of peace." Imam Ahmad, may Allah have mercy on him, spoke truly when he said, "Each hadith explains the other."