Yahya related to me from Malik from Zayd ibn Aslam from Ata ibnYasar that the Messenger of Allah, may Allah bless him and grant himpeace, said, "If you are uncertain in the prayer and do not knowwhether you have prayed three or four rakas, then pray a raka and maketwo prostrations from the sitting position before the taslim. If theraka that you prayed was the fifth, then you make it even by these twosajdas, and if it was the fourth, then the two prostrations spiteShaytan."
App reference: Book 3, Hadith 66
USC-MSA web (English) reference: Book 3, Hadith 66
Arabic reference: Book 3, Hadith 213