The five-number summary — minimum, first quartile (Q1), median, third quartile (Q3), and maximum — is the fastest way to describe the shape and spread of a dataset without assuming it follows a normal distribution. The interquartile range (IQR), the distance between Q1 and Q3, is the single number most often pulled out of that summary because it measures the spread of the “typical” middle half of the data while ignoring extreme values. This guide walks through how to calculate both by hand, why different software can return slightly different quartile values for the same dataset, how to use the IQR to flag outliers, and how to report it correctly.
The worked datasets below are illustrative examples constructed to demonstrate the calculations — they are not drawn from a real study.
The Five-Number Summary
The five-number summary is a set of five values that together describe a distribution’s centre, spread, and range:
- Minimum — the smallest value in the dataset.
- Q1 (first quartile / 25th percentile) — the value below which roughly 25% of the data falls.
- Median (Q2 / 50th percentile) — the middle value; see CASRAI’s descriptive statistics guide for how the median compares to the mean as a measure of central tendency.
- Q3 (third quartile / 75th percentile) — the value below which roughly 75% of the data falls.
- Maximum — the largest value in the dataset.
Read together, these five values tell you the full range (maximum minus minimum), the middle 50% of the data (the IQR, Q3 minus Q1), and — by comparing the distances between minimum-to-median and median-to-maximum, or Q1-to-median and median-to-Q3 — whether the distribution is roughly symmetric or skewed toward one tail. This is exactly the information a histogram or box plot is built to display visually. Because quartiles are just specific points read off a distribution’s cumulative probability, they can also be obtained directly from a cumulative distribution function (CDF) rather than approximated visually.
How to Find the Interquartile Range: Step by Step
Finding the IQR always follows the same three steps: sort the data, find Q1 and Q3, then subtract. The only part that varies is exactly how Q1 and Q3 are located, which depends on whether the sample size is odd or even and which quartile method is used (see the next section).
Worked example with an odd sample size (n = 9)
Illustrative dataset — nine survey response times in minutes, sorted from smallest to largest:
12, 15, 18, 21, 23, 27, 29, 33, 41
- Find the median. With 9 values, the median is the 5th value: 23.
- Find Q1. Take the lower half of the data, excluding the median: 12, 15, 18, 21. The median of these four values is (15 + 18) / 2 = 16.5.
- Find Q3. Take the upper half, excluding the median: 27, 29, 33, 41. The median of these is (29 + 33) / 2 = 31.
- Calculate the IQR. IQR = Q3 − Q1 = 31 − 16.5 = 14.5.
Five-number summary: 12, 16.5, 23, 31, 41.
Worked example with an even sample size (n = 10)
Illustrative dataset — ten participant scores, sorted:
4, 7, 7, 9, 10, 12, 14, 15, 18, 22
- Find the median. With an even count, the median is the average of the 5th and 6th values: (10 + 12) / 2 = 11.
- Find Q1. The lower half is the first five values: 4, 7, 7, 9, 10. Their median (the 3rd of these five) is 7.
- Find Q3. The upper half is the last five values: 12, 14, 15, 18, 22. Their median is 15.
- Calculate the IQR. IQR = Q3 − Q1 = 15 − 7 = 8.
Five-number summary: 4, 7, 11, 15, 22.
Why your software might give a different answer
The method used above — splitting the sorted data into halves and taking the median of each half, excluding the overall median for odd n — is one of several legitimate ways to define a quartile, sometimes called Tukey’s hinges. It is easy to do by hand but is not the only convention in use, and this is a genuine, common source of confusion when a hand calculation does not match a spreadsheet or statistical package:
- R’s
quantile()function supports nine different quartile-calculation methods (types 1–9), selectable via itstypeargument; type 7, which uses linear interpolation between data points, is the default. - Excel provides
QUARTILE.INC(inclusive method, matches the legacyQUARTILEfunction and R’s type 7 default) andQUARTILE.EXC(exclusive method, closer to Tukey’s hinges), which can return different values for the same range of cells. - Most graphing calculators and introductory statistics textbooks use the median-of-halves method shown in the worked examples above.
For small datasets the differences between methods are usually small — often no more than a fraction of a data unit — but they are not always negligible, especially with small n or heavily tied values. If precise reproducibility matters (a manuscript methods section, a shared analysis script), state which method or software function produced the reported quartiles.
IQR = Q3 − Q1: A Robust Measure of Spread
The interquartile range describes how spread out the middle 50% of a dataset is, and it does so without being pulled around by extreme values. That makes it a more robust measure of spread than two commonly used alternatives:
- The range (maximum minus minimum) is determined entirely by the two most extreme observations. A single unusually high or low value can inflate the range dramatically, even if the rest of the data is tightly clustered.
- The standard deviation (SD) uses every value in the dataset, which is a strength when the data are roughly normally distributed and a weakness when the distribution is skewed or contains outliers — a few extreme points can pull the SD up substantially, giving a misleading impression of how spread out “typical” values actually are.
- The coefficient of variation (CV) expresses the SD as a percentage of the mean, which is useful for comparing relative variability across variables measured in different units — but, like the SD, it inherits the mean’s sensitivity to skew and outliers. See CASRAI’s guide to the coefficient of variation.
The IQR does not eliminate the need for the range or SD — each answers a different question — but it is the measure of spread least sensitive to a handful of unusual observations, which is why it is the standard companion to the median rather than the mean.
Outlier Detection with the 1.5 × IQR Rule
The most common convention for flagging potential outliers uses the IQR to set boundaries, often called inner fences:
- Lower fence = Q1 − (1.5 × IQR)
- Upper fence = Q3 + (1.5 × IQR)
Using the odd-n example above (Q1 = 16.5, Q3 = 31, IQR = 14.5): lower fence = 16.5 − (1.5 × 14.5) = −5.25; upper fence = 31 + (1.5 × 14.5) = 52.75. Any value falling outside −5.25 to 52.75 would be flagged for closer inspection. A stricter convention — the 3 × IQR boundary, sometimes labelled “extreme outliers” — pushes the fences further out (here, roughly −27.25 to 74.75) to flag only the most extreme points.
Being flagged by the 1.5 × IQR rule means a value is unusual relative to the rest of the sample — it is not, on its own, evidence that the value is an error. A flagged point can be a genuine, correctly recorded extreme observation, and removing it changes the sample in a way that requires justification. Outlier detection is a prompt to look more closely (check for a data-entry or measurement error, an equipment fault, or a genuinely unusual but valid case), not an automatic rule for exclusion.
Box Plots and the Five-Number Summary
A box plot (or box-and-whisker plot) is a direct visual encoding of the five-number summary:
- The box spans from Q1 to Q3 — its length is the IQR.
- A line inside the box marks the median.
- Whiskers extend from the box out to the most extreme data points that still fall within the fences (commonly the 1.5 × IQR boundary described above).
- Points beyond the whiskers are plotted individually as potential outliers.
Variations exist: a notched box plot adds a narrowing around the median to give a rough visual sense of whether two groups’ medians differ; a variable-width box plot scales each box’s width to its sample size when comparing several groups side by side. In all variants, an asymmetric box (Q1-to-median markedly different in length from median-to-Q3), or long, unequal whiskers, is a quick visual signal of skew — the same skew a histogram would show as a longer tail on one side, and a signal worth checking against a formal test if a downstream analysis assumes normality of distribution.
When to Prefer IQR Over Standard Deviation
The IQR (paired with the median) is generally the better choice over the SD (paired with the mean) when:
- The distribution is skewed rather than roughly symmetric — income, wait times, and many biological measurements are common examples.
- The data are ordinal rather than truly continuous/interval, where a mean and SD are harder to interpret meaningfully but a median and quartiles remain valid — see CASRAI’s types of variables entry for the underlying distinction.
- The sample is small and contains one or more outliers, where a single extreme value can dominate the SD but has bounded influence on the IQR.
Conversely, the mean and SD remain preferable when the distribution is approximately normal and the goal is to use methods (many parametric tests, confidence intervals) that are built around them.
Reporting the IQR
The standard convention is to report the median with the IQR expressed as the Q1–Q3 range, not as a single spread number, so the reader can see the actual middle-50% interval rather than just its width. The typical format is:
median (Q1–Q3) — for example, “23 (16.5–31)” for the odd-n worked example above.
Some reporting styles instead give the IQR as a single width value (“IQR = 14.5”); both are used in practice, but the Q1–Q3 form carries more information for the same space and is generally preferred. If the specific quartile method matters for reproducibility, state it (for example, “quartiles calculated using R’s default quantile() type 7″) alongside the reported values, particularly in a methods section intended to be reproduced exactly.
Calculating the IQR in R, Python, and Excel
- R:
IQR(x)for the interquartile range directly, orquantile(x)for the full five-number summary; both accept atypeargument to select among the nine quartile-calculation methods. - Python:
numpy.percentile(x, [25, 75])or, with pandas,x.quantile([0.25, 0.75]);scipy.stats.iqr(x)computes the IQR directly and also accepts an interpolation-method argument. - Excel:
=QUARTILE.INC(range, 1)and=QUARTILE.INC(range, 3)for the inclusive method (orQUARTILE.EXCfor the exclusive method), then subtract for the IQR.
Because these tools can use different quartile definitions (see above), do not assume two tools will return identical Q1/Q3 values for the same data — check which method each is using if the discrepancy matters.
Outlier Flags Are Not Exclusion Rules
It is worth restating plainly: identifying a point as a statistical outlier via the 1.5 × IQR rule, or any other method, is not by itself a justification for removing it from an analysis. Deciding after the fact to drop “inconvenient” data points — especially when that decision is made only once its effect on the result is known — is a form of selective reporting that CASRAI’s questionable research practices entry addresses directly. Any exclusion criteria, including outlier-handling rules, should be specified before looking at how they affect the result (ideally pre-registered or stated in a protocol), applied consistently, and disclosed in full — including how many points were excluded and why — in the resulting write-up.
Frequently Asked Questions
What is the difference between the range and the interquartile range?
The range is the maximum minus the minimum — it uses only the two most extreme values and is highly sensitive to a single unusual observation. The IQR is Q3 minus Q1, the width of the middle 50% of the data, and is far less affected by extreme values.
Can the IQR be zero?
Yes — if at least half of the sorted data points share the same value (so that Q1 and Q3 land on the same value), the IQR will be zero. This typically signals a large concentration of tied or repeated values around the centre of the distribution.
Is a value outside the 1.5 × IQR fences always an error?
No. It is a statistical flag indicating the value is unusual relative to the rest of the sample, not proof of a data-entry or measurement error. It should prompt inspection, and any resulting exclusion needs a pre-specified, disclosed justification — not just the flag itself.
Do Q1 and Q3 always come out the same across different software?
Not necessarily. Different quartile-calculation methods (R’s nine quantile() types, Excel’s QUARTILE.INC versus QUARTILE.EXC, and the median-of-halves method taught in many introductory courses) can produce slightly different Q1/Q3 values for the same dataset, particularly with small samples.







