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
- Export one column of amounts from your accounts system: supplier payments, expense claims, refunds, journal amounts. Hundreds of rows is good; thousands is better.
- 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-99are read as they are. - 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.
- 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.
- 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.
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.
The three tests, in plain words
- MAD (mean absolute deviation): the average gap between the share you have for each digit and the share the law expects. Mark Nigrini, who brought Benford's Law into auditing, gives bands for first digits: up to 0.006 close, up to 0.012 acceptable, up to 0.015 marginal, above that nonconformity. MAD does not grow just because the file is big, so from 1,000 amounts up the verdict uses these bands. Below 1,000 they flag most honest files (see the measurement below), so they are shown but do not decide.
- Chi-square: one number for how far all nine counts are from the expected counts. Above 15.507 the gap would happen by chance less than 5% of the time; above 20.09, less than 1%. It keeps its promise at small sizes: about 5 honest columns in 100 pass the 5% line, whatever the size. So under 1,000 amounts the verdict comes from chi-square: past the 1% line nonconformity, past the 5% line marginal, otherwise acceptable. On large files it flags small, harmless gaps, so from 1,000 up it is shown as supporting evidence, not the verdict.
- z per digit: whether one digit on its own is too common or too rare. Above 1.96 is unusual for one digit (5% level), and the table marks it. Testing nine digits at once at that line would name a digit in about one honest column in five (1 − 0.9759 ≈ 20%), so a digit is named to "look here first" only above 2.773: the same 5% shared over the nine digits (the Bonferroni correction). Biggest first.
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.
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
- It is a screen, not proof. A nonconforming column tells you where to look. It does not say anyone did anything wrong. A conforming column is not a clean bill of health either: a fraud that copies the normal pattern passes.
- Some data never follows the law, and the tool cannot know that for you. Examples: assigned numbers (invoice numbers, phone numbers), prices set at fixed points (£9.99), amounts with a built-in cap or floor, a single fee charged many times. Use it on amounts that arise naturally.
- It needs enough data. Below the "fewest amounts to judge" setting (100 by default) it gives no verdict. From 100 to 999 amounts the verdict comes from chi-square, which can only see large gaps at that size: a small pile-up can pass. From 1,000 up it uses Nigrini's MAD bands. If you lower the setting under 100, the result says the verdict is weak.
- It needs spread. If the amounts span less than two orders of magnitude (say, all between £100 and £9,999), the verdict is still given, with a note underneath that it is weak. Benford's Law describes amounts that range over several powers of ten; a narrow band of similar amounts can't show the pattern.
- First digits only. Nigrini's fuller method adds first-two-digit and last-two-digit tests, which this version does not run.
- No duplicate check. Every row counts, so the same amount paid twice counts twice. It does not look for duplicate payments: that is a separate test (Nigrini's number-duplication test), which this version does not run.
- Number formats. Read:
£ $ € ¥in front,GBP USD EURafter, a minus sign or accountants' brackets for negatives, commas only as thousands separators (1,234.56). Refused and counted as unreadable, never guessed: European formats like1.234,56, spaces inside a number (1 234.56), a currency code in front (EUR 5), and any text mixed in.
Blueprint
Five small parts, each a pure function: the same input always gives the same output, with no network, clock or randomness.
| Part | What it does | File |
|---|---|---|
| csvColumn | Reads one column of a CSV: quoted cells, commas inside quotes, any line ending, blank lines dropped. | kernel.mjs |
| parseAmount | Turns a ledger cell into a number: £/$/€/¥, thousands commas, accountants' brackets for negatives. Refuses anything ambiguous. | kernel.mjs |
| leadingDigit | The first significant digit, read from the number's own decimal form. | kernel.mjs |
| audit | Counts, 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 |
| honestRates | Screens 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 |
| cli | The 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 |
| checkCase | The cost case below, from the UK median wage and inflation (ONS). | checkcase.mjs |
How it is proved
- Tests:
node --test kernel.test.mjspins exact counts, MAD, chi-square and z values on fixed inputs, every parsing rule, each line exactly on its edge, the honest-data measurement, and that no kind of input throws an error.node --test cli.test.mjspins every exit code the command line promises. - Mutation gate: witness changes the kernel one small step at a time and re-runs the tests; every change must be caught. From receipts/witness.json: reading the receipt…
- CI: GitHub re-runs the tests and all three gates on every change; the runs are public on the repo's Actions tab.
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.
- 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.
- 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:
- 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.
- It called three numbers "maximally divergent". Version 2 refuses to judge below a sample floor.
- 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.
"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
- Nothing leaves the page, and the browser enforces it. The screen runs in your browser. The page carries a Content-Security-Policy that lets it connect only to its own site, so even a changed copy of the code could not send your data anywhere else. It loads only its own code and two small files (the gate receipt and the cost figures). Check it yourself: open your browser's developer tools, Network tab, paste a column and press Screen it. No request is made.
- No personal data needed. Only the amount column is used. You can strip names and suppliers before pasting.
- No AI model decides anything. The verdict comes from fixed published thresholds in code you can read.
- Recomputable. The same column gives the same verdict and the same fingerprint on any machine, so a result can be checked later or by someone else.
- Run it where you like. Copy the repo onto your own machine or intranet; there is nothing to install beyond a browser, or Node.js for the command line.
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
- Day one: run it on last quarter's supplier payments and expense claims. Read what it flags.
- Week one: add it to the month-end close checklist. Save each result's fingerprint with the working papers.
- Month one: run it on every amount column where approval limits apply: expenses, refunds, credit notes, manual journals.
- 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.htmlfrom a local web server, or use the command line. - Command line?
- With Node.js installed:
node cli.mjs payments.csv amountprints 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, andnode cli.mjsprints 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