Sayyiduna Abu Sa'id Khudri (may Allah be pleased with him) narrates that the Prophet Muhammad (peace and blessings be upon him) said: "When a person has doubt about his prayer, he should put the doubt aside and base his action on what he is certain of. When he becomes certain that his prayer is complete, he should perform two prostrations of forgetfulness (sajda sahw). If his prayer was complete, then that extra rak'ah will be counted as a voluntary (nafl) prayer and the two prostrations will also be voluntary. And if his prayer was incomplete, then that rak'ah will complete his prayer and the two prostrations will humiliate the devil."
Hadith Referenceصحیح ابن حبان / كتاب الصلاة / 2667
Hadith Gradingفضيلة الشيخ الإمام محمد ناصر الدين الألبانيحسن صحيح - انظر (2654). تنبيه!! رقم (2654) = (2664) من «طبعة المؤسسة». - مدخل بيانات الشاملة -.فضيلة الشيخ العلّامة شُعيب الأرناؤوطإسناده قوي على شرط مسلم