The idea: five numbers and a fence

A box plot draws a data set with five numbers: the minimum, the lower quartile Q1, the median, the upper quartile Q3 and the maximum. The box runs from Q1 to Q3, so it holds the middle half of the values. Its width is the interquartile range, IQR = Q3 − Q1. Two fences sit 1.5 × IQR outside the box. A value beyond a fence is called an outlier and is drawn as a single point; the whiskers stop at the last values inside the fences. The page builds all of this one Step at a time, then tries a second rule, the z-score rule, on the same data.

Box plot of 12 delivery times above a dot plot: the box from Q1 26.5 to Q3 32.5 with the median line at 29.5, whiskers from 22 to 35, dashed red fences at 17.5 and 41.5, and the value 58 drawn as a red outlier point beyond the upper fence
The box is the middle half; the whiskers stop at the last values inside the fences, and 58 is past the upper fence, so it is drawn on its own.

Quartiles by the median of halves

Quartiles are about order, so the first Step sorts the values. The median Q2 is the middle value (odd n) or the average of the middle two (even n). It splits the list into a lower and an upper half. Q1 is the median of the lower half and Q3 the median of the upper half. When n is odd, this page leaves the median out of both halves. For the 11 exam scores the median 73 is the 6th value, each half has 5 values, and Q1 = 68, Q3 = 79 (Demo: exam scores). For the 12 delivery times each half has 6 values, so Q1 and Q3 are averages: (26 + 27) ÷ 2 = 26.5 and (32 + 33) ÷ 2 = 32.5.

About a quarter of the values lie below Q1 and about a quarter above Q3. The IQR is not moved by how far out the extreme values are: change 58 to 580 and the box stays the same. That is why the fences are built from it. The median and why it resists outliers are on Mean vs Median vs Mode.

Quartile methods differ

There is no single agreed formula for quartiles; Hyndman and Fan list nine. The second dropdown switches this page to linear interpolation: Q sits at position (n − 1) × p in the sorted list counted from 0, between two values when the position is not whole. This is the default of NumPy's percentile, Excel's QUARTILE.INC and R's quantile (type 7). On large data sets the methods barely differ. On small ones they can change the verdict for a value near a fence. For the ten values 10, 12, 13, 14, 15, 16, 17, 19, 20, 28:

MethodQ1Q3IQRUpper fenceIs 28 an outlier?
Median of halves (this page; TI calculators)1319628no, it is on the fence ✓
Tukey's hinges (median kept in both halves when n is odd)1319628no (n is even, so same as above)
Linear, position (n − 1)p: NumPy, Excel QUARTILE.INC, R type 713.2518.55.2526.375yes ✗
Position (n + 1)p: Excel QUARTILE.EXC, R type 6, Minitab12.7519.256.529no
Two box plots of the same ten values. Top, median of halves: box 13 to 19, upper fence at 28, so the value 28 sits on the fence and the whisker reaches it. Bottom, linear interpolation: box 13.25 to 18.5, upper fence 26.375, so 28 is beyond the fence and drawn as a red outlier
Same ten values, two quartile methods: 28 is on the fence with one and an outlier with the other.

So when you report outliers, say which method you used (Demo: a value exactly on the fence and Demo: same data, linear quartiles).

Fences, whiskers and outliers

The lower fence is Q1 − 1.5 × IQR and the upper fence Q3 + 1.5 × IQR. For the deliveries that is 26.5 − 9 = 17.5 and 32.5 + 9 = 41.5, so the 58-minute delivery is an outlier (Demo: one late delivery). Three details are easy to get wrong:

  • The whisker ends at the last data value inside the fence (35 here), not at the fence itself. Most box plots do not draw the fences at all.
  • Only values beyond a fence are outliers. A value exactly on it stays in, and the whisker reaches it.
  • With no outliers, the whiskers reach the minimum and the maximum, and the box plot shows exactly the five-number summary.

The factor 1.5 is Tukey's choice. For normal data it puts the fences about 2.7 standard deviations from the centre, so only about 0.7% of normal values land outside. Values beyond 3 × IQR are sometimes called far out or extreme outliers.

The z-score rule and why it can fail

The other common rule standardises each value, z = (x − mean) / s, and calls it an outlier when |z| > 3; z-scores are explained on Normal Distribution and s on Variance and Standard Deviation. The page uses the sample s, dividing by n − 1. The rule has three weak points, and the demos show each:

  • Masking. The outlier is part of the mean and s it is measured against. The late delivery pulls the mean from 28.8 (without it) to 31.25 and more than doubles s, to 9.22, so its own z is only 2.90 and it is not flagged.
  • Small samples. No value can have |z| larger than (n − 1) / √n. For n = 10 that is 2.85, so with ten values the rule |z| > 3 can never flag anything, however wild the value.
  • Skew. The rule assumes a roughly normal, symmetric shape. The response times have a long right tail: s is 150.9 ms, mean − 3s is −275.7 ms, an impossible time, and 400 ms has z = 1.48. Only 650 (z = 3.13) is flagged, while the IQR rule flags both 400 and 650 (Demo: skewed response times).

Which rule when

IQR rule (1.5 × IQR fences)z-score rule (|z| > 3)
Built fromquartiles: order onlymean and s: every value's size
Moved by the outliers themselveshardly ✓yes, they hide themselves ✗
Small nworks, but depends on the quartile methodcannot flag anything when n ≤ 10 ✗
Skewed dataflags much of the long tail, which may be realband can reach impossible values ✗
Use it fora first look at any data set, with a box plotlarge, roughly normal data

An outlier flag is a reason to look, not to delete. The 58-minute delivery may be a typo, a lost parcel or a real rush-hour trip; slow response times in a long tail are often the most important ones. For skewed data, a box plot of the logarithm of the values is often a fairer picture.

What the page leaves out

Side-by-side box plots for comparing groups, notched box plots (a confidence interval for the median), variable-width and violin plots, adjusted box plots for skewed data (the medcouple), the median absolute deviation (MAD) and the modified z-score, formal outlier tests (Grubbs, Dixon), percentiles other than the quartiles, and quartiles of grouped data or of a continuous distribution.

On the mind map

Open the Probability & Statistics mind mapProbability& StatisticsCounting: count outcomes, then divideCountingConditional probability: update on what you learnConditional probabilityDistributions: how likely each value isDistributionsRandom processes: simulate and repeatRandom processesStatistics from data: summarize, estimate, testStatistics from dataMean, median, modeMean, median, modemedian ignores outliers, mean does notConfidence intervalsConfidence intervalsx̄ ± z*·σ/√n catches μ 95% of the timeHypothesis testingHypothesis testingsmall p-value: data unlikely under H₀Frequentist vs BayesianFrequentist vs Bayesianfixed θ and CI vs prior to posteriorCorrelation and scatterCorrelation and scatterr measures line-ness, not causeVariance and std deviationVariance and std deviationaverage squared distance from meanBox Plots & IQR OutliersOutlier: beyond Q1−1.5·IQR or Q3+1.5·IQRChi-square testChi-square testΣ (obs − exp)² / exp vs chanceOpen the Probability & Statistics mind mapProbability & Statisticssummarize, estimate, testStatistics from dataMean, median, modeMean, median, modemedian ignores outliers, mean does notConfidence intervalsConfidence intervalsx̄ ± z*·σ/√n catches μ 95% of the timeHypothesis testingHypothesis testingsmall p-value: data unlikely under H₀Frequentist vs BayesianFrequentist vs Bayesianfixed θ and CI vs prior to posteriorCorrelation and scatterCorrelation and scatterr measures line-ness, not causeVariance and std deviationVariance and std deviationaverage squared distance from meanBox Plots & IQR OutliersOutlier: beyond Q1−1.5·IQR or Q3+1.5·IQRChi-square testChi-square testΣ (obs − exp)² / exp vs chance
This page on the Probability & Statistics mind map · 25 pages in 5 branches · open it to see the whole map and test yourself in recall mode.