The Messenger of Allah ﷺ said, "When one of you is uncertain about his prayer and does not know how many units he has prayed, three or four, let him pray one more unit and perform two prostrations while seated before the closing salutation. If the unit he prayed was a fifth, these two prostrations will pair it, and if it was the fourth, the two prostrations will be a humiliation for Satan."
حدثنا القعنبي عن مالك عن زيد بن أسلم
أن رسول الله ﷺ قال إذا شك أحدكم في صلاته فلا يدري كم صلى ثلاثا أو أربعا فليصل ركعة وليسجد سجدتين وهو جالس قبل التسليم فإن كانت الركعة التي صلى خامسة شفعها بهاتين وإن كانت رابعة فالسجدتان ترغيم للشيطان
[Sahih] Bayhaqi related it, 2/338, from the hadith of Abu Dawud, by this route, and it is in the Muwatta (Yahya), 1/95, and Qanabi, p. 172. The chain is mursal, and it has corroborating narrations in Ibn Abdul-Barr, in Tamhid, 5/(20), and elsewhere. See the preceding hadith.