Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) said: "When a man has a doubt in his prayer and does not know whether he has prayed three rak'ahs or two, he should build upon what he is most certain of, then perform the two prostrations of forgetfulness (sajdah al-sahw)."
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 9329