Abu Saeed Khudri reported,

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, he should cast aside the doubt and build upon what he is certain of. Then let him perform two prostrations before giving the closing salutation. If he had actually prayed five units, these prostrations will make his prayer an even number for him, and if he had completed four units, the two prostrations will be a humiliation for Satan."

Muslim 1272

Sahih

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

عن أبي سعيد الخدري قال

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

مسلم 1272صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Muslim
Book
Mosques and places of prayer
Chapter
Forgetfulness in prayer and sujud for it
Numbering
Darussalam 1272
Muslim 1272