How Many Bins Should a Histogram Have?
A histogram is only as honest as its bins. Too few and the shape disappears; too many and random noise looks like structure. This guide explains three standard rules for choosing the bin count, shows what each gives for a real example, and explains how to read the result.
What a histogram shows
A histogram takes a list of measurements of one variable, divides the range into equal-width intervals called bins, and counts how many values fall in each. The height of each bar is that count (the frequency). Because the X axis is a continuous scale, neighbouring bars touch. That is the key visual difference from a bar chart, where separate categories are drawn with gaps.
Histograms are used to check the centre of a data set, its spread, whether it is symmetric or skewed, whether it has one peak or several, and whether any values sit far from the rest. They are often the first plot to make with new data, before choosing a statistical test, because many tests assume a roughly bell-shaped distribution.
Why the number of bins matters
The bin width is a smoothing choice. With very wide bins everything piles into a few bars and a clearly two-peaked distribution can look like a single hump. With very narrow bins each bar holds only a few values, counts jump up and down randomly, and the real shape is buried in noise. A good histogram uses enough bins to show the structure and few enough that each bar holds a meaningful number of observations.
There is no single correct answer, which is why several rules exist. All of them make the number of bins grow with the sample size, because more data supports finer detail.
Three standard rules, with numbers
Sturges’ rule sets the number of bins k = log₂(n) + 1. It is simple and works well for roughly normal data up to a few hundred values. Rice’s rule uses k = 2 × n^(1/3), which gives more bins for larger samples. Freedman–Diaconis sets the bin width h = 2 × IQR × n^(−1/3), where IQR is the interquartile range, and is robust to outliers because it uses the quartiles rather than the standard deviation.
For the 120 student heights in the example below, Sturges gives log₂(120) + 1 = 7.9, so 8 bins; Rice gives 2 × 120^(1/3) = 9.9, so 10 bins. With a standard deviation near 9 cm and an IQR of about 12 cm, Freedman–Diaconis gives a width of 2 × 12 × 0.2 = 4.9 cm, which over a range of roughly 50 cm is about 10 bins. All three agree to within a couple of bins, which is typical for well-behaved data.
| Rule | Formula | Bins for n = 120 |
|---|---|---|
| Sturges | log₂(n) + 1 | 8 |
| Rice | 2 × n1/3 | 10 |
| Freedman–Diaconis | width = 2 × IQR × n−1/3 | about 10 |
The example: 120 student heights
The histogram below uses 120 simulated heights centred on 168 cm. Plotiq starts from Sturges’ rule and then rounds the bin width to a convenient value (1, 2, 2.5 or 5 times a power of ten) so the bin edges land on round numbers such as 160, 165 and 170 instead of awkward decimals. You can override it by typing a number of bins.
Reading the shape
Look at four things. The centre is where the tallest bars sit. The spread is how far the bars extend; compare it with the standard deviation. The shape may be symmetric, skewed right (a long tail towards large values, common for incomes and reaction times) or skewed left. Count the peaks: two distinct peaks often mean you are measuring two groups mixed together, such as two machines or two species. Finally, check for outliers, isolated bars far from the rest, which may be genuine or data-entry errors.
The mean and median together tell you about skew. In a symmetric distribution they are almost equal. In a right-skewed distribution a few large values pull the mean above the median. When they differ noticeably, report the median or transform the data (a log transform often fixes right skew).
Common histogram mistakes
Using pre-counted category totals as if they were raw data (a histogram needs the individual measurements); choosing bins to make a result look clean; leaving the Y axis unlabelled (say whether it is a count or a proportion); and using different bin widths when comparing two groups, which makes the shapes incomparable. When you plot two groups on one chart, use the same bins for both, as the tool does automatically.
For small samples, below about 30 values, a histogram is unstable and changes noticeably if you shift the bin edges. A box plot or a plot of the individual points is more reliable at that size.
Frequently asked questions
- What is the best number of bins?
- There is no single best number. Start with Sturges’ rule or about the square root of n, then try a few more or fewer bins. The right choice shows the overall shape without random gaps between bars.
- Can a histogram have gaps between bars?
- Gaps are allowed only when a bin genuinely contains no values. Otherwise adjacent bars should touch, because the X axis is continuous.
- Should the Y axis be count or density?
- Use counts when comparing groups of the same size and when readers want actual numbers. Use density when groups have different sizes or you overlay a theoretical curve.
- How many values do I need?
- Around 30 is the practical minimum; 100 or more gives a stable shape. With fewer values use a box plot or show the raw points.
Keep reading
- Box Plots Explained: How to Read a Box-and-Whisker Plot – How to read and make a box-and-whisker plot: median, quartiles, the 1.5 × IQR rule for outliers, a worked example with nine values, and how box plots compare groups.
- Which Chart Should I Use? – A practical decision guide for choosing between line, bar, scatter, histogram, box and pie charts, with the question each one answers and the mistakes to avoid.
- Error Bars: SD, SE or Confidence Interval? – What error bars show, how SD, SE and 95% confidence intervals differ, how to calculate each from raw data, and which one to put on your graph.
Written and reviewed by the Plotiq Editorial Team. Spotted a mistake? Tell us and we will correct it. See About Plotiq for how these guides are made.