Skip to content
Omnikalc

Histogram bin calculator: Sturges, Rice, Scott and Freedman-Diaconis

Enter the sample size, standard deviation, interquartile range and range to get the number of bins and the bin width by the common histogram rules.

Updated on
Your inputs

Value out of range

Value out of range

Value out of range

Value out of range

Value out of range

Results

Number of bins by Sturges' rule

9

Number of bins by Rice's rule
12
Number of bins by the square-root rule
15
Bin width by Scott's rule
7.460
Number of bins by Scott's rule
12
Bin width by Freedman-Diaconis
5.472
Number of bins by Freedman-Diaconis
16

The shape of a histogram depends on how you cut the data into bins. The histogram bin width calculator takes the sample size, the standard deviation, the interquartile range and the minimum and maximum, and gives the number of bins by Sturges, Rice and the square-root rule, and the bin width and number of bins by Scott and Freedman-Diaconis.

How the calculation works

  • Enter the number of data points, their standard deviation, their interquartile range (Q3 − Q1) and the smallest and largest values.
  • Sturges’ rule uses k = ⌈log₂ n + 1⌉ bins, Rice’s rule uses k = ⌈2 n^(1/3)⌉ and the square-root rule uses k = ⌈√n⌉.
  • Scott’s rule sets the bin width to h = 3.49 × s ÷ n^(1/3), and the Freedman-Diaconis rule sets h = 2 × IQR ÷ n^(1/3). The number of bins is the range divided by h, rounded up.
  • The Freedman-Diaconis rule is less affected by outliers because it uses the interquartile range rather than the standard deviation.

Example

A data set has 200 values with a standard deviation of 12.5, an IQR of 16 and a range from 12 to 95 (83). Sturges gives ⌈log₂200 + 1⌉ = 9 bins, Rice gives 12 and the square-root rule gives 15. Scott’s width is 3.49 × 12.5 ÷ 5.848 = 7.46, so 12 bins. Freedman-Diaconis gives a width of 2 × 16 ÷ 5.848 = 5.47, or 16 bins.

Why it matters

Students, analysts and scientists plot histograms every day, and the default bin count in software is not always good. Comparing several rules shows a reasonable range of choices.

Good to know

The rules assume a reasonably smooth, single-peaked distribution. For very small samples they are unreliable, and for large samples with heavy tails the number of bins may be too large to read. Treat the result as a starting point.

The standard deviation calculator gives the spread used in Scott’s rule, and the IQR and outliers calculator covers the quartiles.

Frequently asked questions

Why does the number of bins matter?

Too few bins hide the shape of the data, while too many create a ragged histogram that shows noise instead of structure. A rule of thumb gives a sensible starting point that you can adjust after looking at the result.

Which rule should I use?

Sturges' rule is simple and works for roughly normal data with up to a few hundred values, but tends to give too few bins for large samples. Rice and the square-root rule give more bins. Scott and Freedman-Diaconis use the spread of the data, and Freedman-Diaconis is more robust to outliers.

What is the interquartile range?

It is the distance between the 75th percentile (Q3) and the 25th percentile (Q1), and describes the spread of the middle half of the data. It is not much affected by extreme values.

Are the rules exact?

No. They are heuristics. Skewed or multi-peaked data may need a different choice, and a histogram with bin edges at round numbers is often easier to read, so round the width to a convenient value.

Was this calculator helpful?

Thanks for your feedback!

Results are estimates provided for information purposes. They do not replace professional advice.