TL;DR
A histogram is a picture of a list of numbers. You cut the range of the numbers into equal-width pieces called bins, count how many numbers land in each bin, and draw one bar per bin with that count as its height. It shows at a glance where the numbers cluster, how spread out they are, and whether there are outliers. It is the first tool to reach for when you meet a new set of measurements.
Builds on: nothing beyond counting and reading a bar chart · Leads to: Probability Density Function, Random Variable, Mean and Variance
Where it's used
Exam results. A teacher has the scores of 200 students. A histogram with bins of 10 points shows whether most students scored in the 60s and 70s, or whether the class split into a strong group and a weak group. The shape tells the teacher more than the average does.
Quality control in a factory. A machine fills bottles to a target of 500 millilitres. Engineers record the fill volume of 1000 bottles and histogram them. A narrow bar pile centred on 500 means the machine is on target. A second, small bump near 480 is a sign that one nozzle is faulty.
Web performance. An engineer records the time each web request took, in milliseconds, over one day. A histogram with bins of 50 ms shows the typical request near 200 ms and a long tail of slow requests past one second. That tail is what users complain about, and an average would hide it.
How it works
Take one tiny list of 10 test scores: 2, 3, 3, 5, 6, 6, 6, 7, 9, 10. Build a histogram with bins of width 2.
- Choose the bins. Split the range from 0 to 10 into pieces of width 2: [0, 2), [2, 4), [4, 6), [6, 8), [8, 10]. A square bracket includes the end point and a round bracket excludes it, so the value 2 goes into [2, 4). Check: the bins cover 0 to 10 with no gaps and no overlaps.
- Go through the list one number at a time. Put each score in the bin it belongs to. The score 2 goes to [2, 4). The score 3 goes there too. Check: every score lands in exactly one bin.
- Count each bin. [0, 2) has 0 scores. [2, 4) has 3 (the 2, 3 and 3). [4, 6) has 1 (the 5). [6, 8) has 4 (the three 6s and the 7). [8, 10] has 2 (the 9 and the 10). Check: 0 + 3 + 1 + 4 + 2 = 10, which matches the 10 scores.
- Draw one bar per bin. The bars sit side by side, the bar for each bin is as wide as the bin, and its height is the count. The tallest bar is [6, 8) with height 4. Check: the bar heights add up to the number of scores.
- Read the picture. Most scores are between 2 and 8, the largest group is 6 to 8, and the bin [0, 2) is empty, a clear gap at the low end. Check: the story you read off the bars matches the list you started with.
Here is the same counting as a table.
| Bin | Scores in bin | Count |
|---|---|---|
| [0, 2) | none | 0 |
| [2, 4) | 2, 3, 3 | 3 |
| [4, 6) | 5 | 1 |
| [6, 8) | 6, 6, 6, 7 | 4 |
| [8, 10] | 9, 10 | 2 |
Step 4 introduces one idea you may not expect: the bars touch each other. In a bar chart of categories, the bars have gaps, because the categories are separate things. In a histogram the bins are slices of one number line, so the bars touch.
flowchart LR A["List of numbers"] --> B["Split range into equal bins"] B --> C["Put each number in its bin"] C --> D["Count the numbers in each bin"] D --> E["Draw bars: height = count"]
The math
The math is only the walkthrough written with symbols. Here is the number of values, is the number of bins, and is the width of each bin.
Step 1 in symbols: the bins
The bins are , where the edges are . In the example , , and , so , , and so on up to . The last bin includes its right edge.
Step 2 and 3 in symbols: the counts
Each value belongs to exactly one bin, so the counts add up:
In the example, (the values 2, 3, 3), and .
Step 4 in symbols: the heights and the area
The plain histogram draws bars of height . A second version, the density histogram, divides each count by :
The area of bar is its height times its width, , which is the fraction of values in that bin. The areas sum to 1. In the example, , and the area of that bar is , which is 3 out of 10.
This second version is what links the histogram to a Probability Density Function. As grows and the bins get narrower, the tops of the bars trace out the shape of the underlying density.
Worked examples
Use the same 10 scores, 2, 3, 3, 5, 6, 6, 6, 7, 9, 10, but with bins of width 5: [0, 5) and [5, 10].
- Bin [0, 5) contains the values 2, 3, 3. Count: 3.
- Bin [5, 10] contains the values 5, 6, 6, 6, 7, 9, 10. Count: 7.
- Check the total: , which matches .
- Read the picture: two bars, one of height 3 and one of height 7. The fine detail from the width-2 version is gone. The bins are wider, so the picture is simpler and hides more.
Interpretation: changing the bin width changes the picture. The same data can look like two groups or like a smooth mound.
Twenty students scored: 42, 47, 51, 55, 58, 58, 61, 63, 64, 66, 68, 70, 71, 73, 74, 77, 80, 84, 88, 95. Use bins of width 10: [40, 50), [50, 60), [60, 70), [70, 80), [80, 90), [90, 100].
- Count the 40s: 42 and 47. Count 2.
- Count the 50s: 51, 55, 58, 58. Count 4.
- Count the 60s: 61, 63, 64, 66, 68. Count 5.
- Count the 70s: 70, 71, 73, 74, 77. Count 5.
- Count the 80s: 80, 84, 88. Count 3.
- Count the 90s: 95. Count 1.
- Check the total: , which matches the 20 students.
- The share of students in the 60s is , a quarter of the class.
Interpretation: the 60s and 70s are tied as the most common bins. The histogram shows a single hump centred near 65 to 75, with a thin tail at each end. The average is about 67, but the average alone would not show the shape.
A rider records 8 waiting times in minutes: 1.2, 3.5, 4.0, 4.8, 6.1, 7.9, 8.4, 12.5. Use bins of width 4 starting at 0: [0, 4), [4, 8), [8, 12), [12, 16].
- Bin [0, 4) holds 1.2 and 3.5. Count 2.
- Bin [4, 8) holds 4.0, 4.8, 6.1 and 7.9. Count 4. The value 4.0 belongs here because the bin includes its left edge.
- Bin [8, 12) holds 8.4. Count 1.
- Bin [12, 16] holds 12.5. Count 1.
- Check the total: .
- Density heights use . So , , and so on. The bar areas are , , , , which sum to 1.
- Interpretation: half the waits are between 4 and 8 minutes, and one wait of 12.5 minutes is the outlier that stands alone on the right.
Try it: using the same 8 waiting times, what fraction of waits are under 8 minutes? Answer: the first two bins hold values out of 8, so the fraction is , or 75%.
Common mistakes and tradeoffs
It is tempting to think a histogram is just a bar chart. In fact a bar chart shows separate categories such as cities or brands, and its bars have gaps. A histogram shows a numeric variable cut into bins, and its bars touch, because the bins are neighbouring pieces of one number line.
It is tempting to think the shape of a histogram is fixed by the data. In fact the shape depends on the bin width as well. Example 1 shows the same 10 scores looking like two bars in one version and a crowd in the other. When you report a histogram, state the bin width.
It is tempting to think bins of unequal width are a free choice. In fact the bar heights of a raw count histogram would then mislead, because a wide bin collects more values just by being wide. Use equal widths, or switch to the density version and read the area, not the height.
It is tempting to think a value on a bin edge belongs to both bins. In fact each value goes in exactly one bin, which is why the convention is [a, b) with the right edge excluded, except for the last bin, which includes it.
When to use it: to see the shape of one numeric variable, to spot skew, clusters, gaps and outliers, and to compare two groups side by side. When not to use it: for categories (use a bar chart), for exact values (use a sorted list or a stem plot), or for very small samples, where the shape is mostly noise. Alternatives include a box plot for a quick summary of spread, and a kernel density estimate for a smooth curve instead of bars.
History
People summarised measurements with tables of counts long before the picture. Statisticians wanted a way to see the shape of a distribution, not just its average, and the bar-based picture was the natural tool. Karl Pearson gave the picture its name, histogram, in 1895 in his work on the mathematical theory of evolution. It spread quickly because it needed no formula: anyone with paper and a ruler could draw one, and it caught on in biology, economics and quality control. The idea of a smooth curve replacing the bars came later, once statisticians wanted to compare distributions without choosing bins.
Recap
- A histogram cuts a range of numbers into equal bins and counts how many values fall in each bin.
- The bar heights are the counts, and the bars touch because the bins are slices of one number line.
- The bin width changes the picture, so state it whenever you show a histogram.
- A density histogram divides each count by , so the bar areas are the fractions of values and sum to 1.
- Next, read Probability Density Function to see the curve the bars approximate, and Random Variable for the numbers being counted. Mean and Variance gives the summary numbers a histogram shows visually.
Check yourself
QuestionYou have 6 numbers: 1, 2, 2, 4, 5, 9. Using bins of width 3 starting at 0, how many numbers fall in the first bin [0, 3)?Show answer
QuestionIn a histogram with bins of width 5, the value 5 appears. Which bin does it go to, [0, 5) or [5, 10)?Show answer
QuestionWhy do the bars of a histogram touch, while the bars of a bar chart of countries do not?Show answer
QuestionA histogram has 50 values and bins of width 2. A bin has a count of 10. What is its density height, and what is the area of its bar?Show answer
QuestionA researcher reports a histogram of household incomes with no bin width given, and the shape has one tall spike. Why should you be cautious, and what would you ask for?Show answer
Sources
- Wikipedia, "Histogram": https://en.wikipedia.org/wiki/Histogram
- Wikipedia, "Probability density function": https://en.wikipedia.org/wiki/Probability_density_function