Your Situation
You're mid-prayer and suddenly you're not sure whether that was your third rakah or your fourth, and you don't want to just guess.
What to know
The Prophet ﷺ gave a direct rule for exactly this: don't guess, and don't restart — go with the number you're certain of, finish the prayer from there, then add two extra prostrations before ending it.
What you can do
- Take the lower number you're sure of — if you're unsure between three and four, treat it as three.
- Complete the rest of the prayer as if that lower count were correct, praying the remaining rakah(s) normally.
- Before giving the final salam, perform two extra prostrations (sujood as-sahw) to make up for the uncertainty, then complete the prayer as usual.
- If you were actually already on the higher number, these two extra prostrations simply round your prayer to an even count — either way, nothing is lost.
- This applies to genuine uncertainty with no clear leaning either way. If you have a strong sense of which count is right (not just certainty, but a leaning), scholars generally say act on that instead.
This is specifically about doubt during the prayer itself. If you only realize afterward that you may have miscounted, that's a related but separate question — the Sujood as-Sahw guide covers the fuller set of after-the-fact scenarios in more depth.
Sources:
Sahih Muslim 571 (Abu Sa'id al-Khudri — cast aside the doubt, build on what you're certain of, then two prostrations before salam).
DeenGuide gives general, sourced guidance — it isn't a fatwa. For your specific personal situation, consult a qualified local scholar.