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.
bukhari:1222Yaḥyá b. Bukayr > al-Layth > Jaʿfar > al-Aʿraj > Abū Hurayrah > Rasūl

Messenger of Allah ﷺ said, "When the Adhan for the prayer is pronounced, then Satan takes to his heels passing wind so that he may not hear the Adhan and when the Mu'adh-dhin finishes, he comes back; and when the Iqama is pronounced he again takes to his heels and when it is finished, he again comes back and continues reminding the praying person of things that he used not to remember when not in prayer till he forgets how much he has prayed." Abu Salama bin ʿAbdur-Rahman said, "If anyone of you has such a thing (forgetting the number of rakʿat he has prayed) he should perform two prostrations of Sahu (i.e. forgetfulness) while sitting." Abu Salama narrates this from Abu Huraira.  

البخاري:١٢٢٢حَدَّثَنَا يَحْيَى بْنُ بُكَيْرٍ حَدَّثَنَا اللَّيْثُ عَنْ جَعْفَرٍ عَنِ الأَعْرَجِ قَالَ قَالَ أَبُو هُرَيْرَةَ ؓ

قَالَ رَسُولُ اللَّهِ ﷺ إِذَا أُذِّنَ بِالصَّلاَةِ أَدْبَرَ الشَّيْطَانُ لَهُ ضُرَاطٌ حَتَّى لاَ يَسْمَعَ التَّأْذِينَ فَإِذَا سَكَتَ الْمُؤَذِّنُ أَقْبَلَ فَإِذَا ثُوِّبَ أَدْبَرَ فَإِذَا سَكَتَ أَقْبَلَ فَلاَ يَزَالُ بِالْمَرْءِ يَقُولُ لَهُ اذْكُرْ مَا لَمْ يَكُنْ يَذْكُرُ حَتَّى لاَ يَدْرِي كَمْ صَلَّى قَالَ أَبُو سَلَمَةَ بْنُ عَبْدِ الرَّحْمَنِ إِذَا فَعَلَ أَحَدُكُمْ ذَلِكَ فَلْيَسْجُدْ سَجْدَتَيْنِ وَهُوَ قَاعِدٌ وَسَمِعَهُ أَبُو سَلَمَةَ مِنْ أَبِي هُرَيْرَةَ ؓ  


See similar narrations below:

Collected by Muslim, Aḥmad
muslim:389hMuḥammad b. al-Muthanná > Muʿādh b. Hishām from my father > Yaḥyá b. Abū Kathīr > Abū Salamah b. ʿAbd al-Raḥman > Abū Hurayrah

The Messenger of Allah ﷺ said: When there is a call to prayer the devil runs back breaking the wind so that he may not hear the call, and when the call is complete he comes back. And when the takbir is pronounced he again runs back, and when takbir is over he comes back and distracts a man saying: Remember such and such, remember such and such, referring to something the man did not have in his mind. with the result that he does not know how much he has prayed; so when any one of you is not sure how much he has prayed. he should perform two prostrations while sitting (qa'da).  

مسلم:٣٨٩hحَدَّثَنَا مُحَمَّدُ بْنُ الْمُثَنَّى حَدَّثَنَا مُعَاذُ بْنُ هِشَامٍ حَدَّثَنِي أَبِي عَنْ يَحْيَى بْنِ أَبِي كَثِيرٍ حَدَّثَنَا أَبُو سَلَمَةَ بْنُ عَبْدِ الرَّحْمَنِ أَنَّ أَبَا هُرَيْرَةَ حَدَّثَهُمْ

أَنَّ رَسُولَ اللَّهِ ﷺ قَالَ إِذَا نُودِيَ بِالأَذَانِ أَدْبَرَ الشَّيْطَانُ لَهُ ضُرَاطٌ حَتَّى لاَ يَسْمَعَ الأَذَانَ فَإِذَا قُضِيَ الأَذَانُ أَقْبَلَ فَإِذَا ثُوِّبَ بِهَا أَدْبَرَ فَإِذَا قُضِيَ التَّثْوِيبُ أَقْبَلَ يَخْطُرُ بَيْنَ الْمَرْءِ وَنَفْسِهِ يَقُولُ اذْكُرْ كَذَا اذْكُرْ كَذَا لِمَا لَمْ يَكُنْ يَذْكُرُ حَتَّى يَظَلَّ الرَّجُلُ إِنْ يَدْرِي كَمْ صَلَّى فَإِذَا لَمْ يَدْرِ أَحَدُكُمْ كَمْ صَلَّى فَلْيَسْجُدْ سَجْدَتَيْنِ وَهُوَ جَالِسٌ  

ahmad:10769ʿAbd al-Malik b. ʿAmr > Hishām > Yaḥyá > Abū Salamah > Abū Hurayrah

Messenger of Allah ﷺ 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. (Using translation from Bukhārī 1231)  

أحمد:١٠٧٦٩حَدَّثَنَا عَبْدُ الْمَلِكِ بْنُ عَمْرٍو حَدَّثَنَا هِشَامٌ عَنْ يَحْيَى عَنْ أَبِي سَلَمَةَ عَنْ أَبِي هُرَيْرَةَ

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