ForHosting KIT · Developer Utilities

Sturges' Rule Bin Count Calculator

The Sturges' rule bin count calculator turns a sample size into a practical starting point for histogram construction.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

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.

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.

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.

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.

POSThttps://api.kit.forhosting.com/stat/sturges-rule

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.

curl -X POST https://api.kit.forhosting.com/stat/sturges-rule \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":100}'
{
  "n": 100
}
{
  "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.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →