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."