Calculateus

Histogram Bin Calculator

Calculate the recommended number of histogram bins and bin width for a dataset, using Sturges' Rule.

Result

Recommended Bins
9
Bin Width
9.444

Sturges' Rule (bins = ⌈log₂(n) + 1⌉) works well for smaller, roughly normal datasets - for larger or skewed datasets, the Freedman-Diaconis rule (based on interquartile range) is often preferred.

About the Histogram Bin Calculator

The Histogram Bin Calculator recommends how many bins to use and how wide each bin should be before plotting a histogram, based on Sturges' Rule. Choosing bin count by trial and error can hide a distribution's real shape if there are too few bins, or bury it in noise if there are too many, so a formula-based starting point is useful before fine-tuning by eye.

How It Works

You enter the number of data points (n), along with the minimum and maximum values in the dataset. The calculator applies Sturges' Rule to get a recommended bin count, then divides the full range of the data by that count to get a suggested bin width.

Bins = ceil(log2(n) + 1); Bin Width = (Maximum - Minimum) / Bins.

Formula & Methodology

Sturges' Rule assumes roughly bell-shaped data and grows the bin count on a log2 scale with sample size, since doubling the sample only adds one more bin. Once the bin count is set, the calculator divides the observed range (max minus min) by that count to get an even bin width for setting up the histogram's buckets.

Examples

A Mid-Sized Dataset

For 150 data points ranging from 10 to 95, Sturges' Rule gives ceil(log2(150) + 1) = ceil(8.23) = 9 bins, with each bin about (95 - 10) / 9 = 9.44 units wide.

A Small Survey Sample

For 30 responses on a 0 to 100 scale, the calculator returns ceil(log2(30) + 1) = ceil(5.91) = 6 bins, each about 16.67 units wide.

Advantages

  • Gives an objective starting point for bin count instead of an arbitrary guess, useful for anyone new to building histograms.
  • Instantly converts a recommended bin count into an actual bin width using the dataset's real range.
  • Flags when a different method (Freedman-Diaconis) may serve larger or skewed datasets better, rather than presenting Sturges' Rule as a universal answer.

Common Mistakes

  • Treating the recommended bin count as a fixed rule rather than a reasonable starting point that may still need visual adjustment.
  • Applying Sturges' Rule to a heavily skewed or multimodal dataset, where a range-based rule typically produces a more informative histogram.
  • Forgetting that the bin width formula assumes equal-width bins across the entire range, which can hide detail when a few extreme values stretch that range.

Edge Cases to Watch For

  • Requires the sample size to be greater than zero and the maximum value to be strictly greater than the minimum, or the calculator returns an error.
  • The result includes a note that Sturges' Rule works best on smaller, roughly normal datasets; for larger or heavily skewed data, a range-based method like the Freedman-Diaconis rule is often more appropriate.
  • Because bin count grows on a log2 scale, very large datasets still get a comparatively small number of bins, which can feel too coarse for exploratory plots.
  • The bin count is rounded up to the next whole number, so the resulting bin width may not divide the range into a perfectly round-looking increment.

Common Use Cases

  • Analysts and students preparing a histogram in a spreadsheet or statistics tool who need a quick, defensible starting bin count.
  • Data scientists doing exploratory analysis on a new dataset before deciding whether finer or coarser binning is needed.
  • Instructors demonstrating how sample size influences histogram resolution when teaching descriptive statistics.
Written & fact-checked by the Calculateus TeamLast updated August 5, 2026How we verify our formulas

Frequently asked questions

What is Sturges' Rule?

It's a formula for choosing a reasonable number of histogram bins based only on sample size: bins = ⌈log₂(n) + 1⌉ - too few bins hides the shape of your distribution, while too many creates a noisy, hard-to-read histogram with many empty or sparse bins.

Conclusion

Sturges' Rule offers a fast, defensible way to pick a starting bin count and width, though it should be treated as a first pass rather than a final answer, particularly for large or skewed datasets.