It wasnarrated that Abu Sa'eed Al-Khudri said:
"The Messenger ofAllah(ﷺ) said: 'If anyone of you is uncertain about his prayer, lethim put aside uncertainty and act upon that which is certain. When hehas made sure his prayer is complete, then let him prostrate twice.Then if his prayer was complete, that (extra) Rak'ah will becountedas voluntary, and if his prayer was lacking, that Rak'ahwill completehis prayer, and the two prostrations will rub theSatan's nose in thedust.'"
English reference: Vol. 1, Book 5, Hadith 1210
Arabic reference: Book 5, Hadith 1267