وَعَنْهُ أَيْضًا أَنَّ رَسُولَ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَآلِهِ وَسَلَّمَ قَالَ: ((إِذَا شَكَّ أَحَدُكُمْ فِي صَلَاتِهِ فَلَمْ يَدْرِكْ كَمْ صَلَّى فَلْيَبْنِ عَلَى الْيَقِينِ حَتَّى إِذَا اسْتَيْقَنَ أَنْ قَدْ أَتَمَّ فَلْيَسْجُدْ سَجْدَتَيْنِ قَبْلَ أَنْ يُسَلِّمَ، فَإِنَّهُ إِنْ كَانَتْ صَلَاتُهُ وَتْرًا صَارَتْ شَفْعًا وَإِنْ كَانَتْ شَفْعًا كَانَ ذَلِكَ تَرْغِيمًا لِلشَّيْطَانِ))
It is also narrated from Sayyiduna Abu Sa'id Khudri (may Allah be pleased with him) that the Messenger of Allah (peace and blessings be upon him) said: When any of you has doubt in prayer and does not know how much he has prayed, then he should base it on certainty (and perform an additional rak‘ah) until he is certain that the prayer is complete. Then, before the salam, he should perform two prostrations. If his (extra performed) prayer is odd-numbered, it will become even due to these two prostrations, and if his prayer is already even (i.e., complete), then these prostrations will humiliate Satan.