كتاب الْمَسَاجِدِ وَمَوَاضِعِ الصَّلاَةِ
5  
The Book of Mosques and Places of Prayer
(19)
Chapter: As-Sahw (forgetfulness) in prayer and prostrating to compensate for it
(19)
باب السَّهْوِ فِي الصَّلاَةِ وَالسُّجُودِ لَهُ ‏
Sahih Muslim 389 h

Abu Huraira reported:

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).
حَدَّثَنَا مُحَمَّدُ بْنُ الْمُثَنَّى، حَدَّثَنَا مُعَاذُ بْنُ هِشَامٍ، حَدَّثَنِي أَبِي، عَنْ يَحْيَى بْنِ أَبِي كَثِيرٍ، حَدَّثَنَا أَبُو سَلَمَةَ بْنُ عَبْدِ الرَّحْمَنِ، أَنَّ أَبَا هُرَيْرَةَ، حَدَّثَهُمْ أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم قَالَ ‏ "‏ إِذَا نُودِيَ بِالأَذَانِ أَدْبَرَ الشَّيْطَانُ لَهُ ضُرَاطٌ حَتَّى لاَ يَسْمَعَ الأَذَانَ فَإِذَا قُضِيَ الأَذَانُ أَقْبَلَ فَإِذَا ثُوِّبَ بِهَا أَدْبَرَ فَإِذَا قُضِيَ التَّثْوِيبُ أَقْبَلَ يَخْطُرُ بَيْنَ الْمَرْءِ وَنَفْسِهِ يَقُولُ اذْكُرْ كَذَا اذْكُرْ كَذَا ‏.‏ لِمَا لَمْ يَكُنْ يَذْكُرُ حَتَّى يَظَلَّ الرَّجُلُ إِنْ يَدْرِي كَمْ صَلَّى فَإِذَا لَمْ يَدْرِ أَحَدُكُمْ كَمْ صَلَّى فَلْيَسْجُدْ سَجْدَتَيْنِ وَهُوَ جَالِسٌ ‏"‏ ‏.‏
Reference : Sahih Muslim 389h
In-book reference : Book 5, Hadith 105
USC-MSA web (English) reference : Book 4, Hadith 1161
  (deprecated numbering scheme)