unspurious.calculators

Foundations · Frequency tables

Class Width Calculator

The class width is how wide each bar of a histogram is — the size of each interval in a grouped frequency table. The recipe is simple: class width = range ÷ number of classes, rounded up to a tidy value. Give it your data (or just the lowest and highest values) and a number of classes, and this builds the intervals, counts the frequencies and draws the histogram — while being honest that the width you pick can change the very shape the histogram shows.

No firm rule fixes the number of classes — 5 to 20 is the usual range. The quick-pick buttons apply common rules of thumb; the right answer is whichever width tells the truth about the data without inventing detail.

Result

In plain English

To turn raw numbers into a histogram you chop the range into equal slices and count how many values fall in each. The class width is the size of one slice. It follows from two decisions — the span of the data and how many bars you want — but the second of those is yours to make, and it quietly controls the picture more than people expect.

class width
The size of each interval: range ÷ number of classes, then rounded up so the classes comfortably cover every value. Rounding up, never down, guarantees nothing falls off the end.
class (bin)
One interval of the histogram, e.g. 11–26. Its frequency is the count of values landing inside it. Boundaries are half-open — a value on a boundary goes to the upper class — so each value is counted once.
range
Maximum minus minimum. The total span the classes have to cover.
number of classes
How many bars. Common rules of thumb: Sturges (1 + log₂n), the square-root rule (√n) and Rice (2·∛n). They are starting points, not laws.
the catch
Too few classes oversmooths and can hide a second peak; too many turns random wobble into fake structure. The same data can look unimodal or bimodal purely from the width — so a histogram is a choice, not just a fact.
equal width matters
These formulas assume every class is the same width. If you use unequal classes, the bar height must be frequency ÷ width (a density), or the wider bars will look misleadingly tall.

Frequently asked

How do you calculate class width?

Take the range of the data — the maximum minus the minimum — and divide by the number of classes you want, then round the result up. For example, values from 11 to 98 give a range of 87; aiming for 6 classes, 87 ÷ 6 = 14.5, which rounds up to a class width of 15. You round up rather than to the nearest value so that the classes, starting at the minimum, always stretch far enough to include the maximum. Round to the same precision as your data (whole numbers for integer data, one decimal for one-decimal data, and so on).

How many classes should I use?

There is no single correct number, but a few rules of thumb help you start. Sturges’ rule sets classes = 1 + log₂n (about 6 for 30 values, 8 for 100); the square-root rule uses √n; and Rice’s rule uses 2·∛n, which tends to suggest more classes for large samples. Sturges assumes roughly bell-shaped data and under-bins large or skewed datasets, so for big samples the square-root or Rice rule is often better. Most histograms end up with somewhere between 5 and 20 classes — try a couple and keep the one that shows the real structure without inventing noise.

Why round the class width up and not down?

Because rounding down can leave the classes too short to reach the largest value. If the exact width is 14.5 and you round down to 14, six classes starting at 11 only reach 11 + 6×14 = 95 — but the data go up to 98, so the top values have nowhere to sit. Rounding up to 15 reaches 11 + 6×15 = 101, comfortably covering everything. The small amount of overshoot at the top is harmless; a class that is too narrow to hold the data is not.

Can the class width change what the histogram shows?

Yes, dramatically — this is the part most tutorials skip. A wide class width (few bars) smooths the data and can merge two genuine peaks into one, hiding structure; a narrow width (many bars) lets random sampling wobble masquerade as real features. The same dataset can be made to look unimodal or bimodal, smooth or spiky, just by changing the width. That is why a histogram is best read as one view among several: if a pattern only appears at one specific bin width, treat it with suspicion and try a few widths before believing it.