Class Width Calculator
Enter the minimum value, maximum value, and number of classes to find the class width (class interval) for a frequency distribution or histogram. The calculator gives you the exact class width, a rounded "nice" width for cleaner boundaries, the suggestion from Sturges' rule, and a full table of class limits and midpoints so you can build your histogram immediately.
What is class width?
Class width, also called class interval or bin width, is the size of each bar in a histogram or frequency distribution table. Every class covers a range of values from its lower boundary (inclusive) to its upper boundary (exclusive), and all classes in a standard histogram have the same width. When you group raw data into classes and count how many values fall in each one, you create a frequency distribution that reveals the shape of your dataset at a glance.
The class width formula
The formula is straightforward: Class Width = (Maximum - Minimum) / Number of Classes. The numerator is the range of your data and the denominator is how many bars you want. For example, if your lowest test score is 45 and your highest is 90 and you want 9 classes, the range is 45 and the class width is 45 / 9 = 5. You would then create intervals 45-50, 50-55, 55-60, and so on up to 85-90.
How many classes should you use? Sturges' rule
Choosing the right number of classes is as important as calculating the width itself. Too few classes and you lose detail; too many and the histogram becomes noisy and hard to read. Sturges' rule offers a quick starting point: k = 1 + 3.322 x log10(n), where n is the number of data points. Round the result up to the nearest whole number. For 30 data points, Sturges gives k = 1 + 3.322 x log10(30) = 1 + 4.91 = 5.91, so you would use 6 classes. For 100 data points it gives about 8 classes, and for 1000 about 11. Most textbooks recommend staying between 5 and 20 classes for everyday datasets.
Rounding class width and setting boundaries
The exact class width often comes out as an awkward decimal. In practice it is easier to round up to a convenient number such as 0.5, 1, 2, 5, or 10 depending on your data scale. Rounding up, rather than rounding to nearest, ensures that all data points still fit within the range. After setting the class width, build your boundaries by starting at the minimum value (or a round number just below it) and adding the class width repeatedly. For example, with min = 45 and class width = 5, your boundaries are 45, 50, 55, 60, 65, 70, 75, 80, 85, 90. The first class is [45, 50), the second is [50, 55), and so on, where the bracket means the lower value is included and the parenthesis means the upper value is not.
Suggested number of classes by sample size (Sturges' rule)
| Sample size (n) | Suggested classes (k) | Guidance |
|---|---|---|
| 5 | 3 | Very small sample - use 3-4 classes |
| 10 | 4 | Small sample - 4-5 classes |
| 20 | 5 | Use 5-6 classes |
| 30 | 6 | 5-7 classes typical |
| 50 | 7 | 6-8 classes |
| 100 | 8 | 7-10 classes |
| 200 | 9 | 8-11 classes |
| 500 | 10 | 9-12 classes |
| 1000 | 11 | 10-13 classes |
| 5000 | 13 | 12-15 classes |
Sturges' rule: k = ceil(1 + 3.322 x log10(n)). These are starting suggestions, not strict rules.
Frequently asked questions
What is the difference between class width and class interval?
They are the same thing. Class width, class interval, bin width, and bucket size all refer to the numeric size of each group in a frequency distribution or histogram. The terms are used interchangeably in most statistics textbooks.
Does class width have to be the same for all classes?
In a standard histogram, yes. Using equal class widths makes the areas of the bars proportional to the frequencies, which is what you want for a fair visual comparison. Unequal widths are occasionally used for open-ended classes (like "65 and over" in age data), but they require adjusting bar heights by frequency density rather than raw count, which complicates interpretation.
What is Sturges' rule and when should I use it?
Sturges' rule (k = 1 + 3.322 x log10(n)) gives a suggested number of classes based on sample size. It works best for roughly normal, unimodal distributions with moderate sample sizes (around 30 to 200). For very large datasets or highly skewed data, other rules like Scott's rule or the Freedman-Diaconis rule often give better results. Use Sturges as a starting point, then adjust by looking at the histogram.
Should I round the class width up or to the nearest value?
Always round up when the goal is to ensure all data points are covered. If you round down and the resulting boundaries fall short of the maximum value, you will have data points that do not fit into any class. Rounding up to a convenient number like 5 or 10 also makes the histogram easier to read.
How do I find the class width from a histogram already drawn?
Read the lower boundary of the first class and the lower boundary of the second class from the horizontal axis, then subtract: class width = second lower boundary minus first lower boundary. All bars in a standard histogram share the same width, so any two adjacent boundaries will give the same answer.
What is a class midpoint and why does it matter?
The midpoint is the average of the lower and upper boundaries of a class: midpoint = (lower + upper) / 2. Midpoints represent the entire class in calculations like the grouped mean, grouped variance, and grouped standard deviation. When you compute these statistics from a frequency table, you multiply each midpoint by the frequency of its class.