StatGardenREF. DESK
Calculators/Statistics/Class width for a histogram
Statistics

Class width for a histogram calculator

How wide each bin should be, from either a target class count or Sturges’ rule.

Published 6 August 2026 · Updated 25 September 2026

What this calculator does

Class width is the data range divided by the number of classes. Data running from 12 to 98 split into 8 classes gives a width of 10.75, which in practice would be rounded up to 11 or 15 for readable bin edges.

The harder question is how many classes to use, and Sturges rule gives a starting answer from the sample size alone: roughly log₂n plus 1. For 50 observations that suggests 7 classes. It is a guideline rather than a rule, and it is known to suggest too few classes for large data sets, so treat it as a first try to adjust from.

The formula

Formulawidth = (max − min) / classes; Sturges’ rule: classes ≈ ⌈log₂ n + 1⌉

The range is the maximum minus the minimum, and dividing by the desired class count gives the width. Sturges rule suggests a class count as the ceiling of log₂n plus 1, and the corresponding width is shown alongside. Both widths are exact divisions, so rounding up to a convenient number is normal and usually improves readability.

TermMeaning
Class widthThe span of each histogram bin.
Sturges ruleA class count suggestion of ⌈log₂n + 1⌉, based on sample size alone.
RangeMaximum minus minimum, the total span the classes must cover.
Bin edgesThe boundaries between classes, which are easier to read when they land on round numbers.

The inputs explained

FieldWhat to enter
Minimum valueThe smallest value in the data.
Maximum valueThe largest value in the data.
Desired number of classesHow many classes you want. Between 5 and 20 covers most cases.
Sample size (for Sturges’ rule)Sample size, used only for the Sturges rule suggestion.

When to use it

Building a histogram

Class width and count determine whether a histogram reveals the distribution shape or obscures it.

Choosing how many bins

Too few classes hide structure and too many produce noise, and Sturges gives a defensible starting point.

Matching an existing report

Reproducing a published histogram means matching its class boundaries, which starts from the width.

Worked examples

Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.

How does the class count change the width?

The same range divided into different numbers of classes.

Data from 12 to 98, n = 50
Desired classesClass widthRangeSturges’ suggested classes (from n)
5 classes17.20086.0007
6 classes14.33386.0007
8 classes10.75086.0007
10 classes8.60086.0007
The Sturges suggestion stays at 7 in every row, because it depends only on the sample size of 50 and not on how many classes you asked for. Its own width of 12.286 sits between the 6-class and 8-class results, so either of those would be a reasonable practical choice once rounded.

Questions

How many classes should a histogram have?

Usually between 5 and 20, with the right number depending on sample size and how much structure the data has. Sturges rule suggests ⌈log₂n + 1⌉, which gives 7 for 50 observations and 11 for 1,000. Try a couple of options and pick the one that shows the shape most clearly.

Should I round the class width?

Almost always. A width of 10.75 produces bin edges like 12, 22.75, 33.5, which nobody can read at a glance. Rounding up to 11 or 15 gives clean boundaries. Round up rather than down, so the classes still cover the full range.

Is Sturges rule reliable?

It is a reasonable starting point for moderate sample sizes but is known to suggest too few classes for large data sets, because it assumes roughly normal data. For large or skewed data, the Freedman-Diaconis rule, which uses the interquartile range, generally performs better.

What happens if the classes are too wide or too narrow?

Too wide and the histogram flattens into a few bars that hide any real structure, including bimodality. Too narrow and it becomes a spiky mess where random variation looks like signal. Both failures are common, which is why trying more than one width is worth the effort.

For mean and spread from a completed frequency table, see the grouped data calculator. For the full summary of raw data, see the descriptive statistics calculator.