Sunan at-Tirmithiy كتاب الصلاة باب ما يقول عند افتتاح الصلاة

حَدَّثَنَا قُتَيْبَةُ حَدَّثَنَا اللَّيْثُ عَنِ ابْنِ شِهَابٍ عَنْ أَبِى سَلَمَةَ عَنْ أَبِى هُرَيْرَةَ قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم إِنَّ الشَّيْطَانَ يَأْتِى أَحَدَكُمْ فِى صَلاَتِهِ فَيَلْبِسُ عَلَيْهِ حَتَّى لاَ يَدْرِى كَمْ صَلَّى فَإِذَا وَجَدَ ذَلِكَ أَحَدُكُمْ فَلْيَسْجُدْ سَجْدَتَيْنِ وَهُوَ جَالِسٌ. قَالَ أَبُو عِيسَى هَذَا حَدِيثٌ حَسَنٌ صَحِيحٌ.
The Messenger of God, peace and blessings of God be upon him, said, "Indeed, Satan comes to anyone of you while in prayer, and causes you confusion until you do not know how much you have prayed [1]. So, if anyone of you finds this, then you should prostrate twice from the seated position."
[1] i.e. how many units of prayer.