What this calculator does
Class width is the data range divided by the number of classes. Data running from 12 to 98 split into 8 classes gives a width of 10.75, which in practice would be rounded up to 11 or 15 for readable bin edges.
The harder question is how many classes to use, and Sturges rule gives a starting answer from the sample size alone: roughly log₂n plus 1. For 50 observations that suggests 7 classes. It is a guideline rather than a rule, and it is known to suggest too few classes for large data sets, so treat it as a first try to adjust from.
The formula
The range is the maximum minus the minimum, and dividing by the desired class count gives the width. Sturges rule suggests a class count as the ceiling of log₂n plus 1, and the corresponding width is shown alongside. Both widths are exact divisions, so rounding up to a convenient number is normal and usually improves readability.
| Term | Meaning |
|---|---|
| Class width | The span of each histogram bin. |
| Sturges rule | A class count suggestion of ⌈log₂n + 1⌉, based on sample size alone. |
| Range | Maximum minus minimum, the total span the classes must cover. |
| Bin edges | The boundaries between classes, which are easier to read when they land on round numbers. |
The inputs explained
| Field | What to enter |
|---|---|
| Minimum value | The smallest value in the data. |
| Maximum value | The largest value in the data. |
| Desired number of classes | How many classes you want. Between 5 and 20 covers most cases. |
| Sample size (for Sturges’ rule) | Sample size, used only for the Sturges rule suggestion. |
When to use it
Building a histogram
Class width and count determine whether a histogram reveals the distribution shape or obscures it.
Choosing how many bins
Too few classes hide structure and too many produce noise, and Sturges gives a defensible starting point.
Matching an existing report
Reproducing a published histogram means matching its class boundaries, which starts from the width.
Worked examples
Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.
How does the class count change the width?
The same range divided into different numbers of classes.
| Desired classes | Class width | Range | Sturges’ suggested classes (from n) |
|---|---|---|---|
| 5 classes | 17.200 | 86.000 | 7 |
| 6 classes | 14.333 | 86.000 | 7 |
| 8 classes | 10.750 | 86.000 | 7 |
| 10 classes | 8.600 | 86.000 | 7 |
Questions
How many classes should a histogram have?
Usually between 5 and 20, with the right number depending on sample size and how much structure the data has. Sturges rule suggests ⌈log₂n + 1⌉, which gives 7 for 50 observations and 11 for 1,000. Try a couple of options and pick the one that shows the shape most clearly.
Should I round the class width?
Almost always. A width of 10.75 produces bin edges like 12, 22.75, 33.5, which nobody can read at a glance. Rounding up to 11 or 15 gives clean boundaries. Round up rather than down, so the classes still cover the full range.
Is Sturges rule reliable?
It is a reasonable starting point for moderate sample sizes but is known to suggest too few classes for large data sets, because it assumes roughly normal data. For large or skewed data, the Freedman-Diaconis rule, which uses the interquartile range, generally performs better.
What happens if the classes are too wide or too narrow?
Too wide and the histogram flattens into a few bars that hide any real structure, including bimodality. Too narrow and it becomes a spiky mess where random variation looks like signal. Both failures are common, which is why trying more than one width is worth the effort.
For mean and spread from a completed frequency table, see the grouped data calculator. For the full summary of raw data, see the descriptive statistics calculator.