The guide
Most numbers start with a small digit, and a mismatch is a question rather than an accusation
Benford's law says how often each leading digit should appear in many real data sets. A chi-square test measures the fit, but only on enough values, and a poor fit asks for an explanation, not a verdict.
- 30.1% of numbers should start with 1 under Benford's law
- 15.5073 5 percent chi-square limit with 8 degrees of freedom
- 0.1586 chi-square of 2 to the power k, k = 1 to 1000
- 401.30 chi-square of the whole numbers 1 to 999
- 100 values where this tool starts to give a verdict
Read the full guide Fold the guide
A law about spacing, not about numbers
In 1881 the astronomer Simon Newcomb noticed that the early pages of a book of logarithm tables were much more worn than the later ones. That pointed to readers looking up numbers that start with 1 far more often than numbers that start with 9.
The physicist Frank Benford stated the same rule in 1938 in an article titled “The Law of Anomalous Numbers”. He tested it on data from 20 different domains, 20,229 observations in all, among them the surface areas of rivers, the sizes of United States populations and a list of physical constants. The law took his name, although Newcomb had been there first.
The rule fits in one line. The share of numbers whose first digit is d equals log10(1 + 1/d). For d = 1 that is about 30.1%, for 2 it is 17.6%, and the shares fall steadily to 4.6% for 9. A flat guess would give every digit 11.1%.
The formula is really a statement about space. On a logarithmic scale the gap between 1 and 2 is much wider than the gap between 8 and 9, and the share for digit d is proportional to the space between d and d + 1 on that scale. Drop a point at random on a number line where every tenfold step has the same length, and it lands in the stretch that starts with 1 about three times in ten.
Why logarithms? Because the law survives a change of units. Berger and Hill’s primer shows that a random variable has exactly Benford digits when its significant digits are scale invariant, meaning that multiplying every value by any positive constant leaves the digit probabilities unchanged. Measure the same list of lengths in metres or in feet and the leading digits should look alike. Logarithmic spacing is the one spacing that keeps that promise.
The second digit follows a flatter rule: the sum over k from 1 to 9 of log10(1 + 1/(10k + d)). A second digit of 2 has probability about 0.109, against 0.1 for an even spread. The shares run from 0.1197 for a 0 down to 0.0850 for a 9, and later digits flatten out quickly toward uniform.
Why some data follow it and some cannot
Data follow the law when the logarithms of the values spread smoothly across a wide range. Wikipedia gives the rule of thumb: the more orders of magnitude the data cover evenly, the better the law applies, and the populations of settlements across a whole country are a natural example.
Narrow data fail by construction. Restrict “settlement” to villages with between 300 and 999 people and the law no longer applies. Adult heights and IQ scores sit almost entirely inside one order of magnitude and are unlikely to follow it. Berger and Hill give a sharper case: for a normal distribution with mean 7 and standard deviation 1, the chance of a leading 1 is at most one in a million.
Many real quantities grow by multiplication, and multiplication helps. In Wikipedia’s example a price is multiplied each day by a random factor between 0.99 and 1.01. The logarithm of the price then takes a random walk, so it spreads out over time and the leading digits approach the law. Additive noise leads instead to normal distributions, which do not satisfy it.
Mixing helps as well. Take numbers from newspaper articles, a jumble of sources that each follow some other distribution, and the law tends to reappear. The primer states a version of this: if samples come from distributions chosen in an unbiased way, the combined sample converges to Benford’s law.
The several-orders rule is a guide, not a theorem. Berger and Hill point out that 10 raised to a uniform random number between 0 and 1 is exactly Benford and yet only takes values between 1 and 10. In 2020 Hill posted a note showing, with constructed examples, that the claim “every Benford distribution spans several orders of magnitude” is false. Spread is neither necessary nor sufficient, and the primer adds that no uniform distribution, however wide, comes close.
Some sequences follow the law exactly in the limit: the powers of 2, the Fibonacci numbers and the factorials. The OEIS lists the leading digits of the powers of 2 as sequence A008952. All three make good test data, and the tool offers each. Its failing example is the whole numbers from 1 to 999, which cannot fit: each digit from 1 to 9 starts exactly 111 of them.
Reading the test
The tool counts how many numbers start with each digit and sets the counts against what the law expects. Chi-square adds up, over the nine digits, the squared gap between the observed and the expected count divided by the expected count. With nothing fitted there are 8 degrees of freedom, just as a six-sided die has five.
Take 2 to the power k for k from 1 to 1000. The leading digits 1 to 9 count 301, 176, 125, 97, 79, 69, 56, 52 and 45, a chi-square of 0.1586 and a mean absolute deviation of 0.00068, which is under a tenth of a percentage point. The factorials from 1 to 500 scatter more, at 7.6932. The whole numbers from 1 to 999 give 401.30.
The 5 percent critical value for 8 degrees of freedom is 15.5073, found here by search and equal to the 15.507 in the NIST table. A statistic above it has a p-value below 0.05. The p-value is the chance, if the law held, of a chi-square at least as large, and it is the upper tail of the chi-square distribution: one minus the regularised incomplete gamma function evaluated at half the degrees of freedom and half the statistic.
The tool evaluates that function from the power series and the continued fraction in the NIST library of mathematical functions, and its statistics and p-values agree with SciPy’s chisquare on the examples. The powers of two give a p-value of 0.999998, so they fit; the whole numbers give about 9.9e-82, where e-82 means times ten to the power of -82. The mean absolute deviation is the average of the absolute gaps between observed and expected shares. It does not grow with the number of values, which is why it earns a place beside chi-square.
Sample size bites from both ends. NIST asks for an expected count of at least 5 in every class and calls the test invalid for small samples, and Wikipedia notes that chi-square has low power with few values. At 100 values the rarest digit, 9, is expected only 4.58 times. So the tool computes from 30 values but gives a verdict only from 100 values, and it warns when the rarest digit falls below 5. The 73 ages from 18 to 90 give a chi-square of 48.5 and still earn no verdict.
At the other end, chi-square equals the count times the sum of the squared share gaps divided by the expected shares. A fixed gap therefore gives a chi-square that grows in step with the count. A difference too small to matter becomes significant given enough values, so read the deviation as well.
A mismatch is a question
Digit tests have been used on election returns. Walter Mebane was the first to apply the second-digit test in election forensics, and Wikipedia calls such analysis simple but not foolproof. Other researchers argued that the law is problematic and misleading as an indicator of fraud, and Mebane agreed that there are many caveats.
A failed test has many innocent explanations. A limit written into a process, such as a cap or a minimum, piles numbers against it. A habit of rounding does the same. A narrow range removes the law’s footing, and a pool of values from sources that disagree can break it. None of these is wrongdoing, and the test cannot tell them apart.
The tool reads digits from the written characters, never from a number it has already rounded. A program that parses 0.19999999999999999999 as a floating-point number gets 0.2 and a leading 2, while the written digits begin with 1. The built-in examples are built from exact integers with BigInt, which stays exact beyond the largest safe integer, and then written with 15 digits cut, not rounded, so that no leading digit moves.
Reading and counting run in a Web Worker so the page stays responsive, and the counts are formatted with Intl.NumberFormat. Zeros, signs, stray words and thousands commas are never counted as digits: each one is skipped and listed with its position, so you can see what was left out.
What it cannot do is plain. It cannot detect fraud. It cannot judge a small sample, and with very many values it flags tiny gaps. It says little about numbers confined to a narrow range such as ages or prices inside a band. At the 5 percent level it will also flag about one in twenty of the data sets that truly follow the law.
When the test says the digits do not fit, ask first how the numbers were made. Look at which digit is off and by how much, check the range, and split the data by source. The useful next sentence after a failed test starts with “why”, and never with “who”.
Sources
Every source consulted for this guide. Links checked November 10, 2026.
- Benford's law Wikipedia
- Chi-squared distribution Wikipedia
- Pearson's chi-squared test Wikipedia
- 1.3.5.15. Chi-Square Goodness-of-Fit Test NIST/SEMATECH e-Handbook of Statistical Methods
- 1.3.6.7.4. Critical Values of the Chi-Square Distribution NIST/SEMATECH e-Handbook of Statistical Methods
- 8.2 Definitions and Basic Properties (Incomplete Gamma Functions) NIST Digital Library of Mathematical Functions
- 8.7 Series Expansions (Incomplete Gamma Functions) NIST Digital Library of Mathematical Functions
- 8.9 Continued Fractions (Incomplete Gamma Functions) NIST Digital Library of Mathematical Functions
- The Mathematics of Benford's Law -- A Primer arXiv (Arno Berger and Theodore P. Hill)
- A Widespread Error in the Use of Benford's Law to Detect Election and Other Fraud arXiv (Theodore P. Hill)
- scipy.stats.chisquare SciPy documentation
- A008952 Leading digit of 2^n The On-Line Encyclopedia of Integer Sequences
- BigInt MDN Web Docs
- Web Workers API MDN Web Docs
- Intl.NumberFormat MDN Web Docs