Reference
Magnetic interference and phone compasses
A magnetometer does not measure Earth’s field. It measures the sum of every magnetic field present, and Earth’s is one of the weakest things in a modern building. This is why a phone compass swings near steel, how much error a given stray field produces, and how far a compass can tell it is being lied to.
The field you are trying to measure is small
Total magnetic intensity at Earth’s surface runs from about 22,000 nT to 67,000 nT — 22 to 67 microtesla (British Geological Survey, An Overview of the Earth’s Magnetic Field). NXP’s application note AN4248 (first published by Freescale), a widely used reference for building a phone compass, gives the same bounds with locations: a minimum of 22 µT over South America and a maximum of 67 µT south of Australia.
Only part of that is useful. A compass works off the horizontal component H — the projection of the field onto the ground plane. At Casper, Wyoming on 21 September 2026 the World Magnetic Model 2025 gives a total field of 52,477 nT with a horizontal component of 19,593 nT and a vertical component of 48,682 nT (BGS geomagnetic model web service). The vertical component is 93% of the total magnitude; only the 19.6 µT horizontal part carries any information about which way you are facing. The declination calculator gives H and the vertical component for any place and date.
That 19.6 µT is what any nearby magnetised object has to compete with, and most of them win easily.
What the sensor actually sees
Magnetic fields superpose — they add as vectors, with no threshold. The reading is:
Bmeasured = W · (Bearth + Bexternal) + V
V is a fixed offset vector and W a 3×3 matrix, both attached to the phone; Bexternal, every field from outside the phone other than Earth’s, is not. The first two have standard names, which AN4248 uses:
- Hard iron — a field produced by something permanently magnetised, such as a speaker magnet or a magnetised screw. AN4248 models it as an additive vector
Vthat rotates with the circuit board, so in the phone’s own axes it is a constant offset. Any zero-field offset in the magnetometer itself adds to the same vector. - Soft iron — material that produces no field of its own but distorts the one passing through it; AN4248 describes these as fields induced by the geomagnetic field. Any ferromagnetic metal near the sensor, iron or nickel for example, does this, and how much depends on which way the material lies relative to the field. It scales the field rather than adding to it, which is why
Wis a matrix and subtraction alone cannot remove it. - External — everything not attached to the phone: rebar in a slab, a steel door frame, a vehicle body, mains wiring, a magnetic mount, the magnets in a case flap.
Calibration removes hard and soft iron, because they are fixed in the phone’s frame and can be learned; Android’s sensor specification requires the magnetometer readings an app receives to have online hard-iron calibration and factory or online soft-iron calibration applied. The external term cannot be calibrated away: it changes the moment you take a step.
How much error a stray field causes
If a stray field of magnitude Bs lies in the horizontal plane at right angles to the true field, the heading error is:
Δψ = arctan( Bs / H )
Using the Casper horizontal field of 19.593 µT:
| Stray field | Heading error |
|---|---|
| 1 µT | 2.9° |
| 5 µT | 14.3° |
| 20 µT | 45.6° |
| 50 µT | 68.6° |
A stray field one twentieth the strength of Earth’s horizontal field already costs three degrees. That is why a compass reading to a tenth of a degree can be forty degrees wrong and give no sign of it. At right angles to the true field is not quite the worst direction: the worst is at right angles to the resulting field, which gives arcsin(Bs / H) — 14.8° for the 5 µT case — and once Bs reaches H the needle can be pushed to any heading at all.
Distance is the remedy. A magnetised object behaves as a magnetic dipole at any distance large compared to the object, and a dipole field falls as 1 / r³. Doubling your distance from the source divides its contribution by eight; tripling it divides by twenty-seven. No amount of filtering removes a steady stray field; distance does.
Stray-field calculator
Heading error for any stray field and location, what the two field checks described below would see, and how much further away you would need to be.
What it assumes. The defaults are Casper on 21 September 2026; the declination calculator gives H and Z in nanotesla, so divide by 1,000. The stray field is taken as horizontal and uniform across the phone, and the phone’s own hard and soft iron as already calibrated out. The distance figure assumes the source behaves as a dipole, which is only true once you are several times its size away from it; close to a car or a steel beam the field does not follow 1 / r³.
Detecting interference without knowing the answer
A compass cannot check its own bearing — that is the quantity it is trying to find. But interference can break two other quantities the World Magnetic Model already predicts, and neither of them depends on which way the phone is pointing.
Check one: field magnitude. The model gives total intensity F at your position and date. The magnitude of the measured vector should equal it, whatever the orientation:
|Bmeasured| = √(Bx² + By² + Bz²) → compare with F
At Casper that is 52.5 µT. A reading of 80 µT or 15 µT is not a heading error to be averaged out, it is proof that something else is in the measurement.
Check two: dip angle. AN4248 writes the reference field in the North-East-Down frame as B(cos δ, 0, sin δ), where δ is the inclination — the angle the field makes below horizontal. So the component of the field along the direction of gravity, which the accelerometer supplies independently, must satisfy:
sin(Imeasured) = (B · ĝ) / |B|
where ĝ is the unit vector pointing down. At Casper the model gives I = 68.077°; at Singapore it gives −12.752°. A measured dip angle several degrees away from the model value means the field vector has been tilted by something local.
Both checks can fail while the needle still looks perfectly steady, which is exactly what makes them worth running: a steady wrong reading is the dangerous case.
What the checks miss. Neither check is complete. A stray field that lies along Earth’s field changes the magnitude directly, but one at right angles to it changes the magnitude only through its square — and a horizontal field at right angles to H is exactly the one that does the most damage to the heading. At Casper, 5 µT of it turns the heading 14.3° while changing the total field by 0.45% and the dip by 0.63°. At 20 µT the heading is 45.6° out, the total field is up 7.0% and the dip is down 8.0°. A threshold of a few percent or a few degrees catches the second case and misses the first. Passing the checks means no large interference, not no interference.
The sensor can also simply run out of range
A smartphone magnetometer, the AKM AK09918, has 16-bit output at a typical sensitivity of 0.15 µT per count and a typical measurement range of ±4912 µT (AKM AK09918 datasheet, 016014242-E-00). That is about 94 times the 52.5 µT total field at Casper, which sounds generous until a strong permanent magnet is brought close to the sensor. The datasheet is specific about the limit: once |X| + |Y| + |Z| reaches 4912 µT the chip flags a magnetic sensor overflow and the data are not correct.
Turn the resolution figure around: at the Casper horizontal field of 19.593 µT, one count of 0.15 µT is arctan(0.15 / 19.593) = 0.44° of heading. That is the quantisation floor of a single sample before any noise, and the reason heading is averaged over many samples rather than read once.
Two sources of error that are not local
Crustal rock. The World Magnetic Model excludes the effects of Earth’s crust and upper mantle, ionosphere and magnetosphere. NCEI reports local crustal anomalies that can exceed 10°, with three or four degrees not uncommon, and cites a mapped area in Minnesota at 16° east declination with anomalies a few miles away at 12° west. Moving the phone a few metres will not help, because the anomaly comes from the ground itself, not from anything near you.
Space weather. Currents in the ionosphere and magnetosphere add a time-varying field the model does not include. NOAA’s Space Weather Prediction Center measures this with the K-index — derived from the maximum fluctuation of the horizontal field components seen on a magnetometer during a three-hour interval, on a 0–9 scale where 5 or more indicates a geomagnetic storm. SWPC’s conversion table for the Boulder magnetometer puts K = 5 at 70–120 nT and K = 9 at more than 500 nT.
The K-index measures the size of the swing, not its direction, and SWPC defines the fluctuation as the largest positive and largest negative deviations in the three hours added together. Treating the whole of it as a field at right angles to H therefore gives the most it could cost. Run those through the same arctan(Bs / H):
| Disturbance (Boulder scale) | At Casper (H = 19,593 nT) | At Resolute (H = 3,361 nT) |
|---|---|---|
| 120 nT (top of K = 5) | 0.35° | 2.04° |
| 500 nT (K = 9) | 1.46° | 8.46° |
The same absolute disturbance is divided by a much smaller horizontal field at high latitude, so a 500 nT swing is worth up to about a degree and a half in Wyoming and eight and a half degrees in the high Arctic. The Arctic row still uses Boulder’s scale, and that understates a storm there: SWPC notes that observatories at higher geomagnetic latitude need larger fluctuations for a given K, so that each level occurs about as often everywhere.
What to do about it
Move, then re-check. A dipole’s field falls as the cube of distance, so once you are several times an object’s size away from it, every doubling of the distance cuts its contribution by a factor of eight. Beside a vehicle, a doorway or a machine you are not that far away, the object does not act as a dipole and no simple law applies, so move well clear rather than a step. Calibrating next to the source does not fix it. A field fixed to the room is not fixed to the phone, so turning the phone in place makes it look like part of Earth’s field: the calibration can converge, report high accuracy, and the heading is still wrong. Where the stray field changes over the few centimetres the phone moves during a figure-eight, it also corrupts the fit itself. Calibrate away from steel.
Bearing runs the first check. About twice a second it compares the measured field strength with the value Android’s built-in geomagnetic model gives for your position, shows both on screen, and puts up a warning when they differ by more than 18%, clearing it once they are back within 13%; without a location fix it warns outside 20–70 µT. It does not run the dip check, and a sideways stray field changes the magnitude little: the 20 µT case above, 45.6° of heading error, moves it only 7%, inside that threshold. The compass works offline, and its one banner ad is removable with a $2.99 one-time purchase.
Related: magnetic declination and true north and how a phone derives a heading from its sensors.