Built by Kar for AI Native Solutions · MIT licence · source

BenfordGap

A first-digit fraud screen for any column of amounts. Paste a payables export, an expense list or a claims file. It counts how often each first digit 1 to 9 appears and compares that with Benford's Law, the pattern that genuine financial amounts usually follow. You get a verdict, the strength of the evidence, and the digits to look at first. It runs on your computer: nothing you paste is sent anywhere.

Try it

Load an example, or paste your own: one amount per line, or a whole CSV with a header row (then pick the column).

With fewer usable amounts than this (100 unless you change it) there is no verdict. From there up to 999 amounts the verdict comes from the chi-square test; from 1,000 up, from Nigrini's MAD bands.

Start here

  1. Export one column of amounts from your accounts system: supplier payments, expense claims, refunds, journal amounts. Hundreds of rows is good; thousands is better.
  2. Paste it above, or open the CSV file. If it has a header row, pick the amount column. Amounts like £1,240.00, (85.50) or -99 are read as they are.
  3. Press Screen it. Read the verdict first, then the notes underneath: they say if rows were skipped or if the data is the wrong shape for this test.
  4. Look at the digits named "look here first". Those first digits turn up more often than the law expects. Filter your ledger to amounts starting with that digit and read them: round numbers, repeats, amounts just under an approval limit, one supplier.
  5. Keep the fingerprint. The result carries a SHA-256 fingerprint of the input and the result. Anyone with the same column gets the same fingerprint, so a reviewer can check your screen was run on what you say it was. The exact recipe is in the FAQ, and the command line prints the same two fingerprints, so the check does not depend on this page.

How it works

In many real collections of amounts (invoices, populations, river lengths, share prices) the first digit is 1 about 30% of the time and 9 under 5% of the time. That is Benford's Law: the share for digit d is log10(1 + 1/d). It holds when amounts arise from many independent causes and spread over several orders of magnitude. Invented amounts usually don't follow it, because people pick digits more evenly, and amounts pushed under a limit pile up on the limit's first digit.

1 · read rowsCSV column2 · read amount£, commas, (brackets)3 · first digitfrom its decimal form4 · count 1 to 9skips counted5 · compareMAD · chi-square · z6 · verdict+ digits to look at every step is in kernel.mjs, the same file the tests and the mutation gate run

Traced from a real run

This is the "£5,000 sign-off limit" example, run by the kernel when this page loaded. The numbers below are computed, not typed in.

Running…

The three tests, in plain words

How often it flags honest data, measured as this page loaded

The kernel draws columns that follow Benford's Law exactly (from a fixed seed, so anyone gets the same numbers) and screens each one. A good screen should flag about 5 in 100 of these. The table shows how often each test would have flagged them.

Measuring…

Real ledgers fit the law less exactly than these columns, so expect somewhat more flags on real honest data, not fewer. The function is honestRates in kernel.mjs; its exact results are pinned in the tests.

What it can't tell you

Blueprint

Five small parts, each a pure function: the same input always gives the same output, with no network, clock or randomness.

PartWhat it doesFile
csvColumnReads one column of a CSV: quoted cells, commas inside quotes, any line ending, blank lines dropped.kernel.mjs
parseAmountTurns a ledger cell into a number: £/$/€/¥, thousands commas, accountants' brackets for negatives. Refuses anything ambiguous.kernel.mjs
leadingDigitThe first significant digit, read from the number's own decimal form.kernel.mjs
auditCounts, MAD with Nigrini's band, chi-square, z per digit, spread, skipped rows, and one verdict: from chi-square under 1,000 amounts, from the MAD bands from 1,000 up. It says which.kernel.mjs
honestRatesScreens columns that follow the law exactly, from a fixed seed, and reports how often each test flags them. The measurement table above comes from it.kernel.mjs
cliThe same screen from the command line, with an exit code a scheduled job can act on: 0 not flagged, 2 flagged, 1 bad input.cli.mjs
checkCaseThe cost case below, from the UK median wage and inflation (ONS).checkcase.mjs

How it is proved

What version 2.1 fixed

Version 2 passed its gate, and the same method found two more faults: running honest columns through it at each size.

  1. It took the verdict from Nigrini's MAD bands at every size. On honest columns of 100 amounts, those bands flag almost all of them (the table above shows the measured share). Version 2.1 uses chi-square under 1,000 amounts, where it keeps its 5% promise, and the MAD bands from 1,000 up.
  2. It named a digit to look at first whenever one digit passed z 1.96. With nine digits tested at once, that happens by chance in about one honest column in five (nine chances at 2.5% on the too-common side: 1 − 0.9759 ≈ 20%). Version 2.1 uses the nine-digit line, 2.773.

What version 2 fixed

Version 1 passed its own gate and still had three faults. Each was found by running a whole class of inputs, not by reading the code:

  1. It found the first digit by dividing by 10 in a loop, which drifts. 1,700 ordinary numbers got the wrong digit (3×1027 read as 2), while a comment said it had been checked exhaustively. Version 2 reads the digit from the number's decimal form, and the tests check the full range.
  2. It called three numbers "maximally divergent". Version 2 refuses to judge below a sample floor.
  3. It silently dropped every row it could not read, including £1,234.56. Version 2 reads ledger formats and reports every skipped row.

For your business

Benford screening is a standard first step in forensic accounting and audit analytics. Most finance teams don't run it routinely, because it means exporting data, building a spreadsheet and knowing the thresholds. This page turns it into a two-minute job, with a fingerprint a reviewer can recheck.

Chief financial officer

A routine, documented screen on payables, expenses and refunds every month-end, not just when someone is suspicious. Findings arrive as "look at amounts starting with 4", which a team can act on that day.

Financial controller and internal audit

Nigrini's thresholds applied the same way every time, with the reasoning shown. The fingerprint ties the working paper to the exact data screened.

Chief operating officer

Claims and expense processes leave a signal when people work around approval limits. A pile-up just under a limit shows as one digit flagged, before it shows up in a loss.

CTO and information security

No server, no account and no upload. The ledger stays on the analyst's machine. The code is short, open and tested, so you can read all of it before approving it.

Chief executive and the board

A cheap, repeatable control that shows diligence on fraud risk, and whose results anyone can recompute.

The finance team

No formulas to build and no thresholds to look up. Paste, read, filter. It doesn't replace their judgement; it points it.

Against what you pay now

Audit analytics suites include a Benford test, usually licensed per seat. Spreadsheet templates are free but have to be built, checked and maintained by hand. BenfordGap is MIT-licensed, with no licence fee. If it replaces a tool you pay for, enter that tool's monthly cost in the case below and it is counted. We don't quote other vendors' prices; yours are the ones that matter.

Cost case

The inputs are yours; change them. Staff time is costed at the UK median hourly wage, with on-costs left out, so the figure is a floor. It rises each year with UK inflation. Both figures are from the ONS and linked below the table.

Working it out…

"By hand" means exporting the column, building the digit count in a spreadsheet, and looking up and applying the thresholds. The 45-minute default is our assumption; use your own.

Security, compliance and data protection

Questions a security review will ask

Where is the data processed, and where does it live?
Only in the browser tab on the analyst's own device. No server receives it: the site that serves the page (GitHub Pages) sends the files and never sees what is pasted. Data location is wherever that device is.
How long is it kept?
Not at all. The page uses no cookies, local storage or database, and writes nothing to disk. Closing or reloading the tab clears it. Anything you keep, such as a copied result or a saved CSV, follows your own retention policy.
Is it encrypted?
The page's own files arrive over HTTPS. Your data is never transmitted or stored, so there is no transfer or storage to encrypt.
Who is the processor? What about subject access requests and breaches?
No data reaches AI Native Solutions, GitHub or anyone else, so for the screen itself there is no supplier holding data: nothing to list as a processor, nothing to search for a subject access request, nothing for us to breach. You stay the controller of your own exports.
Third parties and supply chain?
None at run time: no analytics, no trackers, no fonts or scripts from other sites, no AI model, no package dependencies. The code is three short files you can read (kernel.mjs, checkcase.mjs and the page), and every change is tested and mutation-gated in public on GitHub when it is pushed.
Can we run it fully inside our network?
Yes. Copy the repository to an internal web server, or run the command line on a locked-down machine. It needs no internet connection to screen.

Roll-out

  1. Day one: run it on last quarter's supplier payments and expense claims. Read what it flags.
  2. Week one: add it to the month-end close checklist. Save each result's fingerprint with the working papers.
  3. Month one: run it on every amount column where approval limits apply: expenses, refunds, credit notes, manual journals.
  4. Automate if you want: the same kernel runs from the command line (node), so it can sit in a scheduled job. See the README.

Support and ownership

Supplied by AI Native Solutions; start through that site. Support, any service level, warranty and liability are agreed per deployment, in each deployment's agreement. The software is MIT-licensed and keeps running without us: you own your copy.

Risks, answered straight

What if it flags honest data?
It will sometimes. On columns that follow the law exactly it flags about 5 in 100, measured live in "How it works". Real honest data that doesn't follow the law is flagged more often (see "What it can't tell you"). That is why it names digits to look at rather than people to accuse. The cost of a false flag is a few minutes of filtering.
What if it misses fraud?
It can. A fraud that mimics the normal distribution, or a single large payment, won't show. Treat it as one control among several, not the only one.
Can I trust the code?
Read it: the kernel is under 300 lines, with the reason for each rule written next to it. Every line is covered by tests that a mutation gate checks. Version 1 passed its gate and still had faults, and so did version 2. Each was found by attacking it with a whole class of input, and each attack is now part of the tests.
Who is accountable for a decision made on it?
Your team. The tool screens; people decide.

The explainer

Why first digits are uneven. Take an amount that grows steadily, like a balance earning interest. It spends a long time with first digit 1 (from 100 to 199 it must double), and much less with first digit 9 (from 900 to 999 is only an 11% rise). When many amounts arise from growth, multiplication and mixing over several orders of magnitude, their first digits settle into the share log10(1 + 1/d): 30.1% ones, 17.6% twos, down to 4.6% nines. Simon Newcomb noticed it in 1881 from the worn pages of logarithm tables. Frank Benford tested it on over 20,000 numbers in 1938.

Why fraud shows. People inventing amounts tend to spread digits evenly and avoid repeating themselves. People working around a control push amounts just under it: claims of £4,950 to stay under a £5,000 approval, so digit 4 is over-represented. Both leave a mark in the first-digit counts that a simple, repeatable test can see.

Why these thresholds. Chi-square is the textbook test, but with thousands of rows it flags gaps too small to matter. Nigrini's MAD bands were set from real accounting data to separate "close enough" from "worth a look" on large files, and they do not grow with file size. But on small files honest data drifts further from the law by chance, and the fixed bands flag it. So each test is used where it holds: chi-square under 1,000 amounts, MAD from 1,000 up. Both, and the per-digit z, are always shown so you can see the evidence.

Why a fingerprint. A screen is only as good as the data it was run on. The SHA-256 fingerprint of the input column and the result lets anyone confirm, later, that the screen in a working paper was run on the column it claims.

Words on this page

Benford's Law
The observation that in many real collections of numbers, smaller first digits are more common: about 30% start with 1, under 5% with 9.
First digit
The first non-zero digit: 4 for £4,950, 7 for 0.07, 3 for 3×1027.
MAD
Mean absolute deviation: the average, over the nine digits, of the gap between the share you have and the share the law expects.
Chi-square, p<0.05, p<0.01
A single measure of how far all the counts are from the expected ones. "p<0.05" means a gap this large would happen by chance in honest data less than 5% of the time.
z
How unusual one digit's count is on its own. Above 1.96 is unusual at the 5% level.
Orders of magnitude
Powers of ten. £10 to £10,000 spans three.
Kernel
The small file of code (kernel.mjs) that makes every decision. This page only displays what it returns.
Mutation gate
A test of the tests: witness makes one small deliberate change to the kernel at a time (a > becomes >=) and re-runs the tests. If no test fails, that spot is unchecked, and the gate is not clean.
CI
Continuous integration: GitHub re-runs the tests and the gate on its own machines on every change, publicly.
SHA-256 fingerprint
A 64-character code computed from the data. The same data always gives the same code. Change one character and the code changes completely.
MIT licence
An open-source licence: use, copy, change and sell it, free, keeping the copyright notice.

FAQ

What happens with a huge file?
It runs in your browser's memory. Every result says how long the screen took on your machine, so you can see the cost for yourself; the honest-data measurement in "How it works" screened over a million amounts as this page loaded. For files too big to paste, use the command line.
What happens with bad rows?
They are counted, never guessed. The result says how many rows were unreadable and how many were zero, and leaves them out.
Do negative amounts count?
Yes, by their size: a refund of (85.50) counts as first digit 8. Screen refunds as their own column if you want to look at them apart.
Does it work offline?
Once the page has loaded, the screen needs no connection. For a permanent offline copy, download the repo and open index.html from a local web server, or use the command line.
Command line?
With Node.js installed: node cli.mjs payments.csv amount prints the same result as JSON, with the same two fingerprints. See the README.
Are amounts rounded?
No. Only the first digit that is not zero is used, read from the amount exactly as written: £1,234.56 counts as 1, £0.99 as 9, 0.07 as 7. Pence never change the first digit of an amount of a pound or more.
How exactly is the fingerprint made?
Two SHA-256 hashes of UTF-8 text. Input: the cells that were screened, exactly as read from the column (blank lines dropped), joined with a single newline. Result: the JSON text {"v","n","counts","skipped","verdict","minN"}, with those keys in that order and no spaces: the kernel version, the number of amounts used, the nine digit counts, the skipped rows, the verdict and the floor. Any SHA-256 tool gives the same codes, and node cli.mjs prints them too. The command line's tests check the recipe.

BenfordGap v2.1 · built by Kar for AI Native Solutions · MIT · github.com/sjgant80-hub/kar-benfordgap