
When a Qibla app shows you a number like 136 degrees, you are looking at the result of a spherical trigonometry formula that Muslim scholars developed centuries before the digital compass existed. When you rotate the phone and watch the arrow shake, you are looking at a completely different problem: sensors. Understanding the difference is what lets you trust your direction, or rightly doubt it.
The Qibla lies on a sphere, not on paper
The most common mistake is to look at a flat map and draw a straight line to Mecca. Flat maps, Mercator above all, distort direction increasingly as you move away from the equator. The earth is close to a sphere, and the shortest path between two points on it is an arc of a great circle, the circle whose plane passes through the earth's centre.
The result is counterintuitive but correct: from North American cities the Qibla points north east, not south east, even though Mecca looks lower and to the right on a map. The shortest path runs near the pole rather than horizontally across the Atlantic. Aircraft follow the same logic, which is why the route on the cabin screen looks curved.
The formula itself
The Kaaba coordinates used in the calculation are 21.4225 north and 39.8262 east. If your position is at latitude φ1 and longitude λ1, and the Kaaba is at φ2 and λ2, then with Δλ = λ2 - λ1 the bearing is:
- Numerator: sin(Δλ) × cos(φ2)
- Denominator: cos(φ1) × sin(φ2) - sin(φ1) × cos(φ2) × cos(Δλ)
- Bearing = atan2(numerator, denominator), converted from radians to degrees and normalised into the range 0 to 360.
The result is an angle measured clockwise from true north. Zero is north, 90 east, 180 south, 270 west. The Qibla direction page runs this formula in your browser and also shows the great circle distance to Mecca.
One important detail: the formula gives the initial bearing, not a constant heading for the whole path. Along a great circle the bearing changes as you travel, but that is irrelevant for prayer, since you are standing still.
True north versus magnetic north
This is where the biggest practical error occurs. The calculation gives an angle from true north, toward the geographic pole. A compass needle, or your phone's magnetometer, points at the magnetic pole, a different location that drifts every year.
The gap is called magnetic declination, and it varies entirely by location:
- In Cairo, Riyadh and Dubai it is around 4 degrees or less, a minor effect.
- In western Europe and eastern North America it can reach 10 to 15 degrees, clearly enough to skew a prayer row.
- Near the poles, relying on a compass becomes practically meaningless.
A serious app either corrects for declination automatically or tells you plainly that it is showing a magnetic bearing. If you use a traditional compass, you must add or subtract your local declination yourself.
Why the arrow jitters on a phone
A phone magnetometer is cheap and sensitive, and everyday objects disturb it:
- Steel in the building frame and reinforced concrete columns.
- Speakers, chargers, magnetic cases and cars.
- Computers, refrigerators and anything containing a motor or magnet.
That is why the raw reading is processed before display: circular smoothing of the angle avoids the jump between 359 and 0, and updates are synchronised with the animation frame rather than every raw sample. The result is a steady arrow instead of a trembling one. The sensor is still a sensor, so:
- Move away from metal walls and appliances.
- Calibrate by moving the phone in a figure of eight two or three times.
- Hold the phone flat and level; tilt corrupts the reading.
- Verify the result independently, as follows.
Verify your Qibla with the sun and no device
This method uses no sensor at all, and it is the most accurate way to fix a permanent prayer spot at home:
Method one, the noon shadow. At local solar noon, listed on the prayer times page, stand a straight stick on level ground. Its shadow at that instant lies exactly on the true north to south line. From that line, measure your calculated Qibla angle with a simple protractor. Magnetic declination plays no part whatsoever.
Method two, the sun directly over the Kaaba. Twice a year the sun stands exactly above the Kaaba: around 27 and 28 May near 12:18 Mecca time, and around 15 and 16 July near 12:27. At that moment, anyone who can see the sun faces the Qibla by facing the sun, and the shadow of any upright pole points exactly away from it. Mark the line on your floor in that minute and keep it.
Practical questions
Must I hit the exact degree? For those far from Mecca, facing the general direction is what is required, and a slight deviation is excused. Even so, a 15 degree error caused by ignoring declination is worth correcting, especially in a fixed prayer space.
Why do two apps show different numbers? Usually because one shows a true bearing and the other a magnetic one, or because their location accuracy differs. Compare them once you know your city's declination.
Does the Qibla change within one city? In practice, no. Across a large city the difference is under half a degree.
Can I compute the Qibla programmatically? Yes, the calculation is available as a documented public API on the developers page.
Summary
The Qibla is a precise number derived from a simple, stable spherical trigonometry formula. Errors do not come from the formula but from how north is measured on the ground. Read your bearing on the Qibla page, fix it once with a noon shadow in your prayer space, and you will never need a compass again. To align time with direction, see the guide on prayer time calculation methods.
Data sources
- Adopted Kaaba coordinates: 21.4225 north, 39.8262 east
- Spherical trigonometry: the initial bearing formula on a great circle
- World Magnetic Model (WMM) for magnetic declination values
- Astronomical computation of solar zenith over the Kaaba in Mecca time
Last updated: 6 Sept 2026