All perfect praise be to Allaah, The Lord of the worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
When one is doubtful regarding the number of Rak‘ahs he prayed during prayer, the Sharee‘ah ruling is that he has to consider the lesser number and then complete his prayer and prostrate again for the doubt. The Prophet, sallallaahu ‘alayhi wa sallam, said: "If one of you has doubts in his prayer and does not know how many (units) he prayed – whether it is three or four – then let him cast away the doubt and build upon what he is certain of. Then let him perform two Sajdahs ..." [Muslim]
Consequently, your action of considering the larger number is invalid, particularly because you became certain later. Meanwhile, scholars state that ending a prayer with Tasleem without being certain of its perfection nullifies prayer. Thus, you are required to make up for that prayer.