A histogram is a graphical representation that groups numeric data into intervals—called bins or class intervals—and displays the frequency (count) of observations in each bin as adjacent vertical bars. Unlike bar charts that compare categorical data, a histogram reveals the underlying frequency distribution of a continuous variable: its shape, spread, central tendency, and potential outliers. First introduced by statistician Karl Pearson in 1891, the histogram is one of the most fundamental and widely used tools in exploratory data analysis.
Key Terms
| Term | Definition |
|---|---|
| Bin / Class Interval | An equal-width interval that partitions the data range. For example, 10–19 is a class interval with width 10 |
| Frequency | The count of data points falling within a given bin. Taller bars indicate higher data density in that range |
| Bin Width | The width of each interval = upper bound − lower bound. All bins must be of equal width; otherwise bar areas mislead visual interpretation |
| Distribution Shape | The overall pattern revealed by bar heights—symmetry, skewness, modality, and whether the data is single- or multi-peaked |
| Skewness | A measure of distribution asymmetry. Right-skew (positive) means the tail extends to higher values; left-skew (negative) extends to lower values |
| Modality | The number of peaks in a distribution. Unimodal = one peak; bimodal = two peaks suggesting mixed populations |
Why Use a Histogram?
- See distribution shape at a glance. The rise and fall of bars naturally reveal whether your data is symmetric, skewed, unimodal, or multimodal—insights that summary statistics like mean and standard deviation cannot convey alone.
- Quickly identify the densest region. The tallest bar marks the interval where data clusters most heavily, giving you the most "typical" value range.
- Detect outliers and data gaps. Isolated tall bars or blank gaps between bars may indicate data entry errors, measurement anomalies, or phenomena warranting further investigation.
- Compare multiple datasets. Place histograms side by side (or overlay them) to visually compare distributions across different groups or time periods.
- High teaching value. The histogram is a staple of middle school, high school, and college statistics curricula worldwide, used to teach data grouping, frequency distributions, and distribution shape analysis.
- Works for all numeric data. Whether exam scores, heights and weights, income levels, or production quality metrics—any continuous numeric variable can be visualized as a histogram.
Relationship to Box Plots and Stem-and-Leaf Plots
Histograms, box plots, and stem-and-leaf plots all belong to John Tukey's Exploratory Data Analysis (EDA) toolkit, each with distinct strengths:
| Chart | Preserves Raw Values | Shows Distribution Shape | Reveals Multimodality | Best Data Size |
|---|---|---|---|---|
| Histogram | ✗ Binned into intervals | ✓ Bar heights show frequency | ✓ Bimodal/multimodal visible | 20+ points |
| Box Plot | ✗ Five-number summary only | ✓ But hides multimodal patterns | ✗ Cannot show | Any size |
| Stem-and-Leaf | ✓ Every value preserved | ✓ Leaf arrangement shows shape | ✓ But less intuitive than histogram | 10–50 points, ideal |
Worked Example
Let's work through a set of 30 math exam scores:
55, 58, 62, 65, 67, 68, 70, 72, 73, 74,
75, 76, 77, 78, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 90, 92, 95, 97, 99
Step 1: Determine the Data Range
Minimum = 55
Maximum = 99
Range = 99 − 55 = 44
Step 2: Choose the Number of Bins and Bin Width
Common rules of thumb include:
- Sturges' formula: k = ⌈log₂(n) + 1⌉. For n = 30, k ≈ ⌈4.9 + 1⌉ = 6 bins
- Freedman-Diaconis rule: bin width = 2 × IQR × n^(−1/3). More robust for skewed data or data with outliers
Using Sturges' formula, we choose 6 bins:
Bin width = 44 ÷ 6 ≈ 7.33 → round up to 8
Rounding the bin width up to a "nice" number makes axis labels cleaner—a common practice in real-world charting.
Step 3: Define Intervals and Count Frequencies
Starting at 55, with a width of 8, we define 6 intervals:
Interval Frequency Data points
55 – 62 4 55, 58, 62
63 – 70 4 65, 67, 68, 70
71 – 78 8 72, 73, 74, 75, 76, 77, 78, 78
79 – 86 8 79, 80, 81, 82, 83, 84, 85, 86
87 – 94 4 87, 88, 90, 92
95 – 102 2 95, 97, 99
Step 4: Interpretation
- The tallest bars are in the 71–78 and 79–86 intervals (8 students each), meaning the bulk of scores cluster between 70 and 86
- 55–62 and 63–70 each have 4 students, with low scores spread evenly
- 87–94 has 4 students, 95–102 has 2, showing a gradual decline in high scores
- Overall, the distribution is roughly symmetric and unimodal, centered around 80, with a slight right skew (a few very high scores stretch the right tail)
How Bin Width Affects the Histogram
Bin width is the single most important parameter in a histogram. The same dataset can produce dramatically different visual impressions depending on bin width:
Same 30 exam scores, different bin widths:
Bin width = 4 (~11 bins):
High resolution—many narrow bars reveal local fluctuations,
but may introduce excessive noise
Bin width = 8 (~6 bins):
Moderate resolution—distribution shape is clear and interpretable;
this is the sweet spot for most analyses
Bin width = 15 (~3 bins):
Low resolution—few wide bars oversmooth the data,
hiding important distribution features
Rules of thumb:
- Too few bins → hide meaningful patterns (under-smoothing)
- Too many bins → amplify random noise (over-smoothing)
- 5–20 bins is the optimal range for most datasets
Computation Logic
function computeHistogram(data, numBins = null) {
// 1. Sort and get range
const sorted = [...data].sort((a, b) => a - b);
const dMin = sorted[0];
const dMax = sorted[sorted.length - 1];
// 2. Determine bin count (Freedman-Diaconis or manual)
const bins = numBins ?? Math.max(5, Math.min(20, Math.ceil(2 * Math.cbrt(data.length))));
const binWidth = (dMax - dMin) / bins || 1;
// 3. Count frequencies in each bin
const counts = Array(bins).fill(0);
for (const value of data) {
const idx = Math.min(bins - 1, Math.floor((value - dMin) / binWidth));
counts[idx]++;
}
// 4. Build bin objects
return counts.map((count, i) => ({
start: dMin + i * binWidth,
end: dMin + (i + 1) * binWidth,
count,
}));
}
// Example usage
const scores = [
55, 58, 62, 65, 67, 68, 70, 72, 73, 74,
75, 76, 77, 78, 78, 79, 80, 81, 82, 83,
84, 85, 86, 87, 88, 90, 92, 95, 97, 99
];
const histogram = computeHistogram(scores, 6);
console.log(histogram);
// [
// { start: 55, end: 62.33, count: 4 },
// { start: 62.33, end: 69.67, count: 3 },
// { start: 69.67, end: 77, count: 6 },
// { start: 77, end: 84.33, count: 7 },
// { start: 84.33, end: 91.67, count: 5 },
// { start: 91.67, end: 99, count: 5 },
// ]
Common Distribution Shapes
Familiarity with these typical shapes helps you quickly diagnose your data:
| Shape | Description | Typical Examples |
|---|---|---|
| Bell-shaped | High center, symmetric tails | Heights, weights, test scores, measurement errors |
| Right-skewed | Bulk on the left, long right tail | Income, housing prices, page load times |
| Left-skewed | Bulk on the right, long left tail | Easy exam scores, product lifespan |
| Bimodal | Two distinct peaks | Combined male/female heights, two production batches |
| Uniform | Bars of roughly equal height | Lottery numbers, random number generation, fair dice |
| J-shaped | One end very low, the other very high | Queue waiting times, time between failures |
Frequently Asked Questions
What is the difference between a histogram and a bar chart?
This is the most common confusion. A bar chart compares categorical data (e.g., sales by product), bars have gaps between them, and the order can be rearranged arbitrarily. A histogram displays the distribution of continuous numeric data, bars touch each other (no gaps), and the order is fixed by the numeric scale. In short: bar charts answer "which is larger?"—histograms answer "what does the data look like?"
How many data points do I need for a histogram?
Technically, 3 data points can produce a histogram, but at least 20 are needed to reveal a meaningful distribution shape. With very small datasets, a stem-and-leaf plot may be a better choice—it preserves every original value and is better suited for small samples.
How do I choose the right bin width?
There is no single "correct" bin width, but there are established rules of thumb. Sturges' formula (k = log₂(n) + 1) works well for approximately normal data. The Freedman-Diaconis rule (2 × IQR × n^(−1/3)) is more robust against outliers and skewed data. In practice, try 2–3 different bin widths and choose the one that best reveals the data's underlying structure.
Can a histogram show percentages instead of counts?
Yes. Divide each bin's frequency by the total number of data points to obtain the relative frequency (percentage). The vertical axis changes from "frequency" to "relative frequency." Bar heights remain proportional, but absolute values become percentages. This is especially useful when comparing datasets of different sample sizes.
Can a histogram detect outliers?
Yes, but less directly than a box plot. If a single bin has very low frequency while adjacent bins have much higher frequencies, this "gap" may signal outliers. A more systematic approach is to use box plot IQR fences (Q1 − 1.5×IQR and Q3 + 1.5×IQR) to flag outliers first, then observe their positions in the histogram.
Why must histogram bins be of equal width?
Because a histogram represents frequency through area (not just height). If bins have unequal widths, wider bins would have disproportionately larger areas, misleading the reader into thinking those intervals have higher frequency. Equal-width bins ensure bar height is directly proportional to frequency, making visual interpretation accurate. If unequal-width bins are unavoidable (e.g., logarithmic income brackets), the vertical axis must be labeled "density" (density = frequency ÷ bin width) rather than "frequency."
Extensions of the Histogram
Frequency Polygon
Connect the midpoints of each histogram bar's top edge with straight lines to form a frequency polygon. Overlaying it on the histogram helps readers trace the overall trend of the distribution more intuitively. Frequency polygons are especially useful when comparing multiple distributions in the same coordinate system.
Cumulative Frequency Histogram
Change the vertical axis to cumulative frequency (each bin's count plus all previous bins' counts), producing a step-like graph that rises from left to right. A cumulative frequency histogram directly answers questions like "how many data points are less than or equal to a given value?"
Density Curve Overlay
Superimpose a smooth kernel density estimation (KDE) curve over the histogram. This preserves the raw bin information while adding a smoothed trend line, making it easier to compare the empirical distribution against a theoretical distribution such as the normal curve.
Histogram Output
The chart was generated by https://aiboxplot.com
References
- Pearson, K. (1895). Contributions to the Mathematical Theory of Evolution. II. Skew Variation in Homogeneous Material. Philosophical Transactions of the Royal Society of London, 186, 343–414.
- Freedman, D., & Diaconis, P. (1981). On the histogram as a density estimator: L₂ theory. Zeitschrift für Wahrscheinlichkeitstheorie und verwandte Gebiete, 57(4), 453–476.
- Sturges, H. A. (1926). The choice of a class interval. Journal of the American Statistical Association, 21(153), 65–66.
- Tukey, J. W. (1977). Exploratory Data Analysis. Addison-Wesley.
- Scott, D. W. (1979). On optimal and data-based histograms. Biometrika, 66(3), 605–610.

Top comments (0)