It is narrated from Hazrat Abu Hurairah (may Allah be pleased with him) that the Noble Prophet (peace and blessings be upon him) said: When any one of you is performing prayer, Satan comes to him and confuses him to the extent that he does not remember how many rak‘ahs he has performed. Whoever experiences such a situation should, when he sits in the final sitting (qa‘dah akheerah), perform two prostrations of forgetfulness (sajdah sahw).
Hadith Referenceمسند احمد / مسند المكثرين من الصحابة / 7822