Al-Ilmam bi-Ahadith al-Ahkam 258
عَن أبي سعيد الْخُدْرِيّ رَضِيَ اللَّهُ عَنْه، قَالَ: قَالَ رَسُول الله ﷺ : " إِذا شكّ أحدكُم فِي صلَاته فَلم يدر كم صَلَّى ثَلَاثًا أَو أَرْبعا، فليطرح الشَّك ﷺ وليبن عَلَى مَا استيقن، ثمَّ يسْجد سَجْدَتَيْنِ قبل أَن يسلم ، فَإِن كَانَ صَلَّى خمْسا شفعن لَهُ صلَاته، وَإِن كَانَ صَلَّى تَمامًا لأَرْبَع كَانَتَا ترغيماً للشَّيْطَان ". أخرجه مُسلم. وَفِي رِوَايَة هِشَام بن سعد لهَذَا الحَدِيث: " إِذا شكّ أحدكُم فِي صلَاته فَلَا يدر ي كم صَلَّى ثَلَاثًا أَو أَرْبعا، فَليقمْ فَليصل رَكْعَة ". الحَدِيث أخرجه الْبَيْهَقِيّ فِي " الْمعرفَة " من حَدِيث ابْن وهب عَنهُ، وَعَن غَيره وَلم يرفعهُ مِنْهُم غَيره.
From Abu Saʿid al-Khudri, may Allah be pleased with him, who said: The Messenger of Allah ﷺ said: "When one of you is in doubt in his prayer and does not know how much he has prayed, three or four, let him cast aside the doubt and build on what he is certain of, then prostrate twice before he gives the salam. If he has prayed five, they will make his prayer even, and if he prayed exactly four, they will be a humiliation for Satan." Muslim recorded it. And in the narration of Hisham ibn Saʿd of this hadith: "When one of you is in doubt in his prayer and does not know how much he has prayed, three or four, let him stand and pray one rakʿah" — the hadith. Al-Bayhaqi recorded it in "al-Maʿrifah" from the hadith of Ibn Wahb from him and from others, and none of them traced it to the Prophet except him.