Why do I get bad thoughts during prayer?

No, bad thoughts during prayer don't mean your faith is weak. They are usually whispers (waswas) from Satan, mixed with an active, tired or stressed mind that fills the quiet when you stand still. You are not blamed for thoughts you don't choose, and you don't need to stop or repeat your prayer.
Why they appear in prayer
Prayer is the moment you turn away from the world to face Allah, so it is no surprise that distractions rush in. A Companion, Uthman ibn Abi al-As, once told the Prophet ﷺ that Satan was coming between him and his prayer and his recitation and confusing him. The Prophet ﷺ said it was a devil called Khinzab, and taught him what to do (Sahih Muslim 2203). So this problem is as old as the prayer itself.
Allah teaches us to seek refuge from this exact thing:
You are not blamed for unwanted thoughts
The Prophet ﷺ said that Allah has forgiven his community the evil thoughts that arise in their hearts, as long as they do not speak about them or act on them (Sahih Muslim 127). Some Companions even came to him and said they found thoughts in their minds that were too terrible to say out loud. He asked whether they truly felt this, and when they said yes, he told them it is manifest faith (Sahih Muslim 132). In other words, your horror at the thought shows your faith is alive.
What to do while you're praying
- Keep praying. The thought does not break your prayer or your wudu.
- Don't argue with it. Debating a thought feeds it. Notice it, and move on.
- Seek refuge quietly. Say "A'udhu billahi minash-shaytanir-rajim" in your heart or under your breath. This is what the Prophet ﷺ told Uthman to do, along with a light spit to the left (Sahih Muslim 2203). Ask your imam how to apply the spitting part in a mosque or workplace.
- Return to the words. Go back to the verse or phrase you were saying, and say it slowly.
What to do afterwards
Don't keep checking whether your prayer "counted". If you did the pillars, it did. Repeating prayers because of thoughts usually makes them stronger. If the thoughts are about doubts that make you repeat acts, see What is waswas and how do I deal with it? For disturbing or blasphemous thoughts in general, see Will Allah punish me for my intrusive thoughts?
When to get extra help
If the thoughts are frequent, frightening, or make you dread praying, they may be part of anxiety or obsessive-compulsive disorder, which is common and treatable. Speaking to a doctor or therapist is not a sign of weak faith. Looking after your mind is part of looking after the trust Allah has given you. You can also talk to a trusted imam or teacher, who has probably heard it before.
If your mind is simply busy, the practical tips in How can I stop my mind wandering during prayer? will help.
- Bad thoughts in prayer are common and are not a sign of weak faith.
- Allah doesn't hold you to thoughts you don't speak or act on.
- Keep praying, seek refuge, and don't argue with the thought.
- Frequent, distressing thoughts deserve help from a doctor or therapist.
People also ask
Why do Muslims raise their hands before praying?
Muslims raise their hands with the opening "Allahu akbar" because the Prophet did, to mark starting the prayer. Learn how high and when to raise again.
Read the full answer →Why do Muslims bow and prostrate during prayer?
Muslims bow and prostrate to show humility before Allah alone, not a person, statue or the Kaaba. Prostration is the moment of greatest closeness to Him.
Read the full answer →Which prayer time calculation method should I use?
Use the method your local mosque follows. MWL, ISNA and Umm al-Qura differ mainly in the Fajr and Isha angles, and each is a reasonable choice.
Read the full answer →Which prayer should I start with as a beginner?
Mostly, start with the prayer whose time has arrived, then add the rest. A realistic learning order for beginners so you reach all five prayers in weeks.
Read the full answer →Where do I put my hands during prayer?
It depends on your school: most Muslims fold the right hand over the left, below the navel or on the chest. Some Malikis keep their arms at their sides.
Read the full answer →