صحيح البخاري Sahih Bukhari كتاب السهو The Book of As-Sahw (Forgetting)
بَابُ إِذَا لَمْ يَدْرِ كَمْ صَلَّى ثَلاَثًا أَوْ أَرْبَعًا، سَجَدَ سَجْدَتَيْنِ وَهْوَ جَالِسٌ:

(6) Chapter. When a person forgets whether he has offered three or four Raka (then he should) perform two prostrations while sitting in his last Raka.

1 hadith
Hadith 1231
حَدَّثَنَا مُعَاذُ بْنُ فَضَالَةَ ، حَدَّثَنَا هِشَامُ بْنُ أَبِي عَبْدِ اللَّهِ الدَّسْتَوَائِيُّ ، عَنْ يَحْيَى بْنِ أَبِي كَثِيرٍ ، عَنْ أَبِي سَلَمَةَ ، عَنْ أَبِي هُرَيْرَةَ رَضِيَ اللَّهُ عَنْهُ , قَالَ : قَالَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ : " إِذَا نُودِيَ بِالصَّلَاةِ أَدْبَرَ الشَّيْطَانُ وَلَهُ ضُرَاطٌ حَتَّى لَا يَسْمَعَ الْأَذَانَ ، فَإِذَا قُضِيَ الْأَذَانُ أَقْبَلَ فَإِذَا ثُوِّبَ بِهَا أَدْبَرَ ، فَإِذَا قُضِيَ التَّثْوِيبُ أَقْبَلَ حَتَّى يَخْطِرَ بَيْنَ الْمَرْءِ وَنَفْسِهِ ، يَقُولُ اذْكُرْ كَذَا وَكَذَا مَا لَمْ يَكُنْ يَذْكُرُ حَتَّى يَظَلَّ الرَّجُلُ إِنْ يَدْرِي كَمْ صَلَّى ، فَإِذَا لَمْ يَدْرِ أَحَدُكُمْ كَمْ صَلَّى ثَلَاثًا أَوْ أَرْبَعًا فَلْيَسْجُدْ سَجْدَتَيْنِ وَهُوَ جَالِسٌ " .
Narrated Abu Huraira: Allah's Apostle said, "When the call for prayer is made, Satan takes to his heels passing wind so that he may not hear the Adhan and when the call is finished he comes back, and when the Iqama is pronounced, Satan again takes to his heels, and when the Iqama is finished he comes back again and tries to interfere with the person and his thoughts and say, "Remember this and that (which he has not thought of before the prayer)", till the praying person forgets how much he has prayed. If anyone of you does not remember whether he has offered three or four rak`at then he should perform two prostrations of Sahu while sitting.
Hadith Reference Sahih Bukhari / The Book of As-Sahw (Forgetting) / Hadith: 1231
Hadith Grading محدثین: أحاديث صحيح البخاريّ كلّها صحيحة