Sunan Ibn Majah, Book 5, Hadith 1266 (In-Book)

It was narrated that ‘Abdur-Rahman bin ‘Awf said: “I heard the Messenger of Allah say: ‘If anyone of you is uncertain as to whether he has prayed one or two Rak’ah, let him assume it is one. If he is uncertain as to whether he has prayed two or three, let him assume it is two. If he is uncertain as to whether he has prayed three or four, let him assume it is three. Then let him complete what is left of his prayer, so that the doubt will be about what is more. Then let him prostrate twice while he is sitting, before the Taslim (saying the Salam).’”

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

sunnah.com