If you thought that you have added a rak’ah while praying as in the case if you were standing and you remembered that this is the 5th Rak’sh, you should immediately sit down and offer the tashahud and then offer salam and then offer two prostrations and then offer salam again. In the case where you think that you have missed a rak’ah, you should pray that Rak’ah and then do the same as the above.
And Allah knows best