Method and sources
What is computed, the constant behind each verdict and where it was published, and how the results were checked. All of it runs in the browser from js/benford.js and js/engine.js.
Reading an amount
Each cell is read as text. Thousands separators (comma, dot, space, no-break space, apostrophe), currency symbols and three-letter codes are ignored; negatives may be written -48.20, 48.20-, (48.20) or with the minus sign. The decimal mark is detected from the column (whether the last separator is followed by three digits, and whether a separator repeats) and can be set by hand. Cells that are dates, times or codes are counted as “not numbers” and left out, with an example shown.
The significant digits are taken from the written number, not from its binary value. This matters below 1: in floating point 0.29 × 100 is 28.999999999999996, so a program that truncates the product files 0.29 under the digits 28. Zero is always left out. Amounts below 10 are left out by default.
The digit tests
For a test with digit groups d, observed share APd of the N amounts tested, and expected share EPd:
| Test | Groups | Expected share |
|---|---|---|
| First digit | 1–9 | log10(1 + 1/d) |
| Second digit | 0–9 | Σk=1..9 log10(1 + 1/(10k + d)) |
| First two digits | 10–99 | log10(1 + 1/d) |
| Last two digits | 00–99 | 1/100 |
The first three formulas are Benford’s (1938). The last-two digits test is Nigrini’s (2012), who uses it to find rounding and invented numbers. Here it takes the last two digits of the whole-number part, for amounts of 1,000 and over only; that choice is this tool’s, made so that the two digits are the third digit or later, which Benford’s law itself expects to be nearly uniform (the third digit ranges from 10.18% for 0 to 9.83% for 9). Below 1,000 the tens digit is the second digit, which is not uniform.
Mean absolute deviation and its ranges
MAD = (1/K) · Σd |APd − EPd|, K = number of digit groupsNigrini (2012, Table 7.1, p. 160) gives four conformity ranges for the MAD, building on Drake & Nigrini (2000). The tool uses them as published; a MAD equal to a bound falls in the range above it, as in the R package benford.analysis.
| Test | Close conformity | Acceptable | Marginally acceptable | Nonconformity |
|---|---|---|---|---|
| First digit | 0.000–0.006 | 0.006–0.012 | 0.012–0.015 | above 0.015 |
| Second digit | 0.000–0.008 | 0.008–0.010 | 0.010–0.012 | above 0.012 |
| First two digits | 0.0000–0.0012 | 0.0012–0.0018 | 0.0018–0.0022 | above 0.0022 |
| Last two digits | no published range; the tool reports the MAD, chi-square and Z-scores without a verdict | |||
The R package benford.analysis 0.1.5 codes the second-digit upper bound as 0.011 in MAD.conformity(); its benford() function never uses that row. This tool uses Nigrini’s 0.012.
The MAD does depend on the sample size: even data drawn from Benford’s law itself has an expected MAD of about (1/K) · Σ √(2·EPd(1 − EPd) / (π N)), which shrinks as 1/√N (Cerqueti & Lupi 2022). The tool prints that figure as “MAD by chance alone” under each test, so a small file’s verdict can be read in proportion.
Z-statistic for each digit
Z = ( |AP − EP| − 1/(2N) ) / √( EP(1 − EP) / N )As in Nigrini (2012), the continuity correction 1/(2N) is subtracted only when it is smaller than |AP − EP|. A digit is marked over-represented when AP > EP and Z > 2.576 (two-sided 1% level); 1.96 is the 5% level. The sign shown in the tables is the sign of AP − EP.
Chi-square and Kolmogorov–Smirnov
χ² = Σd (Od − Ed)² / Ed, df = K − 1; D = maxd |cumulative AP − cumulative EP|, 5% critical value 1.36/√NThe p-value is the upper regularised incomplete gamma function Q(df/2, χ²/2), computed with a series and a continued fraction. Both tests are shown for completeness, with a caveat: their power grows with N, so on a large file they reject Benford for deviations of no practical size (Kossovsky 2021; Cerqueti & Lupi 2022). That is the reason Nigrini judges conformity by the MAD.
Summation test
The amounts are summed within each first-two-digit group. If the data follow Benford, each of the 90 groups carries the same share of the total, 1/90 (Nigrini 2012). A group far above that holds a few very large amounts or many of one size. There is no published cut-off; the chart marks groups above twice 1/90 and the table ranks the five largest.
Number duplication test
Counts how often each exact amount occurs among the amounts tested and ranks them (Nigrini 2012). The test makes no assumption about digits; it is the quickest way to explain a spike.
Drill-down and export
Selecting a digit, a summation group or an amount selects exactly the rows counted in it. The export writes those rows as they were in the file, with a first column source_row giving the data row number (1 = first row under the header), in the file’s own delimiter, UTF-8 with a byte-order mark so Excel opens it correctly.
How it was checked
Last run 2026-11-05: 42 of 42 Node tests and 28 of 28 phone checks passed. The suite is in tests/; tests/run_all.sh runs all of it.
Expected proportions
The first-digit, second-digit, first-two and last-two distributions are checked against Benford’s formula written a second way (as differences of logarithms, and as marginals of the first-two-digit distribution) to 1e-12, against R’s p.these.digits to 1e-12, and against the 5-decimal table printed in the literature. Each sums to 1 within 1e-12.
Same data, same answers as R
The R package benford.analysis 0.1.5 (R version 4.4.1 (2024-06-14)) was run in a container on two datasets it ships: corporate.payment (189,470 payments of a division of a West Coast utility in 2010) and census.2009 (populations of 19,509 US towns and cities, July 2009), both documented by the package as from Nigrini (2012). R keeps all positive values (or all non-zero values, as absolute values, with sign = "both") and does not drop amounts below 10, so the comparison does the same. Bin counts, MAD, chi-square, its p-value, the conformity verdict, the summation sums and the ten most duplicated amounts were compared for each case.
| Data | Signs | Test | N | MAD in R | MAD here | Verdict (both) | χ² in R | χ² here | Rows read differently |
|---|---|---|---|---|---|---|---|---|---|
| corporate.payment | positive | First digit | 185,083 | 0.013211405 | 0.013211405 | Marginally acceptable conformity | 4317.27 | 4317.27 | 0 |
| corporate.payment | both | First digit | 189,347 | 0.013178742 | 0.013178742 | Marginally acceptable conformity | 4393.34 | 4393.34 | 0 |
| census.2009 | positive | First digit | 19,509 | 0.003119261 | 0.003119261 | Close conformity | 17.52 | 17.52 | 0 |
| corporate.payment | positive | First two | 185,083 | 0.002336614 | 0.002336614 | Nonconformity | 32094.35 | 32100.90 | 146 |
| corporate.payment | both | First two | 189,347 | 0.002336108 | 0.002336108 | Nonconformity | 31890.17 | 31908.84 | 146 |
| census.2009 | positive | First two | 19,509 | 0.000613414 | 0.000613414 | Close conformity | 107.16 | 107.16 | 0 |
| corporate.payment | positive | First three | 185,083 | 0.000456910 | 0.000456673 | Marginally acceptable conformity | 369052.79 | 368873.20 | 441 |
| corporate.payment | both | First three | 189,347 | 0.000458491 | 0.000458336 | Marginally acceptable conformity | 366999.27 | 366804.31 | 455 |
| census.2009 | positive | First three | 19,509 | 0.000212010 | 0.000212010 | Close conformity | 1831.46 | 1831.46 | 0 |
Applying R’s own digit rule to the same parsed values reproduces R’s bin counts exactly in all 9 cases, the MAD to within 1e-15, the chi-square and summation sums to 1e-12 and 1e-9 relative, the p-value to 1e-9 relative, and the same verdict. With this tool’s rule (digits read from the written number), the verdicts are unchanged; the MAD and chi-square differ slightly on the rows counted in the last column. The test checks that every one of them is a floating-point case: R computes the digits as trunc(10k−1−floor(log10 x) · x), and for an amount like 0.29 the product is 28.999999999999996, so R files it one digit group too low; this tool reads 29 from the text. On the full first-two digits test of corporate.payment both give MAD 0.002337, nonconformity, as the package’s own printed output shows.
Known answers on synthetic data
- 100,000 log-uniform amounts over five orders of magnitude: close conformity on the first digit (MAD 0.00074), second digit (0.00054) and first two digits (0.00021); last-two digits chi-square p = 0.99.
- 50,000 uniform amounts between 10 and 100,000: nonconformity (first digit MAD 0.0596, first two 0.0060).
- 400 invented amounts between 4,800 and 5,000 mixed into 20,000 genuine ones: Z = 10.9 at 48 and 16.8 at 49, the two largest spikes, while the overall MAD stays in close conformity. The drill-down and the export select exactly the rows with first digits 48.
- 150 copies of 2,500 rise to the top of the duplication test; three amounts of about 7.3 million make 73 the largest summation group (2.3 times 1/90) without a first-two digit spike; 1,500 whole hundreds give the last-two digits test its largest spike at 00 (Z = 129.5).
- A file written the European way (semicolons, 1.234,56 €) gives the same counts as the same amounts written 1,234.56; an XLSX gives the same counts as the CSV it was made from.
Speed
- One million rows in Node v26.8.1 on Intel(R) Core(TM) i7-1068NG7 CPU @ 2.30GHz: 29.1 MB plain CSV read and tested in 621 ms (118 ms to index the rows, 503 ms for every test); 43.9 MB with quoted fields and “1,234.56” amounts in 1072 ms.
- The same million plain rows picked as a file in headless Chromium at phone size: results drawn 641 ms after the file was chosen, with the work in a Web Worker.
On a phone
At 390 × 844 the page opens with the sample, draws the five charts, opens the drill-down for 48 when its bar is tapped, and exports those rows; it also loads an XLSX with two sheets and a decimal-comma column, and a pasted column. No horizontal overflow, no script errors, no failed requests (28 of 28 checks).
Sources
- Benford, F. (1938). The law of anomalous numbers. Proceedings of the American Philosophical Society, 78(4), 551–572.
- Cerqueti, R., & Lupi, C. (2022). Severe testing of Benford’s law. arXiv:2202.05237. (Section 3: distribution of the MAD under the null; why fixed MAD ranges are strict for small N.)
- Cinelli, C. (2018). benford.analysis: Benford Analysis for Data Validation and Forensic Analytics. R package version 0.1.5, CRAN. (Reference implementation and the corporate.payment and census.2009 datasets.)
- Drake, P. D., & Nigrini, M. J. (2000). Computer assisted analytical procedures using Benford’s law. Journal of Accounting Education, 18(2), 127–146.
- Hill, T. P. (1995). A statistical derivation of the significant-digit law. Statistical Science, 10(4), 354–363.
- Kossovsky, A. E. (2021). On the mistaken use of the chi-square test in Benford’s law. Stats, 4(2), 419–453.
- Nigrini, M. J. (1996). A taxpayer compliance application of Benford’s law. Journal of the American Taxation Association, 18(1), 72–91.
- Nigrini, M. J. (2012). Benford’s Law: Applications for Forensic Accounting, Auditing, and Fraud Detection. Hoboken, NJ: Wiley. (Digit, summation and duplication tests; Z-statistic with continuity correction; MAD ranges in Table 7.1, p. 160.)
- US Census Bureau (2025). County Population Totals and Components of Change: 2020–2024, file co-est2024-alldata.csv. Public domain. (The sample.)
The explanations on this site are written for it and do not reproduce the text of these works.