Answer
(Fatwa: 799/799=M/1430)
If someone forgot the number of rak?ah whether he performed two or three rak?ah, if it happened him first time and he does not forget most of the time, he should revoke the salah and perform it anew. But if one generally forgets and falls in doubt, he should think over deeply and act according to what he finds more probable. If he is unable to judge the probability, he should perform the remaining salah according to lowest possibility. The detail is mentioned in Fatawa Hindiyah and other books of fatwas.
Allah (Subhana Wa Ta’ala) knows Best
Darul Ifta,
Darul Uloom Deoband