Today a phone works out the qibla from its position in a fraction of a second. For most of history the same question, which way is the Kaaba from here, had to be answered by watching the sky or by solving a problem in spherical trigonometry by hand. Both ways were used, side by side, for about a thousand years, and they did not always give the same answer.
Two traditions
The historian of science David A. King describes two separate traditions in the medieval sources (King, Islamic sacred geography). In the mathematical one, the longitudes and latitudes of a place and of Makkah are known, and a geometric or trigonometric procedure gives the direction. In the other, which he calls sacred geography, the world is divided into sectors around the Kaaba, each sector facing one part of the Kaaba’s walls, and the qibla in each sector is found from the rising and setting of the sun and of certain stars. Roughly, he writes, the folk texts aim to face the walls and corners of the Kaaba itself, and the scientific texts aim to face the distant city in which it stands.
The folk tradition came first, King argues, because it grew out of the pre-Islamic folk astronomy of Arabia, while the mathematical tradition was built on Greek, Indian and Iranian science (King, Islamic sacred geography). In a separate survey he adds that folk astronomy was far more influential in society, and that the problem of the orientation of mosques, long puzzling to historians, is now largely resolved thanks to newly found medieval texts (King, Science in the Service of Religion).
Facing a wall of the Kaaba
The sacred geography schemes start from the Kaaba itself. King notes that its rectangular base is astronomically aligned: its corners roughly face the cardinal directions, its main axis points towards the rising of Canopus, the brightest star in the southern sky, and its shorter axis towards sunrise at midsummer and sunset at midwinter, two directions that at the latitude of Makkah happen to be almost at right angles (King, Islamic sacred geography).
A person far away who knew which wall of the Kaaba his region faced could therefore turn towards it using the same horizon markers. King’s survey gathers instructions of exactly this kind, for example a text from around 1000 CE telling the people of the cities from Baghdad to Bukhara which stars should rise behind them, and over which shoulder the Pole Star should stand, to face the right section of the Kaaba.
He counts close to 20 different traditions in the sources he studied, dividing the world into anything from 4 to 72 sectors; the 72 sector schemes of the Ottoman period suited instruments whose scales ran round 360 degrees in steps of 5 (King, Islamic sacred geography). He stresses that this sacred geography is not a naive belief that the world is centred on the Kaaba, but a practical response to the duty of facing it from anywhere in the known world.
The problem in spherical trigonometry
The mathematical tradition treats the qibla as a problem on a sphere. Three points, the local place, Makkah and the North Pole, form a triangle on the globe, with sides and angles that ordinary flat geometry cannot handle. The qibla is the angle at the local place between north and the great circle, the shortest route over the globe, that runs to Makkah.
Astronomers in Baghdad were attacking it in the ninth century. Habash al-Hasib, active under the caliph al-Mamun (813 to 833) and later at Samarra, devised a graphical construction for the direction of Makkah, which al-Biruni later summarised; his astronomical handbook also contains auxiliary trigonometric tables that a modern biographer calls of singular importance in the history of trigonometry (Charette, Habash al-Hasib).
A trigonometric answer is only as good as the coordinates fed into it, and longitude was the hard part. Al-Biruni (born 973), whose book on determining the coordinates of places Yano dates to 1018, on his way from Khwarazm to Ghazna, used a lunar eclipse of 997 that he observed in Khwarazm, timed against an observation by Abu al-Wafa in Baghdad, to find the difference in longitude between the two cities (Yano, Biruni). He had little patience with the folk methods. In a passage King translates, al-Biruni complains that people asked about the qibla discussed winds and the rising points of the lunar mansions because the mathematics was beyond them, and allows only that the Pole Star gives a traveller an approximate direction (King, Islamic sacred geography).
Why a flat map gives the wrong answer
The drawing below shows the difference. On a flat map whose grid lines are evenly spaced in degrees, a straight line from New York to Makkah points east by south. The great circle, the route that is actually shortest, leaves New York heading north east and arcs over the North Atlantic. The site’s engine puts the qibla of New York at 58.5 degrees from north, over a distance of 10,306 km; from London it is 119.0 degrees over 4,794 km (calculated).
The qibla by great circle, and the straight line on a flat map calculated
| City | Qibla, degrees from north | Distance to the Kaaba | Flat map line | Flat map error |
|---|---|---|---|---|
| London | 119.0 (ESE) | 4,794 km | 127.0 | 8.0 degrees |
| Istanbul | 151.6 (SSE) | 2,407 km | 151.0 | 0.6 degrees |
| Cairo | 136.2 (SE) | 1,288 km | 135.2 | 1.0 degrees |
| Damascus | 164.6 (SSE) | 1,388 km | 163.7 | 0.9 degrees |
| Isfahan | 226.1 (SW) | 1,711 km | 226.5 | 0.5 degrees |
| Lahore | 260.3 (W) | 3,598 km | 253.6 | 6.7 degrees |
| Dhaka | 277.7 (W) | 5,173 km | 267.4 | 10.2 degrees |
| Kuala Lumpur | 292.5 (WNW) | 6,974 km | 286.5 | 6.1 degrees |
| Jakarta | 295.2 (WNW) | 7,920 km | 292.4 | 2.7 degrees |
| Lagos | 63.2 (ENE) | 4,253 km | 67.7 | 4.4 degrees |
| New York City | 58.5 (ENE) | 10,306 km | 99.6 | 41.1 degrees |
| Toronto | 54.6 (NE) | 10,496 km | 100.6 | 46.0 degrees |
| Sydney | 277.5 (W) | 13,236 km | 296.4 | 18.9 degrees |
The qibla and distance come from this site's engine, the same calculation the app uses, and every city page gives its own. The flat map line is the angle of a straight line drawn between the two points on a map whose grid squares are equal in degrees; it is shown only to explain why medieval astronomers needed spherical trigonometry.
The modern formula behind tables like these gives the qibla q from the local latitude φ, the latitude of Makkah φM and the difference in longitude ΔL as tan q = sin ΔL ÷ (cos φ × tan φM − sin φ × cos ΔL). King notes that al-Khalili’s rule for a closely related problem, finding the time from the sun’s altitude, is equivalent to the modern formula for it (King, Khalili).
A table for every place
The most remarkable result of the mathematical tradition is a table. Al-Khalili, a muwaqqit, or mosque timekeeper, at the Umayyad Mosque in Damascus around 1365, computed the qibla for every degree of latitude from 10 to 56, with one extra row for the latitude of Damascus, and every degree of longitude difference from 1 to 60: 2,880 entries, each to two sexagesimal places, most of them correct or within one or two minutes of arc (King, Khalili). Anyone who knew their coordinates could read off the qibla without doing the trigonometry. King notes that the table was not widely used by later astronomers. He adds that analysis by Glen Van Brummelen in 1991, and a further set of al-Khalili’s tables found in Bursa in 2000, settled the order in which his auxiliary tables were computed.
His colleague Ibn al-Shatir built the answer into an instrument: a small compendium, now in Aleppo, that could find the times of the midday and afternoon prayers and indicate the direction of Makkah (King, Ibn al-Shatir). Astrolabes too were used to find the qibla, as the History of Science Museum in Oxford notes of its collection (Museum of the History of Science, Faith).
The world maps centred on Makkah
The most famous qibla instruments are two metal world maps that came to light in 1989 and 1995, with a third identified later. They were studied by King in a book of 1999, reviewed by the historian of astronomy Benno van Dalen (van Dalen, Abstracta Iranica). Each is a map centred on Makkah, with more than a hundred places marked on a grid. A rule lets the user read both the qibla and the distance to Makkah for any of them. Van Dalen describes the metalwork as clearly Safavid, from Iran, and dates it to about 1700. On the grid the meridians are straight lines, while the lines of latitude, which are strictly ellipses, are drawn as arcs of circles.
King’s argument, as the review summarises it, is that the design fits well within the Islamic mathematical tradition and was within reach of astronomers such as Habash and al-Biruni centuries earlier, and that the coordinates engraved on the maps come from a geographical table of Timurid origin. The reviewer does not dispute them. One of the instruments keeps a European style compass and sundial (van Dalen, Abstracta Iranica).
Different methods, different directions
Because both traditions were in use for centuries, King writes, no one should be surprised that they give different results, and the consequences for the history of Islamic architecture were considerable (King, Islamic sacred geography). A mosque laid out by the rising of a star, or by the wall of the Kaaba its region was taught to face, can point in a different direction from the one a modern great circle calculation gives. This is one reason historic mosques do not all face the direction a modern calculation would.
The qibla on this site’s city pages and in the app is the great circle bearing to the Kaaba, computed from the city’s coordinates. The direction a local mosque faces may follow a different tradition, and this guide does not say which anyone should use.
Sources
Each source below is listed with the date it was read. Links in the text go to the page that supports the sentence. Figures marked calculated are worked out by this site's own code each time the site is built, from the rules the sources give.
- David A. King, Islamic sacred geography for finding the qibla by the sun and stars: a survey of the historical sources (Goethe University Frankfurt, 2019), author's text hosted by Muslim Heritage Read 3 December 2026.
- David A. King, "Science in the Service of Religion: The Case of Islam", Impact of Science on Society 40 no. 3 (UNESCO, 1990), pp. 245 to 262; extract republished with the author's permission by Muslim Heritage, 2021 Read 3 December 2026.
- François Charette, "Habash al-Hasib", in Thomas Hockey et al. (eds.), The Biographical Encyclopedia of Astronomers (Springer, 2007), pp. 455 to 457. Online at McGill University's Institute of Islamic Studies Read 3 December 2026.
- Michio Yano, "Biruni", in The Biographical Encyclopedia of Astronomers (Springer, 2007), pp. 131 to 133. Online at McGill University Read 3 December 2026.
- David A. King, "Khalili", in The Biographical Encyclopedia of Astronomers (Springer, 2007), pp. 625 to 626. Online at McGill University Read 3 December 2026.
- David A. King, "Ibn al-Shatir", in The Biographical Encyclopedia of Astronomers (Springer, 2007), pp. 569 to 570. Online at McGill University Read 3 December 2026.
- Benno van Dalen, review of David A. King, World-Maps for Finding the Direction and Distance to Mecca (Brill and Al-Furqan, 1999), Abstracta Iranica 24 (2003), OpenEdition Journals Read 3 December 2026.
- Museum of the History of Science, Oxford (now the History of Science Museum), The Astrolabe, East and West: Faith Read 3 December 2026.
This article is history, drawn from the academic and historical record and published by the makers of Prayer Times & Quran Plus. It is not religious guidance, and it does not rule between schools or traditions. Corrections are welcome at support.