Abu Saeed Khudri reported,

The Prophet ﷺ said, "When one of you is uncertain about his prayer, let him discard the doubt and build upon what he is certain of. Once he is sure he has completed it, let him perform two prostrations while seated. If he had prayed five units, these two prostrations make his prayer an even number, and if he had prayed four, they serve as a humiliation to Satan."

Nasai 1239

Sahih

أخبرنا يحيى بن حبيب بن عربي قال حدثنا خالد عن ابن عجلان عن زيد بن أسلم عن عطاء بن يسار

عن أبي سعيد

عن النبي ﷺ قال إذا شك أحدكم في صلاته فليلغ الشك وليبن على اليقين فإذا استيقن بالتمام فليسجد سجدتين وهو قاعد فإن كان صلى خمسا شفعتا له صلاته وإن صلى أربعا كانتا ترغيما للشيطان

النسائي 1239صحيح
Contents
Reference
Commentary
Ayat
Collection
Sunan Nasai Sughra
Book
Forgetfulness
Chapter
Completing the prayer based on what one remembers when in doubt
Numbering
Darussalam 1239
Nasai 1239