Quartiles & the IQR
Quartiles cut sorted data into four equal parts at the 25th, 50th, and 75th percentiles. The gap between the outer two — the interquartile range — is the spread of the middle half, the box of a box plot, and the basis for drawing outlier fences.
What it is
Sort your data from smallest to largest and split it into four equal-sized chunks. The three cut points are the quartiles:
- Q1, the first quartile — the value below which 25% of the data falls.
- Q2, the second quartile — the value below which 50% falls. This is just the median.
- Q3, the third quartile — the value below which 75% falls.
Quartiles are a special case of percentiles (Q1 is the 25th percentile, Q3 the 75th) and of quantiles (the same idea expressed as a probability between 0 and 1). The interquartile range, or IQR, is the distance between the outer two:
IQR = Q3 − Q1
The IQR captures the spread of the middle 50% of the data. Because it throws away the bottom and top quarters entirely, a few extreme values can't drag it around — which makes it a robust measure of spread, in contrast to the standard deviation, which every outlier pulls on.
The formula
"The value below which 25% falls" is unambiguous only when a data point lands exactly on the boundary. When it doesn't — which is most of the time — you interpolate between the two nearest values. For n sorted values v and a probability p (0.25 for Q1, 0.5 for Q2, 0.75 for Q3):
h = (n − 1) · p
quantile = v[⌊h⌋] + (h − ⌊h⌋) · ( v[⌊h⌋+1] − v[⌊h⌋] )
The position h is a rank on a 0-based index; ⌊h⌋ is its integer floor and h − ⌊h⌋ the fractional part. If h is a whole number you land exactly on a data point; otherwise you take that fraction of the step to the next one. This is linear interpolation between the two closest ranks.
Outlier fences
Quartiles also define where a value stops being ordinary. Tukey's rule places two fences:
lower fence = Q1 − 1.5 · IQR
upper fence = Q3 + 1.5 · IQR
Any value beyond a fence is flagged as an outlier. The 1.5 multiplier is a convention, chosen so that under a normal distribution only about 0.7% of values fall outside the fences. These are exactly the lines that draw the whiskers and the stray dots on a box plot.
How to read it
| Quantity | What it tells you |
|---|---|
| Q1, Q2, Q3 | Where the lower quarter, half, and upper quarter of the data fall |
| IQR = Q3 − Q1 | Spread of the middle 50% — wider IQR, more variable data |
| Q2 off-center in the box | Skew — a median near Q1 means a long right tail, near Q3 a long left tail |
| Points past the 1.5·IQR fences | Outliers worth a second look |
quantile() formula function all use the linear interpolation definition above — the default in NumPy and pandas, and R's type = 7. Its box-whisker charts draw whiskers and flag outliers with the 1.5·IQR rule. Small differences against another tool usually trace to its quantile type, not an error — see the quantile section of the conventions page.
See also
- Try it free
- Box plot maker — paste data and see Q1, Q3, the IQR box, and the fences drawn
- Related terms
- Standard Deviation · Skewness & Kurtosis
- On the blog
- How to read a box plot · How to make a box plot
- In the app
- Build a box or violin plot and see the quartiles and fences drawn
Quartiles and the IQR are the robust counterpart to the mean and standard deviation: they describe center and spread without letting a handful of extreme values rewrite the story. That's exactly why the box plot — built entirely from these five numbers — is one of the fastest ways to size up a distribution at a glance.