Sayyiduna Abu Sa'id al-Khudri (may Allah be pleased with him) said that the Messenger of Allah (peace and blessings be upon him) said: "When someone has a doubt in his prayer as to whether he has prayed three rak'ahs or four, let him discard the doubt, act upon what he is certain of, and perform two prostrations while sitting before giving the salam. If he has prayed five, the two prostrations will make it even, and if he had prayed the full four, then these (two prostrations) will be a humiliation for Satan."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3800