Histogram Bin Calculator - Optimal Bin Width

Calculate optimal number of bins and bin width for histograms using multiple rules (Sturges, Scott, Freedman-Diaconis).

Results

Calculated
Result
—

What a histogram bin calculator does and when to use it

A histogram groups a list of measurements into consecutive intervals called bins and draws a bar whose height shows how many values landed in each interval. The number of bins is the single most influential choice you make: too few and the bars flatten a bimodal or skewed shape into one lump, too many and every bar is a few stray points so the outline looks like noise. This calculator takes the only thing it needs, your sample size n, and returns the bin counts suggested by three classic rules so you have a defensible starting point instead of accepting a software default.

Use it before you plot exam scores, sensor readings, survey responses or lab measurements, especially when you must compare charts from datasets of different sizes. The square-root choice, Sturges' rule and the Rice rule all depend on n alone, so the result is instant and needs no raw data. Treat the suggested bin count as a first draft: look at the chart, and if a feature looks lumpy or over-smoothed, nudge the count up or down. Once you have a count k, divide the data range by k to get a bin width, or use the class width calculator to round it to a convenient number.

The three rules and their variables

Each rule turns the sample size n into a whole number of bins k. The calculator rounds up with the ceiling function so a partial bin becomes a full one.

  • Square-root choice: k = ceil(√n). It grows slowly and is the default in many spreadsheet tools.
  • Sturges' rule: k = ceil(log2(n) + 1). It assumes roughly bell-shaped data and adds one bin each time n doubles.
  • Rice rule: k = ceil(2 × n1/3). It usually gives slightly more bins than Sturges for mid-sized samples.

The suggested count shown by the calculator is the mean of the three results, rounded to the nearest whole number. Two other well-known rules, Scott's (h = 3.49 × s / n1/3) and Freedman-Diaconis (h = 2 × IQR / n1/3), give a bin width h from the standard deviation s or the interquartile range IQR, so they need the actual data and are not calculated here.

Worked example: n = 100 observations

Suppose you measured 100 fruit weights and want a starting bin count.

  • Square-root choice: √100 = 10, so k = 10.
  • Sturges' rule: log2(100) = 6.644, plus 1 is 7.644, rounded up to k = 8.
  • Rice rule: 1001/3 = 4.642, times 2 is 9.283, rounded up to k = 10.
  • Suggested count: (10 + 8 + 10) / 3 = 9.33, which rounds to 9 bins.

Entering 100 in the calculator returns exactly these four numbers. If your fruit weights range from 40 g to 130 g, a 9-bin histogram has a bin width of about 10 g (90 g range divided by 9), which is a tidy and readable choice.

Common mistakes and how to interpret the result

  • Treating the answer as a rule of law. The rules are heuristics. Sturges' rule in particular tends to under-bin large or skewed samples, so with thousands of points try the Rice or square-root result instead.
  • Entering the number of distinct values instead of the number of observations. Sample size n counts every data point, including repeats.
  • Forgetting that bins must be equal width. The count only makes sense if every bin spans the same interval; unequal bins need a density scale on the vertical axis.
  • Ignoring the data's own spread. Two datasets with the same n but very different outliers can deserve different bin widths, which is why Scott's and Freedman-Diaconis rules exist.

Frequently Asked Questions

Why do the three rules give different numbers?
Each rule is built on a different assumption. Sturges assumes near-normal data and grows with log2(n), the Rice rule grows with the cube root of n, and the square-root choice grows with the square root. For n = 100 they return 8, 10 and 10, and the gap widens as n grows.
What sample size does the calculator accept?
Any whole number of at least 2. Decimals are rounded to the nearest integer before the rules are applied, and smaller values show a validation message because a histogram of fewer than two points is not meaningful.
Does the suggested bin count change the shape of my data?
It changes how the shape is displayed, not the data. Different bin counts can hide or reveal features such as a second peak, so compare two or three bin counts before drawing conclusions.
How do I turn the bin count into a bin width?
Subtract the smallest value from the largest to get the range, then divide by the bin count and round up to a convenient number. Choose bin edges that do not cut through natural values, for example multiples of 5 or 10.

Related calculators