Sayyiduna Abdullah bin Mas'ud (may Allah be pleased with him) said: "Forgetfulness is when a person stands up where he should have sat, or sits where he should have stood, or gives the salam after two rak'ahs. In such a case he should complete his prayer, perform two prostrations while sitting, and recite the tashahhud in them."
Hadith Referenceالمعجم الكبير للطبراني / باب العين / 9332