Abu Saeed Khudri reported,

The Messenger of Allah ﷺ said, "When one of you is uncertain about his prayer, let him cast aside the doubt and build upon what he is certain of. Once he is sure he has completed it, let him perform two prostrations. If his prayer was already complete, the extra unit and the two prostrations count as a voluntary act, and if it was deficient, the unit completes his prayer and the two prostrations rub Satan's nose in the dust."

Abu Dawud 1024

Sahih

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

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

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

أبو داود 1024صحيح
Contents
Reference
Commentary
Ayat
Collection
Sunan Abu Dawud
Book
Prayer
Chapter
If uncertain between two and three, one who says to disregard the doubt
Numbering
Darussalam 1024
Abu Dawud 1024