Sunan Ibn Majah, Book 5, Hadith 1274 (In-Book) ⓘ
It was narrated from Abu Hurairah that the Prophet said: “The Satan comes between the son of Adam and his soul, and he does not know how many Rak’ah he has prayed. If a person notices that, then let him prostrate twice before he says the Salam.”
حَدَّثَنَا سُفْيَانُ بْنُ وَكِيعٍ، حَدَّثَنَا يُونُسُ بْنُ بُكَيْرٍ، حَدَّثَنَا ابْنُ إِسْحَاقَ، أَخْبَرَنِي سَلَمَةُ بْنُ صَفْوَانَ بْنِ سَلَمَةَ، عَنْ أَبِي سَلَمَةَ، عَنْ أَبِي هُرَيْرَةَ، أَنَّ النَّبِيَّ ـ صلى الله عليه وسلم ـ قَالَ " إِنَّ الشَّيْطَانَ يَدْخُلُ بَيْنَ ابْنِ آدَمَ وَبَيْنَ نَفْسِهِ فَلاَ يَدْرِي كَمْ صَلَّى فَإِذَا وَجَدَ ذَلِكَ فَلْيَسْجُدْ سَجْدَتَيْنِ قَبْلَ أَنْ يُسَلِّمَ " .
also referenced under: Hadith 1217 (Reference) & Volume 2, Book 5, Hadith 1217 (DarusSalam)