A list of 40 exam scores is hard to read. A frequency table groups the scores into intervals and counts how many fall in each, and a histogram turns those counts into bars. In a few seconds you can see where most scores sit, how spread out they are and whether anything looks odd.
This page shows how to build both from raw data, how to choose the class width, and how to read the result. The interactive histogram lets you change the width and the data and watch the picture rebuild.
What a frequency table contains
- Class (interval): a range of values, such as 70 to 79.99.
- Frequency (f): how many values fall in the class.
- Relative frequency: $latex f/n$, the fraction of all values in the class. Multiply by 100 for a percent.
- Cumulative frequency: the running total of the frequencies, which tells you how many values are at or below the top of each class.
- Class width: the upper limit minus the lower limit of a class.
Classes must not overlap and must cover every value. A common convention is to include the lower limit and exclude the upper one, written $latex [70,80)$. Then 70 belongs to $latex [70,80)$, and 80 belongs to the next class.
How to build one, step by step
- Find the range: the largest value minus the smallest.
- Choose the number of classes $latex k$. A common guide is Sturges' rule, $latex k\approx 1+\log_2 n$, or the square root of $latex n$. Between 5 and 12 classes works for most classroom data.
- Divide the range by $latex k$ and round up to a convenient number. That is the class width.
- Start at a round number at or below the minimum and write the intervals. Make sure the maximum fits in the last one.
- Tally the values and count them to get each frequency.
- Add the relative and cumulative frequencies. Check that the frequencies add up to $latex n$.
Take 20 quiz scores: 55, 62, 64, 67, 68, 70, 71, 73, 74, 75, 76, 78, 79, 81, 83, 84, 86, 88, 92, 95. The smallest is 55 and the largest is 95, so the range is 40. Sturges gives $latex 1+\log_2 20\approx 5.3$, so about 5 classes, and $latex 40/5=8$ rounds up to a width of 10. Starting at 50:
| Class | Tally | Frequency | Relative frequency | Percent | Cumulative |
|---|---|---|---|---|---|
| [50, 60) | | | 1 | 0.05 | 5% | 1 |
| [60, 70) | |||| | 4 | 0.20 | 20% | 5 |
| [70, 80) | ||||| ||| | 8 | 0.40 | 40% | 13 |
| [80, 90) | ||||| | 5 | 0.25 | 25% | 18 |
| [90, 100) | || | 2 | 0.10 | 10% | 20 |
The frequencies add up to 20, and the cumulative column ends at 20 too, which is the check.
Histogram or bar chart?
A histogram looks like a bar chart but it is not the same. A bar chart compares separate categories (favorite fruit, city), so its bars have gaps and can be put in any order. A histogram shows how numerical data is distributed along a number line, so its bars touch, follow the order of the values, and the width of each bar is the class width.
Equal class widths make the bar height proportional to the frequency. If you ever use unequal widths, plot the density $latex f/\text{width}$ instead, so that the area of a bar, not its height, represents the count.
Build a histogram and change the class width
The default data is 40 exam scores. Move the width slider and watch the bars and the table rebuild. A width of 1 shows noise, a width of 46 hides everything in one bar, and widths near 8 to 10 tell the story. Paste your own numbers in the box, or switch to relative frequency to see percentages.
Build a histogram: change the class width
The bars and the table rebuild as you move the slider or edit the data. Each class includes its lower limit and leaves out its upper limit.
How to read a histogram
- Center: where the tallest bars are. The tallest class is the modal class.
- Spread: how far the bars stretch from left to right.
- Shape: symmetric, skewed or with several peaks (see below).
- Gaps and isolated bars: possible outliers or two mixed groups.
In a right-skewed histogram the long tail points right, as with incomes or waiting times, and the mean is usually larger than the median. In a left-skewed one the tail points left. Two peaks often mean two groups mixed in one data set, such as the heights of adults of both sexes.
Choosing the class width
Too few classes hide the shape. Too many make the histogram jagged, because each bar holds only one or two values. There is no single correct answer, so start with Sturges or the square root rule and adjust. For the 40 scores above, Sturges suggests $latex \lceil 1+\log_2 40\rceil = 7$ classes, which is a width of about 6.6, and a width of 10 gives a cleaner picture with 5 classes. Use the Mean, median and mode calculator to find the range and the center of your data first.
Worked examples
EXAMPLE 1
Using the 20 quiz scores in the table, what percent scored 80 or more?
The classes $latex [80,90)$ and $latex [90,100)$ hold 5 and 2 values, so $latex \frac{5+2}{20}=\frac{7}{20}=0.35$, which is 35%.
EXAMPLE 2
How many scores were below 70?
Read the cumulative column at the class $latex [60,70)$: 5 scores, which is 25% of the data.
EXAMPLE 3
Which class contains the median, and what is the modal class?
With 20 values, the median is between the 10th and 11th. The cumulative frequency reaches 5 at $latex [60,70)$ and 13 at $latex [70,80)$, so the median is in $latex [70,80)$. This class also has the highest frequency (8), so it is the modal class.
EXAMPLE 4
Estimate the mean from the table.
Use the midpoint of each class (55, 65, 75, 85, 95) as the representative value: $latex \bar{x}\approx\frac{55(1)+65(4)+75(8)+85(5)+95(2)}{20}=\frac{1530}{20}=76.5$.
The exact mean of the raw data is 76.05. The grouped estimate is close, and the small gap is the price of grouping.
Common mistakes
- Overlapping classes. Writing 60 to 70 and 70 to 80 puts 70 in two classes. Decide which end is included.
- Leaving gaps between bars. A histogram's bars touch, because the data is continuous along the axis.
- Unequal class widths without adjusting. Tall wide bars mislead. Use density or keep the widths equal.
- Dropping the maximum. If the last class stops below the largest value, the frequencies will not add up to $latex n$.
- Starting the vertical axis above zero. Bars must start at 0 for their heights to compare honestly.
- Treating the shape as the truth. Different widths and starting points change the picture, so check more than one.
Solved exercises
EXERCISE 1
The values run from 12 to 87 and you want 6 classes. Find a convenient class width and write the limits.
Solution
The range is $latex 87-12=75$, and $latex 75/6=12.5$. Round up to a convenient width such as 15. Starting at 10: $latex [10,25)$, $latex [25,40)$, $latex [40,55)$, $latex [55,70)$, $latex [70,85)$, $latex [85,100)$. These six classes cover 12 to 87.
EXERCISE 2
Build a frequency table for 3, 5, 6, 6, 7, 8, 8, 8, 9, 10, 11, 12, 12, 13, 15 with classes of width 4 starting at 2.
Solution
$latex [2,6)$: 3, 5, so 2. $latex [6,10)$: 6, 6, 7, 8, 8, 8, 9, so 7. $latex [10,14)$: 10, 11, 12, 12, 13, so 5. $latex [14,18)$: 15, so 1. The total is 15.
EXERCISE 3
With classes $latex [30,40)$ and $latex [40,50)$, in which class does the value 40 go?
Solution
In $latex [40,50)$, because each class includes its lower limit and excludes its upper limit.
EXERCISE 4
A table of 40 values has frequencies 4, 9, 15, 8, 4. Find the relative and cumulative frequencies, and the percent of values up to the end of the third class.
Solution
Relative: $latex 0.10, 0.225, 0.375, 0.20, 0.10$, that is 10%, 22.5%, 37.5%, 20%, 10%. Cumulative: 4, 13, 28, 36, 40.
Up to the third class there are 28 of 40 values: $latex 28/40=0.70$, so 70%.
EXERCISE 5
A histogram has frequencies 20, 14, 8, 5, 3, 1 from left to right. Describe the shape.
Solution
The tallest bar is on the left and the bars shrink slowly toward the right, so it is skewed right. The mean will be larger than the median.
EXERCISE 6
Estimate the mean from the classes $latex [0,10)$, $latex [10,20)$, $latex [20,30)$ with frequencies 5, 10, 5.
Solution
Midpoints 5, 15, 25: $latex \bar{x}\approx\frac{5(5)+15(10)+25(5)}{20}=\frac{300}{20}=15$.
Frequently asked questions
How many classes should a histogram have?
Between 5 and 12 for classroom data. Start from Sturges' rule or the square root of n, then adjust until the shape is clear without too much noise.
What is the difference between a histogram and a bar chart?
A bar chart compares categories, so its bars are separated and can be reordered. A histogram shows numerical data in ordered intervals, so its bars touch.
Can the classes have different widths?
Yes, but then the area of each bar, not its height, must represent the frequency. For beginners, equal widths are simpler and safer.
Why did my histogram change when I changed the width?
Because grouping hides detail. Both pictures are correct, but they emphasize different things. Check a few widths before concluding anything.
Related calculators
- Mean, median and mode calculator
- Standard deviation calculator
- Percentage calculator
- Dice and coin probability simulator
More tools are in the calculators hub.