Histogram Bins Calculator

Find the optimal number of histogram bins and bin width by three rules — Sturges, Scott, and Freedman-Diaconis — from your data.

Inputs

Paste your dataset, comma- or space-separated.

Result

Suggested bins (Sturges)
5
Scott 3 · Freedman-Diaconis 3
  • Data points (n)12
  • Range38 (4 to 42)
  • Sturges — bins5 (width ≈ 7.6)
  • Scott — bin width / bins17.8879 / 3
  • Freedman-Diaconis — width / bins13.3221 / 3
  • SD / IQR used11.7344 / 15.25
Note — Sturges suits small, roughly normal data but under-bins large datasets. Scott assumes normality. Freedman-Diaconis is robust to outliers (uses the IQR). Treat the suggestions as starting points and adjust visually.

Step-by-step

  1. Sturges: k = ⌈log₂(12) + 1⌉ = ⌈4.585⌉ = 5 bins.
  2. Scott: width = 3.49·s·n^(−1/3) = 3.49×11.734×12^(−1/3) = 17.8879 → 3 bins.
  3. Freedman-Diaconis: width = 2·IQR·n^(−1/3) = 2×15.25×12^(−1/3) = 13.3221 → 3 bins.

How to use this calculator

  • Paste your dataset, separated by commas, spaces, or new lines.
  • Read the suggested bin counts from Sturges, Scott, and Freedman-Diaconis.
  • Use Freedman-Diaconis for skewed data or when outliers are present.
  • Adjust the chosen bin count visually until the histogram shape is clear.

About this calculator

Choosing the number of bins for a histogram is a balance: too few bins hide the shape of the distribution, too many make it noisy. Several rules formalize the choice. Sturges' rule, k = ⌈log₂n + 1⌉, is simple and works for small, roughly bell-shaped datasets but tends to use too few bins for large samples. Scott's rule sets the bin width from the standard deviation and sample size, assuming the data is approximately normal. The Freedman-Diaconis rule uses the interquartile range instead of the standard deviation, which makes it robust to outliers and skew. This calculator computes all three from your pasted data, reporting both the bin count and bin width for each, so you can pick the one that best matches your data and visualize accordingly.

How it works — the formula

Sturges: k = ⌈log₂ n + 1⌉ Scott: h = 3.49 · s · n^(−1/3), k = ⌈range / h⌉ Freedman-Diaconis: h = 2 · IQR · n^(−1/3), k = ⌈range / h⌉

Sturges counts bins directly from sample size; Scott and Freedman-Diaconis derive a bin width from spread and sample size, then divide the range by it.

Worked examples

Example 1
n = 12 dataset
Inputs:
data=4,8,15,16,23,42,11,19,27,33,5,9
Output:
Sturges ⌈log₂12+1⌉ = 5 bins
Example 2
n = 100 (Sturges)
Inputs:
100 values
Output:
Sturges = ⌈6.64+1⌉ = 8 bins
Example 3
n = 1000 (Sturges)
Inputs:
1000 values
Output:
Sturges = ⌈9.97+1⌉ = 11 bins

Limitations

  • Sturges under-bins large datasets; Scott assumes normality.
  • Freedman-Diaconis can give very many bins for tight IQR with wide range.
  • All are guidelines — final bin count is a visualization judgment.

Bin-count rules are heuristics; always sanity-check the resulting histogram.

Frequently asked

There is no single right answer — it depends on the data. Common rules give a starting point: Sturges for small normal-ish data, Scott for larger normal data, and Freedman-Diaconis for skewed data or data with outliers. Then refine visually.

Related calculators

More tools you might like