Q: If one is doubtful in Salaah - as to whether one is in the third or fourth Rakaat, what should one do?
A: If doubt has occured for the first time ever in Salaah; then one should repeat the Salaah.
If doubt occurs often; one should apply prudent judgment and practise on that which one’s mind is inclined to. For examle, if you strongly feel that you in the fourth Rakaat - then practice on that.
Furthermore, after applying prudent judgment if doubt still remains, then practice on the lesser of the two amounts; in this case that will be three rakaats.
When acting on the lesser number, one should sit for Tashahhud after each Rakaat and make Sajdah Sahu at the end.