
How Qibla Direction Is Calculated: Great Circles and True North
Calculate the qibla from latitude and longitude, follow a worked New York example, and convert a true bearing for use with a magnetic compass.
In the New York example below, the qibla is 58.48° clockwise from true north on a spherical Earth. The same two points joined by a straight line on a Mercator map give a bearing of 101.28°. Both numbers can be reproduced from the coordinates. They measure the directions of two different routes. A magnetic compass introduces another distinction: its zero is local magnetic north, so the number on its dial may differ from the true bearing.
What the initial qibla bearing measures
The qibla is the direction Muslims face in prayer toward the Kaaba, in the Grand Mosque in Makkah. A geographic calculator takes the coordinates of the place where you are standing and those of the Kaaba. On a spherical Earth, it joins them with the shorter arc of a great circle, a circle whose plane passes through Earth’s center. The qibla bearing is the direction in which that arc leaves your location.
At your location, true north follows the meridian toward the geographic North Pole. Bearings are measured clockwise from that direction: 0° is north, 90° east, 180° south and 270° west. Picture a local compass rose placed flat against a globe. The outgoing arc crosses that rose at a particular angle. Move the rose along the route and the angle can change because the local north line has changed. For prayer at the starting point, you need the first angle only.
A prayer space may mark its established direction on a wall or with a mihrab. The guide to mosque architecture shows where these features fit in a building. A map calculation gives a geographic reference when you need to locate that direction yourself.
The spherical calculation
Let φ₁ and λ₁ be the latitude and longitude of your position, and φ₂ and λ₂ those of the Kaaba. Take east longitude and north latitude as positive, west and south as negative. Convert the four inputs from degrees to radians before using the trigonometric functions. Set Δλ = λ₂ − λ₁. The two terms used for the bearing are the east and north components of the outgoing direction, up to a common scale.
- East term:
y = sin(Δλ) × cos(φ₂). - North term:
x = cos(φ₁) × sin(φ₂) − sin(φ₁) × cos(φ₂) × cos(Δλ). - Initial bearing:
atan2(y, x). Convert its result to degrees and reduce it to the range 0° to less than 360°. A result of −30°, for example, becomes 330°.
Use the two-argument arctangent in your calculator or programming language and check its argument order. With only the ratio y / x, you lose the signs that tell you which quadrant contains the destination. An east term above zero and a north term below zero, for example, place the initial direction somewhere between east and south. At the exact antipode of the Kaaba there are several equally short great-circle routes and the spherical formula cannot choose a unique bearing. The bearing is also undefined if the two input points coincide.
A worked example from New York to the Kaaba
Use 40.7128° N and 74.0060° W as a representative starting point in central New York City. Use 21.4224779° N and 39.8251832° E for the Kaaba, the coordinates published in Google’s Qibla Finder documentation. The longitude difference is 113.8311832° east. After converting the angles to radians, the east term is approximately 0.851543 and the north term approximately 0.522186. Evaluating the formula with the unrounded terms gives 58.4824°, or 58.48° at two decimal places. That is between north and east.
The same coordinates put Makkah at a lower latitude than New York, so it can seem natural to expect an initial direction south of east. On a globe, the short arc starts north of east before curving back toward lower latitudes. An initial bearing is a local direction at one endpoint. Comparing the two latitudes alone gives no way to determine that angle.
Some calculators model Earth as the slightly flattened WGS 84 ellipsoid. The shortest path on that surface is a geodesic. Give an inverse geodesic calculator both endpoints and read the forward azimuth at the first point. The WGS 84 calculation for these inputs gives 58.40°, about 0.09° away from the spherical bearing before rounding. A city-center example helps compare the models. For your own reading, enter the position where you will use the direction.
Why a straight line on a map can give a different answer
Projection turns the curved surface of Earth into a flat map. In the standard Mercator projection, a straight segment crosses each meridian at a constant angle. It represents a rhumb line, a route you can follow by maintaining the same true heading. A great-circle route can look curved on the same map because its angle to the meridians changes. The USGS comparison of projections identifies the gnomonic projection as one that represents great circles as straight lines.
Using the example coordinates in a spherical Mercator projection gives a straight-line bearing of 101.28°, slightly south of east. You can reproduce it from the map geometry by using atan2 of the longitude difference and the difference in projected northings. For a unit sphere the northing at latitude φ is ln(tan(π/4 + φ/2)). Subtract the starting northing from the destination northing, just as with longitude. The result angles down on a north-up Mercator map because the destination has a lower latitude.
A map tool that draws a geodesic between two points can still use a Mercator base map. The feature that matters is how the tool computes the line. To use a printed map as a check, establish where true north is at the starting point and identify the curve or the local bearing the map represents. If the map shows grid north or has been rotated, determine the north reference before comparing angles.
How to convert true north to a magnetic compass reading
A hand compass aligns with the horizontal component of the local magnetic field. Its north direction can lie east or west of true north. NOAA calls that angle magnetic declination and assigns a positive value east of true north and a negative value west of it. Declination changes with location and time. Use an estimate for the actual place and date from a source such as the World Magnetic Model.
Under NOAA’s convention, true bearing = magnetic bearing + signed declination. To find the number to use on a magnetic compass, subtract the signed declination from the true bearing. With a true bearing of 58.48° and a hypothetical declination of 10° west (−10°), the magnetic bearing would be 68.48°. The −10° in this example illustrates the sign convention. Look up the value for your own location and date before applying the formula.
Check the device’s north setting before making a correction. If the heading is already expressed relative to true north, compare it directly with the calculated true bearing. A magnetic case, a steel desk or a parked vehicle can disturb the compass independently of regional magnetic declination. The geological model gives a reference for the background field, so moving the device away from nearby sources of interference is a separate step.
How earlier calculators and instruments found the direction
The historian David A. King documents both mathematical and observational approaches to the qibla. Some communities related the direction to the cardinal points or to where particular celestial bodies rose or set. Mathematical sources approached it through the position of a locality relative to Makkah. A diagram, a table and a locally established direction therefore offer different kinds of historical evidence, even if each addresses where to face.
Ahmad S. Dallal’s edition of an early eleventh-century treatise by Ibn al-Haytham describes a spherical trigonometric solution intended to work for any locality with known coordinates. This establishes that mathematicians could express the problem on a sphere centuries before digital maps. A modern formula makes the procedure reproducible with new coordinates. The surviving treatise tells us how a particular mathematician framed and solved it. The guide to medieval astronomical tables shows what it takes to read a historical numerical source.
A different example is the British Museum’s ivory compass, sundial and qibla indicator 1921,0625.1, dated 1582–83. Its center shows the Kaaba and a compass sits inside the circular case. The outer rim groups city and region names in 72 sectors, and the angle of the string that casts the sundial’s shadow corresponds to latitude 41° N, consistent with Istanbul. The engraved scale and the shadow-setting give an idea of the geographic knowledge built into an instrument. For comparison, see the guide to historical qibla indicators and the guide to the working parts of an astrolabe.
How to check two readings that disagree
- Compare location inputs. Get the numeric bearing from the qibla finder and note the location used. Check the latitude and longitude signs, especially if you entered the coordinates yourself or used a nearby city as a proxy.
- Compare like with like. Check whether each number refers to true north or magnetic north and whether the map line follows a geodesic. Keep the same point on the map while changing settings so you can see what caused the difference.
- Check the physical direction separately. Standing in an open place, compare the heading away from metal and magnetic accessories with a known true-north reference or with landmarks plotted on a properly oriented map. Follow the phone’s instructions if it reports a calibration issue.
If you are at an established prayer space and have questions about the direction marked there, ask the local mosque how it was set. You can look up local prayer times separately using the same location.
Sources
- Google Help, Qibla Finder method and Kaaba coordinates
- NOAA NCEI, magnetic declination and bearing conversion
- NOAA NCEI, World Magnetic Model
- U.S. Geological Survey, map projection properties
- National Geospatial-Intelligence Agency, WGS 84 reference frame
- Charles F. F. Karney, algorithms for ellipsoidal geodesics
- British Museum, compass, sundial and qibla indicator 1921,0625.1
- David A. King, astronomy and Islamic cartography
- Ahmad S. Dallal, edition and study of Ibn al-Haytham’s qibla treatise





