I get confused a lot concerning how many rakats I perform, even though I pray in a loud voice in order to remember what I have recited. However, I still get doubts. When I finish the prayer, I feel that I have missed a rakah, prostration or sitting, even though I try very hard not have doubts during my prayer. But still this is without benefit. I hope you will guide me to what will benefit me in such a case. Do I have to repeat the prayer when I have such confusion? Is there some supplication that I can make at the beginning of the prayer that will remove such confusion?
You must fight against such devilish prompting and be cautious about them. You must increase your seeking of refuge in Allah from the accursed Satan. Allah has said,
“Say: I seek refuge with [Allah] the Lord of Mankind, the King of Mankind, the God of Mankind, from the evil of the whisperer who withdraws from his whispering…” to the end
of the surah (surah al-Nass).
Allah also says,
“And if an evil whisper comes to you from Satan, then seek refuge with Allah. Verily, He is All-Hearer, All Knower” (al-Araf 200).
If you have finished your prayer or ablution and then such doubts come to your mind, then turn away from them and don’t give them any attention. Consider your prayer and ablution as proper and sound. If doubts come to you while you are praying, such as whether you have prayed three or four rakats, then consider them as three and finish your prayer, making two prostrations of forgetfulness before the salutations at the end of the prayer. This is what the Prophet (peace be upon him) ordered one who had similar doubts to do. We seek refuge in Allah for ourselves and you from Satan.
Shaikh ibn Baz