عَنْ أَبِي هُرَيْرَةَ ـ رضى الله عنه أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم قَالَ: إِنَّ أَحَدَكُمْ إِذَا قَامَ يُصَلِّي جَاءَ الشَّيْطَانُ فَلَبَسَ عَلَيْهِ حَتَّى لاَ يَدْرِيَ كَمْ صَلَّى، فَإِذَا وَجَدَ ذَلِكَ أَحَدُكُمْ فَلْيَسْجُدْ سَجْدَتَيْنِ وَهُوَ جَالِسٌ.
Hazrat Abu Hurairahra narrated that Allah’s Messengersa said, “When any one of you stands to pray, Satan comes to him and confuses him, so that he no longer knows how many rak‘at he has performed. If this happens to someone, he should make two prostrations of forgetfulness [sahw] while seated.”
(Sahih al-Bukhari, Kitab as-sahw, Bab as-sahwi fi l-fardi wa t-tatawwu‘i, Hadith 1232)