Class Width Calculator

Find the class width for a histogram or frequency distribution.

Science 4 rules Auto rounding
Rate this calculator · 5.0 (1)

Class width

Sturges, Rice, √n rules

Instructions — Class Width Calculator

Enter your dataset's minimum and maximum, then either set the number of classes (k) directly or pick a rule (Sturges, Rice, √n) and supply the sample size n. The calculator returns the exact class width, the rounded width (default: round up), the data range, and a preview of the bin intervals.

  1. Enter Min and Max — must come from your raw data, not from your bins.
  2. Choose k or a rule — Sturges = ⌈log₂ n + 1⌉, Rice = ⌈2·n^⅓⌉, √n = ⌈√n⌉.
  3. Pick rounding — round up is the statistical standard so every data point fits.
  4. Read off the result — use the rounded width to build your intervals starting at min.

Formulas

Main formula: w = (max − min) ÷ k

Sturges' rule: k = ⌈log₂(n) + 1⌉ — recommended for n < 200.

Rice rule: k = ⌈2 · n^(1/3)⌉ — better for n > 200.

Square root rule: k = ⌈√n⌉ — simple, fine for medium datasets.

Scott's rule: h = 3.5σ ÷ n^(1/3) — uses standard deviation; ideal for near-normal data.

Reference

Round up. If the computed width is 14.17, use 15 — never 14. Rounding down can push the largest observation outside the last bin.

Pick rule by sample size: Sturges shines below 200 observations; Rice is more sensitive for larger samples; √n overestimates k for big n.

Half-open intervals. Conventional intervals are [a, b) — the lower bound is included, the upper bound is not. A value equal to b goes in the next bin.

Article — Class Width Calculator

Class width calculator: how to size histogram bins

Class width is the span of each interval in a histogram or frequency table, found by dividing the data range by the number of classes: w = (max − min) ÷ k. Most statisticians round w up to ensure every data point lands inside a bin.

Picking the right class width sits at the heart of every histogram. Too wide and you flatten useful structure; too narrow and you trade signal for noise. The good news is that a single line of arithmetic, paired with one of three classic rules for choosing k, gives you a defensible answer almost every time.

What is class width?

Class width is the constant difference between successive interval boundaries in a grouped frequency distribution. If a histogram has bins at 10–20, 20–30, 30–40, the class width is 10. Pick it well and the bars across the histogram tell a clear story about where the data piles up; pick badly and the same dataset can look bimodal, unimodal, or shapeless depending on how you cut it.

The class width carries no information about the data itself. It is purely a presentation choice. That said, the choice changes how easy it is to read the underlying distribution, so it deserves more thought than it usually gets.

Did you know

Herbert Sturges published his rule for picking k in 1926 in a one-page paper called "The Choice of a Class Interval". It was the first mathematical proposal for what had always been done by eye, and a century later it remains the default in introductory textbooks.

The class width formula

The formula is one line: w = (max − min) ÷ k, where max and min are the largest and smallest observations in the raw data and k is the number of intervals you want. Three concrete examples:

  • Test scores 10 to 95, k = 6: w = 85 ÷ 6 = 14.17 → round to 15.
  • Heights 150 to 200 cm, k = 8: w = 50 ÷ 8 = 6.25 → round to 7 cm.
  • Wait times 1 to 60 min, k = 9: w = 59 ÷ 9 = 6.56 → round to 7 min.

Rounding direction matters. Round up and the k intervals always cover the full range, with the last bin extending slightly past max. Round down and the k intervals fall short, leaving the maximum value with nowhere to go. We will come back to this in a moment.

Choosing the number of classes

The "right" number of classes depends on how much data you have. Three rules dominate the literature: Sturges, Rice, and the square-root rule. Each gives a different k for the same n, but they agree to within a bin or two for most practical sample sizes.

Number-of-classes shortcuts
Sturges k = ⌈log₂(n) + 1⌉
Rice k = ⌈2 · n^⅓⌉
Square root k = ⌈√n⌉
Scott w = 3.5σ ÷ n^⅓

Sturges is the textbook default and assumes a near-normal distribution. Rice is less sensitive to distribution shape and tends to give larger k for big samples. The square-root rule is the easiest to remember but can overshoot for n in the thousands. Scott's rule skips k entirely and gives the width directly, but it needs the sample standard deviation, which is one extra calculation away.

Class width rounding rules

Three rounding conventions sit on the table for class width. Round up (ceiling) is the statistical standard. Round to the nearest whole number gives smaller bins but can leave the largest observation outside the last interval. Round down is rarely used outside specific cases with discrete data.

Don't round down

If your data range is 85 and you compute w = 14.17 across 6 classes, rounding to 14 gives total coverage of 84 — short of the range. The maximum value of 95 falls outside the last bin (10 + 14×6 = 94). Round up to 15 instead and the bins cover 10 to 100 cleanly.

For continuous data, always round up. For discrete data (whole-number counts), you can sometimes round to the natural unit — if all observations are integers, a width of 5 makes more sense than 4.7. The calculator above defaults to round-up; switch the rounding rule control to compare.

Sturges, Rice, and √n rule comparison

Sample size matters more than people expect. Here is what each rule produces across common dataset sizes, with the recommended pick:

  • n = 50: Sturges 6, Rice 8, √n 8. Sturges fits a small sample best.
  • n = 200: Sturges 9, Rice 12, √n 15. Crossover point — try both.
  • n = 1,000: Sturges 11, Rice 20, √n 32. Rice tracks reality more closely.
  • n = 10,000: Sturges 14, Rice 44, √n 100. √n produces too many bins.
  • n = 100,000: Sturges 18, Rice 93, √n 317. Use Rice or Scott.
Did you know

For the heaviest datasets — millions of observations — modern visualisation libraries (matplotlib, ggplot2, Plotly) default to the Freedman-Diaconis rule: w = 2·IQR ÷ n^⅓. It uses the interquartile range instead of the full range, which makes it robust to outliers and is the only rule that actively adapts to distribution shape.

Building a frequency distribution step by step

Once you have a class width, building the table is mechanical. Take 50 exam scores with min = 10, max = 95. Sturges gives k = ⌈log₂(50) + 1⌉ = 6. Class width = 85 ÷ 6 = 14.17 → round up to 15. The intervals are 10–25, 25–40, 40–55, 55–70, 70–85, 85–100. Count how many scores fall in each interval and you have the frequency distribution.

One subtle issue: a score of exactly 25 — does it belong to the first bin or the second? The standard convention in statistics is [a, b): include the lower bound, exclude the upper. So 25 goes in the 25–40 bin, not 10–25. Be consistent across all bins to avoid double counting.

Tip

Pick a class width that matches your reporting unit. If your data is in dollars and you'll round to the nearest five, choose a width that's a multiple of 5 — 5, 10, 15, 25. The histogram becomes far easier for non-statisticians to read.

Common class-width mistakes

Five errors keep appearing in student lab reports and undergraduate dissertations. None are subtle, all are avoidable.

  • Rounding down — the largest data point ends up outside any bin.
  • Letting outliers dominate — one extreme value bloats the range and the bin width.
  • Inconsistent boundary convention — values on a boundary get counted twice or not at all.
  • Using the wrong rule for n — Sturges for n = 10,000 gives just 14 bins, which can hide structure.
  • Forgetting decimals — for continuous measurements, w = 0.25 or 1.5 is fine; insisting on whole numbers can blur the picture.

The Freedman-Diaconis rule (w = 2·IQR ÷ n^⅓) sidesteps the outlier problem because the interquartile range is unaffected by extreme values. If your data has heavy tails or known outliers, prefer it over Sturges or Rice.

FAQ

Class width (w) is the span of each interval in a frequency distribution or histogram. It is computed as the data range divided by the number of classes: w = (max − min) / k. Most statisticians round the result up to the next whole unit so every data point lands inside an interval.
For datasets smaller than 200 observations, Sturges' rule (k = ⌈log₂ n + 1⌉) is the textbook default. For larger samples, Rice (k = ⌈2 · n^⅓⌉) often gives a clearer histogram. The square-root rule (k = ⌈√n⌉) is quick to compute but overestimates k for n above a few hundred.
Rounding up (ceiling) guarantees that k intervals of width w cover the full data range. If 14.17 rounds to 14 and k is 6, total coverage is 84 — short of an 85-unit range, leaving the maximum value outside the last bin.
Yes. Continuous measurements such as height, weight, or temperature often use widths like 0.5, 2.5, or 0.1. Round to whatever decimal place makes the histogram easy to read in your units.
Both are valid. Sturges assumes a near-normal distribution and works best for small to medium samples. Rice is less sensitive to normality and tends to give more bins for the same n, which can reveal structure in larger datasets.