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.
bayhaqi:3828[Chain 1] Abū ʿAbdullāh al-Ḥāfiẓ > Aḥmad b. Salmān > ʿUbayd b. ʿAbd al-Wāḥid [Chain 2] ʿAlī b. Aḥmad b. ʿAbdān > Aḥmad b. ʿUbayd al-Ṣaffār > ʿUbayd b. Sharīk And Ibn Milḥān > Yaḥyá b. Bukayr > al-Layth > Ibn Shihāb > Abū Salamah > Abū Hurayrah

[Machine] He said, the Messenger of Allah ﷺ said, "Satan comes to one of you during his prayer and confuses him until he does not know how much he has prayed. So if any of you experiences this, let him perform two prostrations while sitting."  

البيهقي:٣٨٢٨أَخْبَرَنَا أَبُو عَبْدِ اللهِ الْحَافِظُ أنبأ أَحْمَدُ بْنُ سَلْمَانَ ثنا عُبَيْدُ بْنُ عَبْدِ الْوَاحِدِ ح وَأَخْبَرَنَا عَلِيُّ بْنُ أَحْمَدَ بْنِ عَبْدَانَ أنبأ أَحْمَدُ بْنُ عُبَيْدٍ الصَّفَّارُ ثنا عُبَيْدُ بْنُ شَرِيكٍ وَابْنُ مِلْحَانَ قَالَا ثنا يَحْيَى بْنُ بُكَيْرٍ ثنا اللَّيْثُ عَنِ ابْنِ شِهَابٍ عَنْ أَبِي سَلَمَةَ عَنْ أَبِي هُرَيْرَةَ

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

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

See similar narrations below:

Collected by Mālik
malik:4-1Yaḥyá > Mālik > Ibn Shihāb > Abū Salamah b. ʿAbd al-Raḥman b. ʿAwf > Abū Hurayrah

Yahya related to me from Malik from Ibn Shihab from Abu Salama ibn Abdar-Rahman ibn Awf from Abu Hurayra that the Messenger of Allah ﷺ said, "When you stand in prayer, Shaytan comes to you and confuses you until you do not know how much you have prayed. If you find that happening do two sajdas from the sitting position."  

مالك:٤-١حَدَّثَنِي يَحْيَى عَنْ مَالِكٍ عَنِ ابْنِ شِهَابٍ عَنْ أَبِي سَلَمَةَ بْنِ عَبْدِ الرَّحْمَنِ بْنِ عَوْفٍ عَنْ أَبِي هُرَيْرَةَ

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