Skip to content
simstat.com Statistics by simulation

How to Find Class Width: Formula, Rounding and Decimals

Here is how to find class width for a grouped frequency table: subtract the smallest value from the largest, divide by the number of classes, and round the result up to the precision of the data (the next whole number for whole numbers, the next 0.1 for data with one decimal). If the division comes out exact, add one unit so that the last class still reaches the maximum. In a table that already exists, the class width is the difference between two consecutive lower class limits.

Last updated · by the simstat.com editorial team · How we write

What class width is

A grouped frequency distribution sorts numbers into classes: intervals such as “10.4 to 14.3 miles per gallon”, each with a count of the values that fall in it. The class width is the distance from the start of one class to the start of the next. When the classes follow on from each other with the same width, they tile the range of the data without gaps or overlaps, and the bars of the histogram are directly comparable.

Two quantities fix the width: how many classes you want (k) and how far the data spread (the range, max − min). Divide one by the other and you have a first answer. The rest of this guide is about the two details that trip people up: rounding the answer correctly, and reading the width back off a finished table.

The class width formula

The textbook class width formula divides the range by the number of classes. Jones (n.d.) puts it as “Find the class width by dividing the range by the number of classes and rounding up”:

w≈max⁡−min⁡kw \approx \frac{\max - \min}{k}

Here max and min are the largest and smallest data values and k is the number of classes. The division rarely gives a convenient number, so the result is rounded, and the direction matters (next section). Written out with the rounding, the rule our frequency distribution calculator uses is:

w=(⌊max⁡−min⁡k u⌋+1)uw = \left( \left\lfloor \frac{\max - \min}{k\,u} \right\rfloor + 1 \right) u

where u is the precision unit of the data, the smallest step in which values are recorded: 1 for whole numbers, 0.1 for one decimal place, 0.01 for two. The brackets ⌊ ⌋ mean “round down to a whole number”. Dividing by u counts the range in units, and adding one before multiplying back rounds the width up to the next unit, even when the division is already exact.

Choosing the number of classes

Instructions often fix k for you. If not, two guidelines are common:

k=⌈log⁡2n+1⌉k = \lceil \log_2 n + 1 \rceil

Treat Sturges’ k as a starting point. Hyndman (1995) argues that “the argument leading to Sturges’ rule is wrong” and notes that the rule is known to give oversmoothed histograms, especially for large samples (citing Scott, 1992); for moderate n (less than 200) it gives results similar to better-founded rules, “However, it does not work for large n.” It grows slowly: 11 classes for 1,000 values. Even R uses it loosely: the hist() documentation says the number “is a suggestion only; as the breakpoints will be set to pretty values”. For the mpg data below, R draws 5 bars of width 5 from 10 to 35, not 6.

Hyndman (1995) also lists rules that set the width directly. The Freedman–Diaconis rule is h = 2 × IQR × n^(−1/3), with IQR the interquartile range. For the mpg data the IQR is 7.375 (R’s default quartiles), so h ≈ 4.65, which also implies 6 classes. Our IQR calculator computes the quartiles with R’s method among others.

The rounding rule: always round up

Round the class width up, never to the nearest value. Jones (n.d.) is blunt: “You must round up, not off.” The reason is coverage. Starting at the minimum, k classes of width w cover values up to, but not including, min + k × w, and that has to be beyond the maximum. Jones states the condition: “The starting point plus the number of classes times the class width must be greater than the maximum value.” Rounding down shrinks k × w below the range, so the largest values fall off the end.

When the division is already exact

Rounding up does nothing when the range divides exactly, and then the classes are one unit short. Take whole numbers from 20 to 50 in 6 classes: 30 ÷ 6 = 5 exactly. With width 5, the classes run 20–24, 25–29 and so on, and the last one ends at 49. The maximum, 50, belongs to no class. Jones (n.d.) covers this case: “you can either add one to the number of classes or add one to the class width.” Adding one to the width gives 6, and 6 classes then end at 55.

Geraghty (n.d.) avoids the special case another way: he divides max − min + 1 by k and rounds up (to the next whole number). For whole numbers this always gives the same width as “round up, and add one if exact”. His own example, 67 to 125 in 5 classes, gives 11.8 by his formula and 11.6 by ours, and both round up to 12.

The same problem appears with decimals. In 5 classes, the mpg range gives 23.5 ÷ 5 = 4.7, already a whole number of tenths. Classes of width 4.7 starting at 10.4 would end at 33.8, and the maximum 33.9 would be left out; width 4.8 reaches 34.3. Jones and Geraghty state the add-one rule for whole numbers. Applying it in units of 0.1 or 0.01, as our calculator does, is our own extension: it is Jones’s condition (start + k × w greater than the maximum) applied in the data’s own unit, not a rule either source states for decimals.

Class width with decimals

For data with decimals, round up to the data’s own precision; you need not round up to a whole number. The mpg values are recorded to one decimal, so u = 0.1: 23.5 ÷ 6 ≈ 3.9167, which rounds up to 4.0. Write it as 4.0, not 4: the trailing zero tells the reader the limits are in tenths, so the next lower limit is 10.4 + 4.0 = 14.4.

With two decimals the unit is 0.01. The rear axle ratio of the same 32 cars (mtcars$drat in R) runs from 2.76 to 4.93. In 6 classes, 2.17 ÷ 6 ≈ 0.36167, which rounds up to 0.37; the classes are 2.76–3.12, 3.13–3.49, and so on up to 4.61–4.97. In 7 classes the division is exact, 2.17 ÷ 7 = 0.31, so the width is 0.32: with 0.31, the last class would end at 4.92, just below the maximum.

A wider, rounder width, such as 5 for the mpg data, is also allowed, as long as it is at least the width the rule gives (4.0 here), and Geraghty (n.d.) recommends “rounding UP to a convenient value”. The number of classes then follows from the width, and a round starting point below the minimum keeps the limits round too.

Worked example: mtcars fuel consumption

The steps below show how to find class width for real data: the fuel consumption, in miles per US gallon, of 32 cars in R’s mtcars data set, “extracted from the 1974 Motor Trend US magazine” (R Core Team, 2024). They are the default data of our calculator.

Worked example: class width for mtcars mpg

Step 1: precision. Every value has one decimal place, so the unit is u = 0.1.

Step 2: number of classes. n = 32, so Sturges’ rule gives k = ⌈5 + 1⌉ = 6.

Step 3: range. The smallest value is 10.4 and the largest 33.9, so the range is 33.9 − 10.4 = 23.5.

Step 4: divide. 23.5 ÷ 6 ≈ 3.9167.

Step 5: round up to the next multiple of 0.1: the class width is 4.0. The quotient was not exact, so no unit is added.

Step 6: check. The first class starts at 10.4; adding 4.0 repeatedly gives the other lower limits. The last class, 30.4–34.3, contains the maximum 33.9.

The resulting table, with class limits (the smallest and largest values a class can hold at the data’s precision), class boundaries (half a unit outside the limits) and counts:

ClassClass limitsClass boundariesFrequency
110.4–14.310.35–14.354
214.4–18.314.35–18.3510
318.4–22.318.35–22.359
422.4–26.322.35–26.354
526.4–30.326.35–30.351
630.4–34.330.35–34.354

The calculator opens with these data and settings, so its step-by-step box shows the same working. Type 5 as the number of classes to see the “add one unit” case, where the width becomes 4.8.

How to identify class width in a frequency table

Given a finished table, find the class width by subtracting one lower class limit from the next. In the table above, 14.4 − 10.4 = 4.0. Consecutive lower boundaries give the same answer: 14.35 − 10.35 = 4.00. Check a second pair to confirm that the classes have equal width.

Do not subtract the lower limit of a class from its own upper limit. For the first class, 14.3 − 10.4 = 3.9, one unit less than the true width, because the limits are the first and last values a class can hold, and the gap of one unit to the next class is part of the width. Jones (n.d.) builds upper limits the same way, telling you to “subtract one from the lower limit of the second class”.

How to report the class width

State the number of classes, how you chose it, the width and the starting point, so that a reader can rebuild the table:

Fuel consumption of the 32 cars, recorded to 0.1 mpg, ranged from 10.4 to 33.9 mpg. We grouped it into 6 classes (Sturges’ rule) of width 4.0 mpg, starting at the minimum, so the classes run from 10.4–14.3 to 30.4–34.3 mpg.

If you rounded the width up to a convenient value or started below the minimum, say so too: the shape of a histogram can change with the classes.

Common mistakes

Rounding to the nearest value. 3.9167 rounded off is 3.9, and 6 classes of width 3.9 from 10.4 end at 33.7, below the maximum 33.9. Always round up.

Forgetting the exact case. If the range divided by k is already a whole number of units, add one unit (or one class). Otherwise the maximum is left out, as with 20 to 50 in 6 classes.

Rounding decimals to whole numbers by habit. For data in tenths, round up to the next tenth. Rounding up to a whole number is allowed but is a choice of a convenient width, and may mean fewer classes are needed to reach the maximum.

Reading the width as upper minus lower limit. That gives 3.9 instead of 4.0 here. Use consecutive lower limits or consecutive boundaries.

Treating Sturges’ rule as a law. It is a rough default that undercounts classes for large samples (Hyndman, 1995). Try a few values of k and look at the histogram.

Where to go next

Build the full table, with midpoints and relative and cumulative frequencies, in our frequency distribution calculator. To watch a histogram of sample means take shape, read our guide to the sampling distribution and try the sampling distribution simulator. To label each class with its limits, boundaries and midpoint, read how to find class boundaries. More guides and calculators are on the statistics hub.

References

  1. Illowsky, B. & Dean, S. (2023). Introductory Statistics 2e, Section 2.2: Histograms, Frequency Polygons, and Time Series Graphs. OpenStax, Rice University.
  2. Jones, J. (n.d.). Statistics: Grouped Frequency Distributions (Math 170 lecture notes). Richland Community College (undated web page, accessed December 2026).
  3. Geraghty, M. A. (n.d.). 2.5.3: Grouping Numeric Data, in Inferential Statistics and Probability: A Holistic Approach. LibreTexts (undated, accessed December 2026).
  4. Hyndman, R. J. (1995). The problem with Sturges' rule for constructing histograms. Monash University, unpublished note.
  5. R Core Team (2024). hist: Histograms (graphics package documentation). R Foundation for Statistical Computing.
  6. R Core Team (2024). mtcars: Motor Trend Car Road Tests (datasets package documentation). R Foundation for Statistical Computing.

Try it

Related reading