Sayyidah Maymunah bint Sa'd (may Allah be pleased with her) said: O Messenger of Allah, give us a ruling about a man who becomes forgetful in his prayer and does not know how many units (rak'ahs) he has prayed. He (peace and blessings be upon him) said: "He should turn back, then stand in his prayer until he knows how many he has prayed, for that is only the whispering (of Satan) that comes to him and makes him forget his prayer."
Hadith Referenceالمعجم الكبير للطبراني / مسند النساء / 21530