Skip to main content
v2026.11,858 entries · CC-BY 4.0

How to Calculate Class Width: Formula and Worked Example

Class width = (max − min) ÷ number of classes, rounded up. Worked example with boundaries, plus Excel, R and Python formulas.

Written and maintained by CASRAI Editorial Board

Last updated

Class width is the size of each interval in a grouped frequency distribution or histogram. Calculate it as (maximum value − minimum value) ÷ number of classes, then round up to a convenient whole number. Rounding up, rather than to the nearest value, guarantees that the classes together cover every observation. The sections below show the formula, a fully worked example with the arithmetic and the resulting class boundaries, and the same calculation in Excel, R and Python.

What is class width?

Class width (also called class size or, in histograms, bin width) is the distance from the lower boundary of one class to the lower boundary of the next. In a frequency distribution every class has the same width, so the width is a single number that fixes where every class starts and ends. In a histogram it is the width of each bar. Textbooks usually recommend roughly five to 15 classes: OpenStax Introductory Statistics notes that many histograms consist of five to 15 bars or classes for clarity.

How to calculate class width (formula)

Use this formula, as given in the LibreTexts Introductory Statistics (Citrus College) chapter formulas:

Class width = (maximum value − minimum value) ÷ number of classes

  • Maximum value is the largest observation in the data set.
  • Minimum value is the smallest observation.
  • Maximum − minimum is the range of the data.
  • Number of classes (k) is the number of intervals you choose to group the data into.

The same source says to round the result up to the next whole number so that all data values are included. OpenStax describes the same calculation in words: subtract the starting point from the ending value and divide by the number of bars.

Steps:

  1. Find the minimum and maximum and subtract to get the range.
  2. Choose the number of classes k (see the next section).
  3. Divide the range by k.
  4. Round the result up (for example 8.6 becomes 9).
  5. Choose a starting point at or just below the minimum, then add the class width repeatedly to build the class boundaries.

How many classes should you use?

There is no single required number of classes. Two rules of thumb appear in OpenStax Introductory Statistics: keep the histogram to about five to 15 classes, and, as a starting point for the number of bars, take the square root of the number of data values and round to the nearest whole number. For 20 observations the square root is about 4.47, which rounds to 4; because that is under the five-class guideline, the example below uses five classes. Whichever k you pick, state it, because the class width follows directly from it: more classes give a narrower width and a more jagged histogram, fewer classes give a wider width and a smoother one.

Worked example: class width for 20 exam scores

Twenty exam scores, sorted: 52, 55, 58, 61, 63, 64, 67, 68, 70, 71, 73, 74, 76, 79, 81, 83, 86, 88, 91, 95. This is an illustrative data set invented for this page.

  1. Maximum = 95, minimum = 52, so range = 95 − 52 = 43.
  2. Choose k = 5 classes.
  3. Divide: 43 ÷ 5 = 8.6.
  4. Round up: class width = 9. Check: 5 × 9 = 45, which is at least the range of 43, so the five classes cover all the data. Rounding down to 8 would give 5 × 8 = 40, which is less than 43, and the top scores would fall outside the last class.
  5. Choose a starting point below the minimum. Because the scores are whole numbers, starting at 51.5 puts every score safely inside a class, and the boundaries are 51.5, 60.5, 69.5, 78.5, 87.5 and 96.5 (add 9 each time).
Class (boundaries) Scores in the class Frequency
51.5 to under 60.5 52, 55, 58 3
60.5 to under 69.5 61, 63, 64, 67, 68 5
69.5 to under 78.5 70, 71, 73, 74, 76 5
78.5 to under 87.5 79, 81, 83, 86 4
87.5 to under 96.5 88, 91, 95 3

The frequencies add to 3 + 5 + 5 + 4 + 3 = 20, matching the number of scores. The class intervals follow the convention OpenStax states for histograms: a value is counted in a class if it falls on the left boundary, but not if it falls on the right boundary.

Continuous data versus whole-number data

OpenStax shows both cases. For continuous data (its heights example), the minimum is 60 and the maximum is 74; it starts at 59.95 and ends at 74.05, giving a range of 14.1, and with 8 bars the width is 14.1 ÷ 8, about 1.76, which it rounds up to 2. For discrete whole-number data (its second example), it starts at 0.5 and uses a width of 1, so each integer sits in the centre of its own bar.

You may also meet a variant, (maximum − minimum + 1) ÷ number of classes, used for whole-number data; the LibreTexts Geraghty text applies it to data from 67 to 125 with 5 intervals: (125 − 67 + 1) ÷ 5 = 11.8, rounded up to 12. For our exam scores the two versions agree (43 ÷ 5 = 8.6 and 44 ÷ 5 = 8.8 both round up to 9), but they can differ by one at other values, so follow the formula your course or software uses and apply it consistently.

Class width versus class limits and class boundaries

These three terms are easy to confuse:

  • Class width is one number: the size of each interval.
  • Class boundaries are the exact edges between classes (51.5, 60.5, 69.5 and so on above). Class width is the difference between consecutive lower boundaries.
  • Class limits are the stated smallest and largest whole values in a class, for example 52 to 60 and 61 to 69 for the first two classes above. The lower limits 52 and 61 differ by 9, which is also the class width.

Interpreting the result: what the width means for your histogram

Situation What it means
Number of classes between about 5 and 15 Within the range OpenStax gives for a clear histogram.
Classes times width is less than the range The width was rounded down or k is too small; some values fall outside the classes. Round up.
Classes times width is much more than the range Empty space at the ends of the histogram; consider fewer classes or a tighter starting point.
Same width for every class Required for a standard histogram so bar heights can be compared directly.

Assumptions and common mistakes

  • Rounding to the nearest value instead of up. For this data, rounding 8.6 down to 8 gives 5 × 8 = 40, which is less than the range of 43, so the top scores fall outside the last class. Always round up.
  • Starting exactly at the minimum. OpenStax advises a starting point below the smallest data value so the minimum is not sitting on a boundary.
  • Using the number of observations as the number of classes. k is the number of intervals, not the sample size.
  • Unequal widths in a standard histogram. The formula assumes equal-width classes.
  • Mixing up the boundary rule. Decide whether the left or right edge is inclusive and apply it to every class.

How to report it

State the class width, the number of classes and the boundary convention in the text or the figure note, so readers can reproduce the histogram. Example wording for the exam scores above:

Exam scores (N = 20) ranged from 52 to 95. Scores were grouped into five classes of width 9, beginning at 51.5; a score on a lower boundary was counted in the class it begins.

See the histograms in R guide for drawing the figure, and ogive for the cumulative version built from the same classes.

How to calculate class width in Excel, R or Python

Excel

With the scores in cells A2:A21 and the number of classes in D1 (5):

=ROUNDUP((MAX(A2:A21)-MIN(A2:A21))/D1,0)

This returns 9.

R

x <- c(52,55,58,61,63,64,67,68,70,71,73,74,76,79,81,83,86,88,91,95)
k <- 5
width <- ceiling(diff(range(x)) / k)   # 9
breaks <- 51.5 + width * 0:k           # 51.5 60.5 69.5 78.5 87.5 96.5
hist(x, breaks = breaks, right = FALSE)

Python

import math
x = [52,55,58,61,63,64,67,68,70,71,73,74,76,79,81,83,86,88,91,95]
k = 5
width = math.ceil((max(x) - min(x)) / k)   # 9
breaks = [51.5 + width * i for i in range(k + 1)]
counts = [sum(b0 <= v < b1 for v in x) for b0, b1 in zip(breaks, breaks[1:])]
print(width, counts)   # 9 [3, 5, 5, 4, 3]

Frequently asked questions

How do you calculate class width?

Subtract the minimum from the maximum, divide by the number of classes, and round up. For a range of 43 and 5 classes, 43 ÷ 5 = 8.6, so the class width is 9.

Why round class width up?

Rounding up makes the classes together span at least the full range of the data, so no value is left out. With a width of 9, five classes span 45 units; a width of 8 would span only 40 of the 43 units needed.

How many classes should a frequency distribution have?

OpenStax suggests five to 15 for a clear histogram, with the square root of the number of data values as one starting guess for the number of bars.

Is class width the same as bin width?

Yes in practice: class width in a frequency table and bin width in a histogram both mean the size of each equal-width interval.

Can you find class width from the class limits?

Yes. Subtract one lower class limit from the next lower class limit. In the example, 61 − 52 = 9.

Sources

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about How to Calculate Class Width: Formula and Worked Example

Ask your first 2 questions free below. Subscribers get 150 a day for $29 a month.

An AI assistant specialized in research administration. It cites the sources behind every answer, labels web answers and says when it can't answer.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays free to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →

Ask CASRAI · Regulatory Radar

Research-admin question? Get an answer that links its sources.

An AI assistant specialized in research administration. Every answer links its sources to check before you act. 2 questions free, no account. $29/month after.

  • Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.
  • Every answer numbers its sources and links each one, so you can check the source yourself.