Short answer
If you made an honest effort to find the qibla, by asking someone or using a compass or app, and later learn you were wrong, your prayer is valid and you do not repeat it. If you did not try at all and it turns out wrong, repeat it. A small deviation, within 45 degrees either side, still counts.
Facing the qibla is a condition of prayer. Someone who does not know the direction must try to find it (by asking or by effort, tahharri); if he prays after trying and later learns he was wrong, the prayer is valid. If he learns during the prayer he turns and continues. If he prayed without trying and it was wrong, or did not ask someone available, he repeats it.
Other madhhabs
- Shafi'i
- In the relied view, if you later become certain you were wrong, you must repeat the prayer even if you made an effort.
- Maliki
- If you made an effort and later learn you were clearly wrong, repeating the prayer within its time is recommended.
Explanation
Allah commands us to turn our faces toward the Sacred Mosque wherever we are. For those who cannot see the Kaaba, the duty is to face its direction, and the Hanafi school allows a margin: as long as part of your face is turned toward the qibla, roughly within 45 degrees either side, the prayer is valid.
- You tried and got it wrong: you asked a local, used a compass, an app or the sun, and prayed. Later you found it was wrong. Your prayer is valid; no need to repeat.
- You found out during the prayer: turn to the right direction and carry on. The people of Quba did exactly this when news came mid-prayer that the qibla had changed.
- You did not try: you just picked a direction without asking or checking. If it was right, the prayer counts; if it was wrong, repeat it.
- Someone nearby knew and you did not ask: repeat the prayer.
In a hotel, a friend's house or a new office, take a moment before praying. Our qibla finder shows the direction from your location. Phone compasses can be thrown off by metal and magnets nearby, so calibrate it or check against the sun if the result looks strange.
If you have been praying in a wrong direction at home for a long time without checking, speak to a local scholar about which prayers to repeat. For why Muslims face Makkah, see why Muslims face Makkah.
The evidence
Quran, Surah Al-Baqara 2:144
قَدْ نَرَىٰ تَقَلُّبَ وَجْهِكَ فِى ٱلسَّمَآءِ ۖ فَلَنُوَلِّيَنَّكَ قِبْلَةًۭ تَرْضَىٰهَا ۚ فَوَلِّ وَجْهَكَ شَطْرَ ٱلْمَسْجِدِ ٱلْحَرَامِ ۚ وَحَيْثُ مَا كُنتُمْ فَوَلُّوا۟ وُجُوهَكُمْ شَطْرَهُۥ ۗ وَإِنَّ ٱلَّذِينَ أُوتُوا۟ ٱلْكِتَٰبَ لَيَعْلَمُونَ أَنَّهُ ٱلْحَقُّ مِن رَّبِّهِمْ ۗ وَمَا ٱللَّهُ بِغَٰفِلٍ عَمَّا يَعْمَلُونَ ﴿١٤٤﴾
We have certainly seen the turning of your face, [O Muhammad], toward the heaven, and We will surely turn you to a qiblah with which you will be pleased. So turn your face toward al-Masjid al-Haram. And wherever you [believers] are, turn your faces toward it [in prayer]. Indeed, those who have been given the Scripture well know that it is the truth from their Lord. And Allah is not unaware of what they do.
Facing the qibla is commanded wherever you are.
Quran, Surah Al-Baqara 2:115
وَلِلَّهِ ٱلْمَشْرِقُ وَٱلْمَغْرِبُ ۚ فَأَيْنَمَا تُوَلُّوا۟ فَثَمَّ وَجْهُ ٱللَّهِ ۚ إِنَّ ٱللَّهَ وَٰسِعٌ عَلِيمٌۭ ﴿١١٥﴾
And to Allah belongs the east and the west. So wherever you [might] turn, there is the Face of Allah. Indeed, Allah is all-Encompassing and Knowing.
Allah accepts the one who does his best when the direction is unclear.
Sahih al-Bukhari 403
Sahih... بينا الناس بقباء في صلاة الصبح إذ جاءهم آت ...
"While the people were at Quba praying Fajr, someone came to them."
They turned toward the Kaaba mid-prayer and did not restart.
Where the ruling is recorded
- al-Hidaya, Kitab al-Salah, chapter on the conditions of prayer, facing the qibla. Whoever prays after effort and errs does not repeat; if he learns in prayer he turns.
- Radd al-Muhtar (Ibn Abidin), Chapter on facing the qibla. The margin within which one is still facing the direction of the qibla.
- Minhaj al-Talibin, Chapter on facing the qibla. The Shafi'i rule of repeating when certain of an error.
This answer is pending review by the scholars on our team. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.