Skip to main content
Calcimator

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

Method UsedSturges' Rule
Sturges Bins8
Scott Bins6
Freedman-Diaconis Bins8
Square Root Bins10
Rice Bins10
How to Use This Calculator
  1. Enter Number of Data Points (n) and Data Range.
  2. Select a Primary Method: Sturges' Rule, Scott's Rule, or Freedman-Diaconis.
  3. Adjust Interquartile Range (IQR) as needed -- required for Scott's and Freedman-Diaconis.
  4. Review Optimal Number of Bins and Bin Width.
  5. 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

  1. Identify Input Parameters
    4 parameters
    Number of Data Points (n) = 100, Data Range = 50, Primary Method = 1, Interquartile Range (IQR) = 15 = 4 input(s) provided
  2. Calculate Optimal Number of Bins
    8 = 8
  3. Calculate Bin Width
    Bin Width
    6.25 = 6.25
  4. Calculate Method Used
    Sturges' Rule = Sturges' Rule
  5. Calculate Sturges Bins
    Sturges Bins
    8 = 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.

The questions that sit next to this one — chosen by subject, including calculators filed under a different category.

More in Manufacturing, Industrial & Coatings.