Sturges' Rule Bin Count Calculator
The Sturges' rule bin count calculator turns a sample size into a practical starting point for histogram construction.
Run — free
Enter the number of observations, and it evaluates one plus the base-two logarithm of that number, then rounds upward to produce a whole number of bins. The result is useful when you need a quick, reproducible choice instead of selecting a histogram layout by eye. It also reports the unrounded value so you can see exactly how the recommendation was formed.
Turn a sample size into a repeatable histogram choice
A histogram can look very different depending on how many bins it uses. Too few bins may hide clusters, gaps, or skewness, while too many can make ordinary sampling noise look like meaningful structure. Sturges' rule provides a simple baseline based only on the number of observations. Supply n, the count of observations in the sample, and the calculator evaluates 1 + log2(n). Because a histogram cannot use a fractional number of bins, the suggested count is rounded upward to the next whole number. For example, powers of two produce exact whole-number results, while other sample sizes usually produce a fractional intermediate value. The response includes both the final bin count and that intermediate value rounded to six decimal places. This makes the output convenient for immediate chart configuration while keeping the reasoning visible for reports, notebooks, and validation. Use the recommendation as a consistent first draft, especially when several people or automated jobs need to construct comparable histograms from datasets of different sizes.
Understand the formula and its boundaries
Sturges' rule is written as k = 1 + log2(n), where n is the sample size and k is the number of classes or bins. Each doubling of the sample adds one bin to the recommendation. A sample of one therefore suggests one bin, a sample of eight suggests four, and a sample of 128 suggests eight. This calculator applies the common ceiling convention so a non-integer result becomes a usable whole bin count without discarding part of the formula's recommendation. The input must be a finite whole number because a sample size counts observations, and it must be at least one because the logarithm does not yield a meaningful histogram recommendation for an empty sample. Sturges' rule grows slowly as datasets become larger. That restraint often produces readable summaries, but it can smooth away detail in large, strongly skewed, multimodal, or heavy-tailed samples. The output is a rule-based suggestion, not evidence that the selected bins reveal every important feature of a distribution.
Use the result as a baseline, then inspect the distribution
Start by passing the number of valid observations that will actually appear in the histogram. If your raw table contains missing or excluded values, count only the observations retained for plotting; otherwise the recommendation will describe a larger sample than the chart contains. Apply the returned bin count to your plotting library, spreadsheet, or reporting pipeline, then inspect the result alongside one or two alternatives. Comparing the Sturges count with nearby counts can reveal whether an apparent shape is stable or merely caused by a particular set of boundaries. Also remember that the number of bins does not determine where bin edges begin, so two histograms with the same count may still differ when their ranges or boundary positions change. For highly variable data, consider comparing this baseline with a width-based method such as the Freedman-Diaconis rule. In automated workflows, record the method and returned count with the chart so reviewers can reproduce the choice rather than guessing which software default was used.
What you can do with it
Configure a plotting library
Convert the number of retained observations into a whole bin count before rendering a histogram.
Standardize exploratory reports
Apply the same documented bin-selection rule across recurring datasets and reporting runs.
Audit a histogram default
Compare a chart application's automatic choice with a transparent Sturges' rule baseline.
FAQ
What does the calculator return?
It returns the validated sample size, the ceiling-rounded suggested bin count, and the unrounded value of 1 + log2(n) to six decimal places.
Why is the result rounded upward?
Bins must be counted with a whole number. Taking the ceiling preserves the full recommendation when the formula produces a fraction.
Can n be zero?
No. A histogram sample must contain at least one observation, and the base-two logarithm of zero is not defined.
Is Sturges' rule always the best choice?
No. It is a convenient baseline, but it may use too few bins for large, skewed, multimodal, or heavy-tailed datasets.
Should missing values be included in n?
Use the number of valid observations that will actually be plotted, excluding missing or filtered-out values.
What does it cost?
The browser calculator is free to run on this page. An API request costs $0.002.
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/sturges-rule \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"n":100}'const res = await fetch("https://api.kit.forhosting.com/stat/sturges-rule", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"n": 100
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/stat/sturges-rule",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"n": 100
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/stat/sturges-rule", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"n":100}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"n":100}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/stat/sturges-rule", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"n": 100
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "stat.sturges_rule",
"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. |