The Messenger of Allah ﷺ said, "If one of you is uncertain during his prayer and does not know how much he has prayed, whether three or four, let him pray one rakat and then perform two prostrations while seated, before giving the greeting of peace. If the rakat he prayed turns out to be a fifth, these two prostrations make it an even number, and if it was the fourth, then the two prostrations are a humiliation for Satan."
حدثني يحيى عن مالك عن زيد بن أسلم
أن رسول الله ﷺ قال إذا شك أحدكم في صلاته فلم يدر كم صلى أثلاثا أم أربعا فليصلي ركعة وليسجد سجدتين وهو جالس قبل التسليم فإن كانت الركعة التي صلى خامسة شفعها بهاتين السجدتين وإن كانت رابعة فالسجدتان ترغيم للشيطان