Caution: Translations of Quran and Ḥadīth may lead to possible misapplications and misinterpretations. This site is intended for students of sacred knowledge that are proficient in comprehending classical Arabic and have a strong foundation in Islamic sciences. Also note that religious injunctions rely on several aspects beyond what one may glean through reading individual aḥādīth.
tirmidhi:398Muḥammad b. Bashhār > Muḥammad b. Khālid Ibn ʿAthmah al-Baṣrī > Ibrāhīm b. Saʿd > Muḥammad b. Isḥāq > Makḥūl > Kurayb > Ibn ʿAbbās > ʿAbd al-Raḥman b. ʿAwf

"When one of you becomes forgetful in his Salat so that he does not know if he prayed one or two, then let him consider it one. When he does not know if he prayed three or four, then let him consider it three, and let him perform two prostrations before he says the Taslim."  

الترمذي:٣٩٨حَدَّثَنَا مُحَمَّدُ بْنُ بَشَّارٍ حَدَّثَنَا مُحَمَّدُ بْنُ خَالِدٍ ابْنُ عَثْمَةَ الْبَصْرِيُّ حَدَّثَنَا إِبْرَاهِيمُ بْنُ سَعْدٍ قَالَ حَدَّثَنِي مُحَمَّدُ بْنُ إِسْحَاقَ عَنْ مَكْحُولٍ عَنْ كُرَيْبٍ عَنِ ابْنِ عَبَّاسٍ عَنْ عَبْدِ الرَّحْمَنِ بْنِ عَوْفٍ قَالَ

سَمِعْتُ النَّبِيَّ ﷺ يَقُولُ إِذَا سَهَا أَحَدُكُمْ فِي صَلاَتِهِ فَلَمْ يَدْرِ وَاحِدَةً صَلَّى أَوْ ثِنْتَيْنِ فَلْيَبْنِ عَلَى وَاحِدَةٍ فَإِنْ لَمْ يَدْرِ ثِنْتَيْنِ صَلَّى أَوْ ثَلاَثًا فَلْيَبْنِ عَلَى ثِنْتَيْنِ فَإِنْ لَمْ يَدْرِ ثَلاَثًا صَلَّى أَوْ أَرْبَعًا فَلْيَبْنِ عَلَى ثَلاَثٍ وَلْيَسْجُدْ سَجْدَتَيْنِ قَبْلَ أَنْ يُسَلِّمَ  

قَالَ أَبُو عِيسَى هَذَا حَدِيثٌ حَسَنٌ صَحِيحٌ وَقَدْ رُوِيَ هَذَا الْحَدِيثُ عَنْ عَبْدِ الرَّحْمَنِ بْنِ عَوْفٍ مِنْ غَيْرِ هَذَا الْوَجْهِ رَوَاهُ الزُّهْرِيُّ عَنْ عُبَيْدِ اللَّهِ بْنِ عَبْدِ اللَّهِ بْنِ عُتْبَةَ عَنِ ابْنِ عَبَّاسٍ عَنْ عَبْدِ الرَّحْمَنِ بْنِ عَوْفٍ عَنِ النَّبِيِّ ﷺ

See similar narrations below:

Collected by Suyūṭī
suyuti:2021a

"When one of you becomes forgetful in his Salat so that he does not know if he prayed one or two, then let him consider it one. When he does not know if he prayed three or four, then let him consider it three, and let him perform two prostrations before he says the Taslim." (Using translation from Tirmidhī 398)   

السيوطي:٢٠٢١a

"إِذَا سَهَا أحدُكم في صلاتِه فلم يدرِ واحدةً صلى أوْ ثنتْين؟ فْلَيَبْنِ علَى واحدةٍ، فإِنْ لمْ يدرِ ثلاثًا صلّى أو أرْبعًا؟ فليبْنِ على ثلاثٍ، ولْيَسجدْ سجدتين قبلَ أنْ يُسلِّمَ".  

[ت] الترمذي حسن عن ابن عباس عن عبد الرحمن بن عوف