Histogram Bin Calculator
Calculate the optimal number of histogram bins and bin width using Sturges, Scott, Freedman-Diaconis, Square Root, and Rice rules based on your dataset properties.
About this calculator
Choosing too few histogram bins hides real structure in a distribution by lumping distinct groups together; choosing too many turns real structure into visual noise from bins with only a handful of points each. This calculator computes five published rules side by side so you can compare them rather than trust just one. Sturges' Rule (k = ceil(log2 n) + 1) depends only on sample count and assumes a roughly normal distribution -- it is the oldest and simplest rule, but it under-recommends bins for large or skewed datasets. The Square Root and Rice rules are similarly simple sample-count-only heuristics, useful as a sanity check against Sturges rather than a primary choice.
Scott's Rule and the Freedman-Diaconis Rule both account for how spread out your data actually is, not just how many points you have: Scott's Rule estimates spread from an assumed normal distribution's standard deviation (approximated here from your Interquartile Range), while Freedman-Diaconis uses the IQR directly and is the most robust of the five to outliers, since the IQR itself is not affected by a few extreme values the way a computed standard deviation would be. The Primary Method selector determines which rule's bin count and width become the headline Optimal Number of Bins and Bin Width results, while all five remain visible for comparison. None of these rules can tell you whether your underlying data assumptions (like near-normality, for Sturges and Scott) actually hold -- that judgment call is still yours to make by looking at the resulting histogram.
Inputs
Results
Optimal Number of Bins
8
Bin Width
6.25
How to Use This Calculator
- Enter Number of Data Points (n) and Data Range.
- Select a Primary Method: Sturges' Rule, Scott's Rule, or Freedman-Diaconis.
- Adjust Interquartile Range (IQR) as needed -- required for Scott's and Freedman-Diaconis.
- Review Optimal Number of Bins and Bin Width.
- Use Method Used and Sturges Bins to inform your decision.
What each input means
- Number of Data Points (n)
- Total number of observations in your dataset.
- Data Range
- The range of your data (maximum value minus minimum value).
- Primary Method
- Sturges: good for normal data. Scott: accounts for spread. Freedman-Diaconis: robust to outliers (uses IQR).
- Interquartile Range (IQR)
- IQR = Q3 - Q1. Required for Scott's and Freedman-Diaconis methods: Scott's Rule uses it only to estimate standard deviation (IQR / 1.35), while Freedman-Diaconis uses it directly in its bin-width formula.
How this is calculated
Worked example, using the default values
- Identify Input Parameters4 parametersNumber of Data Points (n) = 100, Data Range = 50, Primary Method = 1, Interquartile Range (IQR) = 15 = 4 input(s) provided
- Calculate Optimal Number of Bins8 = 8
- Calculate Bin WidthBin Width6.25 = 6.25
- Calculate Method UsedSturges' Rule = Sturges' Rule
- Calculate Sturges BinsSturges Bins8 = 8
Engine last updated . Checked against 2 independently-derived tests — how we verify calculators. Built by Paul Gunder, a software engineer, not a licensed financial, medical, or legal professional.
Frequently Asked Questions
Why do the five rules give me different bin counts for the same data?
Because they use different information: Sturges', Square Root, and Rice rules look only at how many data points you have, while Scott's and Freedman-Diaconis also factor in how spread out the data is (via the interquartile range). A dataset with the same sample count but a wider spread will get a wider recommended bin width and fewer bins from Scott's or Freedman-Diaconis, but the identical answer from the three count-only rules.
Which rule should I trust if my data has outliers?
Freedman-Diaconis is the most robust to outliers among the five, because it bases its bin width directly on the interquartile range (the middle 50% of your data), which barely moves even if a few extreme values are added or removed. Rules based on standard deviation, like Scott's, or on sample count alone can be more distorted by extreme values sitting far from the bulk of the distribution.
Does increasing my number of data points always increase the recommended bin count?
Yes, for every one of these five rules, holding the data's range and spread constant -- more data points support finer resolution without individual bins becoming too sparse to be meaningful. The relationship is not linear, though: most of these formulas grow with the cube root or logarithm of sample count, so doubling your data does not double the recommended bin count.
Why does the calculator need both Data Range and IQR as separate inputs?
Data Range (maximum minus minimum) sets how wide the whole histogram needs to span, while IQR (the spread of just the middle 50% of the data) is used only by Scott's and Freedman-Diaconis rules to estimate the data's typical spread for bin width. A dataset can have a huge range dominated by a few extreme outliers while its IQR stays modest, which is exactly the situation Freedman-Diaconis is designed to handle well.
What happens if I select Scott's Rule but haven't estimated an IQR?
Scott's Rule still runs, but its spread estimate comes entirely from dividing your entered IQR by 1.35 to approximate a standard deviation, so an inaccurate IQR will produce an inaccurate bin width recommendation for this method specifically. If you don't have a real IQR handy, Sturges' Rule or the Square Root Rule -- which need only your sample count -- are more reliable fallbacks.
Related Calculators
The questions that sit next to this one — chosen by subject, including calculators filed under a different category.
Pareto Chart Generator
Generate a Pareto analysis from category defect counts. Identify the vital few causes that account for the majority of problems using the 80/20 rule.
Quality ControlControl Chart Calculator
Calculate Upper Control Limit (UCL), Lower Control Limit (LCL), and center line for X-bar, R, and S control charts using process statistics and sample size.
Quality ControlAcceptance Sampling Plan Calculator
Generate an acceptance sampling plan based on lot size, AQL, and inspection level. Determine sample size, accept/reject numbers, and operating characteristics.
More in Manufacturing, Industrial & Coatings.