It is narrated from Ata bin Yasar (may Allah have mercy on him) that the Messenger of Allah (peace and blessings be upon him) said: "When any of you is in doubt about his prayer and does not know how much he has prayed, three rak'ahs or four, let him pray one rak'ah and perform two prostrations while sitting before giving the salam. If the rak'ah he prayed was the fifth, it will become even with these two prostrations; and if it was the fourth, these two prostrations will be a cause of humiliation and disgrace for Satan."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 3825