Bubble Level

Your phone, set down, tells you what is level.

  • Uses the phone sensor
  • Angle and slope
  • Two-way calibration
A white spirit level with a round glass vial at its center rests on a pale wooden shelf beside a pencil and a yellow tape measure, with workshop tools blurred behind.

The guide

A phone can find level, but only after it admits which way it leans

A bubble climbs to the top of a curved vial without being asked. A phone computes the same answer from a sensor with a bias, and one half turn on the same spot is what makes that answer honest.

  • 1661 year by which Thévenot had described his spirit level to Huygens
  • 0.58 degrees tilt inside one step of a gravity reading rounded to 0.1 m/s2
  • 0.82 degrees tilt that a 14.3 mg zero offset mimics, the average in a phone survey
  • 1:48 ADA cross slope limit, the same as a quarter inch per foot
  • 63.2 percent of a sudden change shown after one time constant of smoothing
Read the full guide Fold the guide 9 min · 19 sources

A spirit level is one of the few instruments that explains itself. A bubble sits between two lines, or it does not. Nobody has to be taught to read one.

The phone in a pocket can answer the same question, and it carries no bubble at all. It carries a chip that feels the pull of the Earth, a browser that passes three numbers along, and software that turns them into an angle. Every link in that chain bends the answer a little.

That does not make a phone a bad level. It makes it a level that has to be questioned before it is believed. The best question was already being asked of glass vials three centuries ago: turn the thing around, and see whether it still says the same.

A bubble that climbs to the top

The instrument is credited to Melchisédech Thévenot, a French scientist, who invented it some time before February 2, 1661. The date is known from his correspondence with Christiaan Huygens, and within a year he had sent details to Robert Hooke in London and Vincenzo Viviani in Florence. The idea travelled quickly because there is so little to it: a sealed glass vial, a liquid that does not quite fill it, and the bubble that is left over.

The bubble rises for the reason a cork does. Archimedes’ principle says that a body in a fluid is pushed up with a force equal to the weight of fluid it displaces, and a pocket of vapor weighs almost nothing beside the liquid it pushes aside. So the liquid sinks, the bubble is squeezed upward, and it stops at the highest point it can reach. In a perfectly straight tube, held level, no point would be highest. Early vials were therefore very slightly curved, and where a level must also work upside down the curved tube gives way to a barrel-shaped bore. Either way the highest point is a single place that travels along the glass as the tube tilts.

The filling is an alcohol, not water. Alcohols have low viscosity and surface tension, so the bubble moves quickly and settles accurately, and they stay liquid over a far wider range of temperature, where freezing water could crack the vial. A dye such as fluorescein, usually yellow or green, makes the bubble easier to see. How far the bubble moves for a given tilt is the level’s sensitivity, stated as the change of angle needed to move it a unit distance. On a surveyor’s level the bubble travels 2 mm when the vial is tilted by about 0.005 degree.

Vials come in two shapes. A tube shows the tilt along its own length and nothing else. A bull’s eye level, a round vial under slightly convex glass with a circle at its center, levels a whole surface at once. A phone can play both parts: lying flat it reads two directions, and standing on an edge it reads one.

How a phone knows which way is down

Inside the phone is an accelerometer cut into silicon. A tiny proof mass hangs on restoring springs, and its movement is read as a change in capacitance between fingers on the mass and fixed sensing plates. Such a sensor answers to the linear acceleration of the device and to the local gravitational field alike. With no linear acceleration, its output is the gravity vector as seen from the tilted chip, which is why a phone resting on a table reports a magnitude of about 9.81 meters per second squared without moving at all.

A web page receives that vector through the devicemotion event, in a property with the misleading name accelerationIncludingGravity. The specification fixes the axes to the device: x toward the right of the screen, y toward its top, z out of the glass. A phone lying flat with its screen up reports zero, zero and 9.8, so the vector points away from the ground. The tilt of each axis is then the arcsine of its share of the whole.

Two limits come with the physics. An accelerometer is insensitive to rotation about the gravity vector, so no level can say which way it faces. And it cannot tell gravity from being pushed. A phone in a moving hand reads its own motion as tilt, and the number means something only when the device is at rest.

Two more come with the browser. On some browsers motion data sits behind a permission, requested by a method that answers only to a press. And the specification has browsers limit the precision of acceleration to 0.1 meters per second squared and of orientation angles to 0.1 degree. The source code of one widely used browser engine sets those rounding steps, with the reason in a comment: sensors are accurate enough that sampling them can reveal a device’s calibration data. Near level, one step of 0.1 in a reading of 9.8 is a tilt of 0.58 degrees. A level that reads the rounded vector moves in steps of that size, so a careful page also watches the finer orientation angles.

Bias, and the half turn that cancels it

No accelerometer reads zero when it should. One survey gathered more than 500 measurements from 116 phones lying face down on leveled surfaces. The zero offset on one in-plane axis averaged 14.3 mg, a mg being a thousandth of standard gravity. On an axis that ought to read nothing, 14.3 mg looks exactly like a tilt of 0.82 degrees. The 90th percentile was 30.1 mg and the largest value 90.9 mg.

The authors add that an application reads the phone’s own output and not the chip directly, so a chip maker’s data sheet cannot supply these figures. The chip, in turn, sits on a circuit board that can be mounted at any angle inside the finished product.

Spirit levels have the same disease, and the cure is the oldest trick in the trade. Set the level on a flat, roughly level surface and note the bubble. Turn it through 180 degrees in the horizontal plane and look again. An accurate level shows the same thing both times. A difference means the vial is not true to its body, and the remedy is to shift the vial by about half the discrepancy.

Metrologists call the family of such methods reversal: ways of measuring accurately without reference to an externally calibrated artifact. The arithmetic is short. A reading is the true tilt plus the instrument’s own bias. After half a turn on the same spot the surface slopes the other way as the instrument sees it, while the bias, which belongs to the instrument, has not moved. Add the two readings and the tilt cancels, leaving twice the bias. Subtract them and the bias cancels, leaving twice the tilt.

Suppose a phone lying on a workbench reads 1.4 degrees with its right side high. Turned half a turn where it lies, it reads 0.6 degree with its left side high, which is minus 0.6. Half the sum is a bias of 0.4 degree. Half the difference is a true tilt of 1.0 degree.

The cure has limits. It removes a constant angle, and an offset in acceleration behaves like a constant angle only near level. It holds for one way of resting the phone, because the back and each edge of a case meet a table differently. And it holds for a while, not for good. The same survey measured one phone every evening for 44 days, and its two in-plane zeros wandered across spans of 3 mg and 4 mg, the larger worth 0.23 degree. Its authors put such drift down to slow sensor noise and to changes in temperature.

Degrees, percent and rise over run

Trades describe the same tilt in different words. Slope is the proportion of vertical rise to horizontal length, so an angle becomes a slope through its tangent. One degree is a rise of 17.5 mm in every meter, which is 1.75 percent. Forty-five degrees is 100 percent. A ratio such as 1:12 says the same thing with the run counted in units of rise.

Ramps are written as ratios. The ADA Standards allow a ramp a running slope no steeper than 1:12, limit the rise of any one run to 30 inches, hold ordinary walking surfaces to 1:20 and allow a cross slope of at most 1:48. The Access Board’s guide gives 1:12 as 8.33 percent and suggests specifying 7.5 percent for exterior ramps, so that the irregularities of real construction still land inside the limit. As an angle, 1:12 is 4.76 degrees. Set the first demonstration slider on this page to 4.8 and the second to 0, and it shows 8.4 percent, 84 mm per meter, 1.01 inches per foot and a ratio of 1:11.9, which is just too steep.

Drains are written as rise per run. Wisconsin’s plumbing code, for one, sets the minimum pitch of horizontal branch drains at a quarter inch per foot for pipes of 2 inches or less and an eighth of an inch per foot for larger ones. A quarter inch per foot is 1:48 again, or 1.19 degrees. An eighth is 0.60 degree. Set that beside the 0.58 degrees hidden in one step of a rounded gravity reading and the point is plain: such a reading cannot tell a correctly pitched large drain from a dead level one.

A shelf has no code. It has an eye, and perhaps a marble. The tolerance set on a level is where that judgment gets written down.

Noise, smoothing and the last digit

Even a calibrated reading shivers. The phone survey found that noise differs between phone models and stays stable within one, and its authors draw the line: bias can be compensated, noise only reduced. The honest summary of a shivering number is its standard deviation: the square root of the summed squared departures from the mean, divided by one less than the count. Shown beside the angle, it says how far to trust the last digit. Rounding has its own line in that ledger. A value equally likely to lie anywhere within an interval has a standard uncertainty of the half-width divided by the square root of three, so a step of 0.58 degrees is worth about 0.17 degree of doubt.

Smoothing trades time for steadiness. Exponential smoothing keeps a running value and moves it part of the way toward each new sample, so that old samples fade geometrically. Android’s own sensor guide uses that filter to isolate gravity and takes the fraction from a time constant. The time constant is defined by what it does: one time constant after a sudden change, the output has covered 1 minus 1 over e of it, which is 63.2 percent. A longer constant calms the digits and makes the level slower to answer.

What a phone cannot do should be said plainly. It cannot state an accuracy, because nobody has compared it with a standard. It cannot span a doorway; it reads only the short stretch it rests on. It cannot measure while it is being moved, and it cannot see past the rounding a browser applies. A surveyor’s vial that moves 2 mm for 0.005 degree works at about a hundredth of the step of a rounded reading.

So use the phone for what it is good at: a picture frame, a shelf, a washing machine, a first look at a slope. Calibrate it where it lies. Watch the noise figure. And for a ramp that will be inspected, a drain that must run, or anything that carries a load, reach for the instrument Thévenot described in 1661, and turn it end for end before trusting that one too.

Sources

Every source consulted for this guide. Links checked October 4, 2026.

  1. Device Orientation and Motion World Wide Web Consortium (W3C)
  2. DeviceMotionEvent: accelerationIncludingGravity property MDN Web Docs (Mozilla)
  3. DeviceMotionEvent: requestPermission() static method MDN Web Docs (Mozilla)
  4. Orientation and motion data explained MDN Web Docs (Mozilla)
  5. chromium/services/device/generic_sensor/platform_sensor_util.h at main The Chromium Authors, on GitHub
  6. Motion sensors Android Developers (Google)
  7. Tilt Sensing Using a Three-Axis Accelerometer (AN3461, Rev. 6) Freescale Semiconductor, published by NXP
  8. Evaluation of Smartphone Inertial Sensor Performance for Cross-Platform Mobile Applications Anton Kos, Sašo Tomažič and Anton Umek, Sensors, vol. 16, no. 4, 2016, via PubMed Central
  9. CODATA Value: standard acceleration of gravity National Institute of Standards and Technology (NIST)
  10. Spirit level Wikipedia
  11. Archimedes' principle Wikipedia
  12. Self-Calibration: Reversal, Redundancy, Error Separation, and "Absolute Testing" Evans, Hocken and Estler, Annals of the CIRP 45(2), on NIST
  13. Chapter 4: Accessible Routes U.S. Access Board, ADA Accessibility Standards
  14. Chapter 4: Ramps and Curb Ramps U.S. Access Board, Guide to the ADA Accessibility Standards
  15. Wisconsin Legislature: SPS 382.30 Wisconsin State Legislature, Wisconsin Administrative Code
  16. 1.3.5.6. Measures of Scale NIST/SEMATECH e-Handbook of Statistical Methods
  17. Evaluating uncertainty components: Type B National Institute of Standards and Technology (NIST)
  18. 6.4.3.1. Single Exponential Smoothing NIST/SEMATECH e-Handbook of Statistical Methods
  19. Exponential smoothing Wikipedia