Search

Search papers and lessons

Histogram

Level 1 · 11 min read

A histogram sorts numbers into equal-width ranges, called bins, and draws a bar for each bin whose height shows how many numbers fell in it.

On this page

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.

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.

BinScores in binCount
[0, 2)none0
[2, 4)2, 3, 33
[4, 6)51
[6, 8)6, 6, 6, 74
[8, 10]9, 102

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

Definition: Histogram
Given numbers x1,…,xnx_1, \dots, x_n and bins B1,…,BkB_1, \dots, B_k of equal width ww, the histogram is the set of counts njn_j, where njn_j is the number of the xix_i that fall in bin BjB_j. The total count is n=n1+⋯+nkn = n_1 + \dots + n_k.

The math is only the walkthrough written with symbols. Here nn is the number of values, kk is the number of bins, and ww is the width of each bin.

Step 1 in symbols: the bins

The bins are Bj=[aj−1,aj)B_j = [a_{j-1}, a_j), where the edges are aj=a0+j wa_j = a_0 + j\,w. In the example a0=0a_0 = 0, w=2w = 2, and k=5k = 5, so a1=2a_1 = 2, a2=4a_2 = 4, and so on up to a5=10a_5 = 10. The last bin includes its right edge.

Step 2 and 3 in symbols: the counts

Each value xix_i belongs to exactly one bin, so the counts add up:

nj=#{i:xi∈Bj},∑j=1knj=nn_j = \#\{ i : x_i \in B_j \}, \qquad \sum_{j=1}^{k} n_j = n

In the example, n2=3n_2 = 3 (the values 2, 3, 3), and ∑jnj=0+3+1+4+2=10=n\sum_j n_j = 0 + 3 + 1 + 4 + 2 = 10 = n.

Step 4 in symbols: the heights and the area

The plain histogram draws bars of height njn_j. A second version, the density histogram, divides each count by n⋅wn \cdot w:

hj=njn wh_j = \frac{n_j}{n\,w}

The area of bar jj is its height times its width, hj⋅w=njnh_j \cdot w = \dfrac{n_j}{n}, which is the fraction of values in that bin. The areas sum to 1. In the example, h2=310⋅2=0.15h_2 = \dfrac{3}{10 \cdot 2} = 0.15, and the area of that bar is 0.15×2=0.30.15 \times 2 = 0.3, which is 3 out of 10.

This second version is what links the histogram to a Probability Density Function. As nn grows and the bins get narrower, the tops of the bars trace out the shape of the underlying density.

Worked examples

Example
1. Tiny: change the bin width

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].

  1. Bin [0, 5) contains the values 2, 3, 3. Count: 3.
  2. Bin [5, 10] contains the values 5, 6, 6, 6, 7, 9, 10. Count: 7.
  3. Check the total: 3+7=103 + 7 = 10, which matches nn.
  4. 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.

Example
2. Standard: exam scores

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].

  1. Count the 40s: 42 and 47. Count 2.
  2. Count the 50s: 51, 55, 58, 58. Count 4.
  3. Count the 60s: 61, 63, 64, 66, 68. Count 5.
  4. Count the 70s: 70, 71, 73, 74, 77. Count 5.
  5. Count the 80s: 80, 84, 88. Count 3.
  6. Count the 90s: 95. Count 1.
  7. Check the total: 2+4+5+5+3+1=202 + 4 + 5 + 5 + 3 + 1 = 20, which matches the 20 students.
  8. The share of students in the 60s is 5/20=0.255 / 20 = 0.25, 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.

Example
3. Realistic: bus waiting times

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].

  1. Bin [0, 4) holds 1.2 and 3.5. Count 2.
  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.
  3. Bin [8, 12) holds 8.4. Count 1.
  4. Bin [12, 16] holds 12.5. Count 1.
  5. Check the total: 2+4+1+1=82 + 4 + 1 + 1 = 8.
  6. Density heights use n w=8×4=32n\,w = 8 \times 4 = 32. So h1=2/32=0.0625h_1 = 2/32 = 0.0625, h2=4/32=0.125h_2 = 4/32 = 0.125, and so on. The bar areas are 0.250.25, 0.50.5, 0.1250.125, 0.1250.125, which sum to 1.
  7. 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 2+4=62 + 4 = 6 values out of 8, so the fraction is 6/8=0.756/8 = 0.75, 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 n×wn \times w, 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
The bin [0, 3) holds 1, 2 and 2, so the count is 3.
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
It goes to [5, 10), because the convention is a left edge included and a right edge excluded. The value 5 is the left edge of [5, 10).
QuestionWhy do the bars of a histogram touch, while the bars of a bar chart of countries do not?Show answer
A histogram's bins are neighbouring slices of one numeric scale, so there is no gap between them. A bar chart of countries shows separate categories with no order or continuity between them, so the bars are drawn apart.
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
The density height is 10/(50×2)=0.110 / (50 \times 2) = 0.1. The area is 0.1×2=0.20.1 \times 2 = 0.2, which equals 10/5010 / 50, the fraction of values in that bin.
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
The spike may be an effect of the bin width. A narrow bin can make a noisy bump look like a peak, and a wide bin can hide it. You would ask for the bin width, and ideally a second histogram with a different width, to check that the spike survives.

Sources