The Prophet ﷺ said, "If one of you is uncertain during his prayer and does not know whether he has prayed three or four units, let him stand and pray one more unit." Yazid added, "So that the doubt becomes about having prayed extra." "Then let him perform two prostrations of forgetfulness. If he had prayed five, these two prostrations make his prayer an even number, and if he had prayed four, they humiliate Satan."
حدثنا يزيد وأبو النضر قالا أخبرنا عبد العزيز بن عبد الله بن أبي سلمة عن زيد بن أسلم عن عطاء بن يسار
عن النبي ﷺ قال إذا شك أحدكم في الصلاة فلم يدر ثلاثا صلى أم أربعا فليقم فليصل ركعة قال يزيد حتى يكون الشك في الزيادة ثم ليسجد سجدتي السهو فإن كان صلى خمسا شفعتا له صلاته وإن كان صلى أربعا فهما يرغمان الشيطان
Its isnad is sahih. Abu Nadr is Hashim bin Qasim, and Abdul-Aziz bin Abdullah is Majishun, the well-known Maliki jurist. The hadith has already appeared at 11721.