Benford's law calculator
Under Benford's law about 30.103 percent of numbers start with 1, but only about 4.576 percent start with 9. Pick a leading digit to get its expected share, the theoretical bar to hold your own counts against. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Digit
- 1
- Percentage
- 30.1029995664
- Probability
- 0.3010299957
Benford's law describes a striking regularity in many naturally occurring collections of numbers: the first significant digit is far more often 1 than 9. The expected share for digit d is the base-ten logarithm of one plus one over d, written P(d) equals log10 of (1 + 1/d). This Benford's law calculator accepts a single leading digit from 1 to 9 and returns that expected frequency as a percentage, together with the unit-interval probability and the textbook formula string. Digit 0 is not a leading digit and is rejected, as are fractions and any value outside the closed range from 1 through 9.
What Benford's law says and how the expected frequency is computed
Simon Newcomb noticed in 1881 that the early pages of logarithm tables were more worn than the later ones, and Frank Benford later published the same first-digit law with broader empirical tables. The mathematical statement is simple: if a positive number is equally likely to lie anywhere on a logarithmic scale, the significand is uniformly distributed in log space, and the probability that the leading digit equals d is the width of the interval from d to d plus one on that scale.
That width is log10 of (1 + 1/d). For d equals 1 the interval runs from 1 to 2 and occupies about 30.103 percent of the decade. For d equals 9 the interval from 9 to 10 occupies only about 4.576 percent.
Those nine probabilities sum to one, which is a useful classroom check. The law is scale-invariant: multiplying every observation by a constant (changing currency, units, or a reporting scale) does not change the predicted first-digit shares, because a constant shift in log space leaves the fractional part of the logarithm equally likely. It also tends to appear when data span several orders of magnitude and arise from multiplicative processes, such as populations, river lengths, street addresses, physical constants, and many accounting ledgers.
It does not apply to assigned identifiers, tightly bounded measurements, lottery draws, or any series that is uniform on a linear scale.
Who relies on the expected first-digit shares
Statistics and forensic-accounting courses constantly ask students to write the first-digit formula and to quote the nine expected percentages from memory. Internal-audit and data-quality teams compare an observed leading-digit histogram against these theoretical bars as a screening signal, not as a verdict of fraud: a large deviation can mean fabricated figures, a truncated range, a mixture of two processes, or simply the wrong dataset for the law.
Election and campaign-finance researchers, journalists, and open-data analysts use the same expected frequencies when they publish first-digit charts and need a documented source for the comparison line. Keep requests small, pin the rounded percentage in tests, and you get reproducible answers for homework, LMS plugins, and edge workers without standing up a statistics library of your own. If you later need a chi-square goodness-of-fit against a full sample, treat that as a separate search intent rather than overloading this single-digit expected-frequency page.
What you can do with it
Classroom Benford drills
Students submit a digit from 1 to 9 and check the expected percentage against hand calculations of 100 times log10(1 + 1/d).
Audit and ledger screening tables
Build the nine theoretical first-digit bars for an observed-versus-expected chart when reviewing invoices, journal entries, or public ledgers.
FAQ
What is the Benford's law formula for a leading digit?
P(d) = log10(1 + 1/d) for an integer digit d from 1 to 9. This calculator returns that value as a percentage and as a unit-interval probability.
What does the response contain?
The echoed digit, percentage (100 times the Benford probability), probability on [0, 1], and the formula string P(d) = log10(1 + 1/d).
Does this test whether my dataset follows Benford's law?
No. It returns only the theoretical expected frequency for one digit. Compare your own observed shares to these bars with a separate goodness-of-fit procedure.
What does the Benford's law calculator cost?
The browser tool is free and runs locally.
Does Benford's law apply to every kind of data?
No. It tends to appear in data that span several orders of magnitude and grow by multiplication, such as populations or river lengths. It does not fit assigned identifiers, tightly bounded measurements, lottery draws or series that are uniform on a linear scale.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/stat/benfords-law \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"digit":1}'const res = await fetch("https://api.kit.forhosting.com/stat/benfords-law", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"digit": 1
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/stat/benfords-law",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"digit": 1
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/stat/benfords-law", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"digit":1}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"digit":1}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/stat/benfords-law", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"digit": 1
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "stat.benfords_law",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
The same pure function powers the free browser tool and the prepaid API path, so audit notebooks, exam keys, and forensic scripts never disagree on the classic thirty-point-one percent figure for leading ones. Successful API calls are priced at the published $0.002 base; invalid input is not billed.
What Benford's law says and how the expected frequency is computed
This endpoint does not test a dataset against the law. It evaluates the closed-form expected frequency for one requested digit so you can build tables, mark homework, or compare an observed share against the theoretical bar without re-deriving the logarithm each time.
Input contract, response fields, and validation errors
Provide a single integer from 1 to 9. On success the body echoes the parsed digit, returns percentage as one hundred times log10 of (1 + 1/d), returns probability as the same quantity on the unit interval, and includes formula as the string P(d) equals log10(1 + 1/d). Values are rounded to a stable twelve-significant-figure precision so automated checks compare byte for byte across runtimes. Classic checks: digit 1 yields a percentage near 30.103 and a probability near 0.30103; digit 2 yields about 17.609 percent; digit 9 yields about 4.576 percent. Wire the free browser form for interactive teaching, then call the identical contract from scripts when you need a full 1-through-9 table for an audit workbook or a grader. POST a JSON body with one required field named digit, or use the short aliases d or leading_digit. JSON numbers and whole-number strings are accepted so form widgets can submit a text field without client-side casting. The nine theoretical bars are deterministic constants, not estimates from a sample, so two callers with the same digit always receive the same JSON. Pricing for successful API calls is the published base of $0.002 per item; validation failures do not consume prepaid balance.
Where a Benford expected-frequency API earns its keep
A single trusted oracle that returns cleaned JSON speeds homework checks, demo setup, and interactive lesson design without a spreadsheet logarithm that someone typed as natural log by mistake. Curriculum authors building browser widgets want the same JSON shape free on the page and paid through the API so offline worksheets and online auto-graders stay aligned. Because this capability is a pure parse engine, every successful call costs the published $0.002 base price with no model tokens and no outbound network, and failed validation does not consume balance.
Integration use cases
Grading fixtures and notebook checks
Pin deterministic expected frequencies in unit tests, LMS auto-graders, and research notebooks that compare observed shares to Benford's law.
Technical questions
Why is digit 0 rejected?
A leading significant digit cannot be 0. Benford's first-digit law is defined only for d = 1, 2, …, 9. The request fails with invalid_input and is not billed.