Qibla Direction: How to Find the Direction of the Kaaba Accurately

What is the qibla?

The qibla is the direction a Muslim faces in prayer: the Kaaba in the Sacred Mosque at Makkah. Early Muslims first prayed toward the Farthest Mosque in Jerusalem, then were commanded to turn to the Kaaba in the second year of the Hijra: “We certainly see the turning of your face toward the heaven, and We will surely turn you to a qibla with which you will be pleased; so turn your face toward the Sacred Mosque” (Quran 2:144). From any point on Earth, the qibla is the direction of the shortest surface path from that point to the Kaaba, at latitude 21.4224779° N, longitude 39.8251832° E.

How is it computed? The great-circle equation

Because the Earth is a sphere, the shortest path between your city and the Kaaba is not the straight line you might draw on a flat map but a great-circle arc across the surface — the same routes airliners follow on long hauls. The qibla angle is computed by the standard spherical-trigonometry equation: with your latitude φ₁ and longitude λ₁, and the Kaaba’s φ₂ = 21.4224779° and λ₂ = 39.8251832°, the bearing B follows from:

Δλ = λ₂ − λ₁
B = atan2( sin Δλ · cos φ₂ , cos φ₁ · sin φ₂ − sin φ₁ · cos φ₂ · cos Δλ )
Qibla = ( B + 360° ) mod 360°

The result is the qibla angle: the bearing measured in degrees clockwise from true north. If your city’s qibla angle is, say, 118°, you face 118 degrees to the right of true north. This exact calculation is what the qibla direction tool on this site performs, along with the distance to the Kaaba in kilometers and miles along the same great circle.

True north vs magnetic north: a common trap

The computed qibla angle is measured from true north (Earth’s rotation axis), while your phone’s compass points to magnetic north. The gap between them — the magnetic declination — varies by location and drifts slowly over time, and it can be substantial: about 30 degrees in far-northern Canada, about 20 degrees in the opposite sense in the western United States, while negligible elsewhere. Each degree of error translates into a noticeable sideways miss over a distance as long as the path to the Kaaba.

Good phone compass apps compensate automatically using your location; with a simple magnetic compass you must add or subtract your city’s declination (by its east or west sign) from the qibla angle to get the correct compass bearing. Your location’s declination can be found from the global geomagnetic models of the Earth’s magnetic field.

Using your phone compass to find the qibla

For a tool-free check: twice each year — around late May and mid-July at noontime in Makkah — the Sun passes directly over the Kaaba; at that moment, a vertical stick’s shadow at any place whose noon coincides points exactly opposite the qibla.

A finer question: the general direction or the exact point?

The schools of fiqh agree that what is required of one far from Makkah is facing the general direction of the Kaaba, not its exact geometric point: whoever strives to determine the qibla and errs, the prayer is valid by the majority’s position, for direction is by ability. Still, the more precisely you know your city’s qibla angle, the more complete and safe your prayer is — which is the purpose of precise tools such as this site’s. Muslim astronomers of the classical age attended to this computation with great care; al-Biruni’s “al-Athar al-Baqiya” and the Andalusian and Maghribi treatises on the qibla’s azimuth stand among the earliest records of computing it on the globe with the deviations of cities from Makkah’s meridian.

Sources and references

Related articles

Frequently asked questions