What Should I Do If I am Not Sure If I Prayed 3 or 4 Rak’ahs?
Question

What should one do if one finds oneself unsure in the middle of the prayer how many raka’at one has prayed?
Praise be to Allah.If a person falls into doubt as to whether he prayed , e.g., three of four rak`ahs he should consider the most likely case. However, if he cannot put more weight to one of the two , he should assume what he is certain of and that is the lesser amount, and make the prostrations of forgetfulness (sujud al-sahw ). 
The evidence is the hadith narrated by Abu Sa‘id Al-Khudri (may Allah be pleased with him), who said: The Prophet (peace and blessings be upon him) said: If one of you has doubts during his prayer and he does not recall how many rak`ahs he has prayed, whether three or four, then he can put an end to his doubt by praying according to what he was certain of (the lesser amount) and then making two sujud before the salam. If it turns out that he had prayed five rak`ahs, the two sujud would make it even. Whereas if he ended up completing his four rak`ahs , they would be in defiance of the Satan.” (Sahih Muslim, No. 571)
Source: From The Book, What Should You Do In The Following Situations...?
And Allah knows best.