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.
Related tools
The standard deviation calculator gives the spread used in Scott’s rule, and the IQR and outliers calculator covers the quartiles.