Statistics
How To Calculate The Interquartile Range
The interquartile range measures the spread of the middle half of a data set. It is the difference between the upper quartile and the lower quartile, and because it ignores the extremes it gives a more stable picture of typical variation than the full range does.
Last updated
Quick Answer
IQR = Q3 - Q1
- IQR
- Interquartile range, the spread of the middle half of the data
- Q1
- Lower quartile, the 25th percentile of the sorted data
- Q3
- Upper quartile, the 75th percentile of the sorted data
Sort the data, find the lower quartile Q1 and the upper quartile Q3, then subtract. In this teaching model the five entered values are already sorted: Q1 is the mean of x1 and x2, the median is x3, and Q3 is the mean of x4 and x5. For 3, 7, 8, 12 and 20 the result is 16 minus 5, giving an interquartile range of 11 and an upper outlier fence of 32.5.
What Is The Interquartile Range?
The interquartile range is the width of the central portion of a sorted data set. It is the upper quartile minus the lower quartile, written IQR = Q3 - Q1, and it contains the middle fifty per cent of the observations. Half the values lie below Q1 and half above Q3, so the distance between them captures where the bulk of the data sits. Because the measure is built from positions in the ordered list rather than from every value, it belongs to the family of robust statistics. It is reported in the same units as the original measurements, which makes it easy to describe in ordinary language.
The idea was popularised in exploratory data analysis, where the goal is to summarise a batch of numbers quickly and notice anything unusual. The quartiles split the ordered data into four groups of roughly equal size, and the interquartile range is the span of the two middle groups. That is why it pairs naturally with the median: the median gives the centre, and the interquartile range gives the spread around it. Reporting the two together, as in a five-number summary, tells you far more than an average alone. The approach is simple enough to compute by hand, which is part of its enduring appeal.
This calculator uses a teaching model with five fixed positions. The values x1 through x5 are assumed already sorted in ascending order, so x1 is the smallest and x5 the largest. The median is the middle value x3, the lower quartile is the mean of x1 and x2, and the upper quartile is the mean of x4 and x5. With five observations this is the median-of-halves convention, and it keeps the arithmetic short enough to follow. The sorted-input assumption matters: if the entries are not in order, the expression still produces a number, but not the interquartile range of the data. Sort first, then enter the values.
Take the default set 3, 7, 8, 12 and 20. The lower quartile is the mean of 3 and 7, which is 5, and the median is the middle value 8. The upper quartile is the mean of 12 and 20, which is 16. Subtracting gives IQR = 16 - 5 = 11, so the middle half of these observations spans eleven units. The upper outlier fence, defined as Q3 plus one and a half times the IQR, is 16 + 1.5 x 11 = 32.5. Any value above 32.5 would be flagged as a potential outlier under that rule. None of the five default values is flagged, but the fence shows how the same two quartiles can be reused for a second purpose.
The one and a half times rule deserves a word of explanation. It extends the central box by a distance proportional to the width of that box, and points beyond the extension are treated as unusual rather than automatically discarded. For the default data the lower fence is 5 - 1.5 x 11 = -11.5, below which nothing falls, and the upper fence is 32.5. The multiplier is a convention rather than a theorem; a larger multiplier flags fewer points, and a smaller one flags more. The calculator reports the upper fence directly so you can see exactly where the threshold sits. Flagging a point is an invitation to investigate it, not a licence to delete it.
Robustness is the main reason to prefer the interquartile range over the ordinary range. Change the largest entry from 20 to 16 while leaving the rest alone: the upper quartile becomes the mean of 12 and 16, which is 14, and the IQR falls from 11 to 9. Change the smallest entry from 3 to 1 instead: the lower quartile becomes the mean of 1 and 7, which is 4, and the IQR rises from 11 to 12. Notice that the measure moves in the direction the altered quartile moves, but by less than the extreme value itself moved. The full range reacts more dramatically to the same edits, dropping from 17 to 13 in the first case and rising from 17 to 19 in the second. That contrast is the practical advantage of a statistic based on the middle of the distribution.
Other quartile conventions exist, and they can give different answers on the same data. Some textbooks include the median in each half when computing the quartiles, others exclude it; some interpolate between neighbouring positions using a percentile rank, and statistical software packages differ in their default choice. For large data sets the discrepancies are usually small, but with only five observations they can be noticeable. The value 11 produced here is correct for the median-of-halves method with sorted inputs, not a universal constant of the data set. When comparing your answer with a textbook or a spreadsheet, check which convention that source uses before assuming either is wrong. Stating the convention explicitly is the safest habit.
It is also useful to contrast the interquartile range with the standard deviation. The standard deviation uses every observation, measures distance from the mean, and grows quickly when a single value is moved far away. The interquartile range uses only the positions of the quartiles, measures the width of the central block, and is largely indifferent to how far an extreme value sits beyond a quartile. Neither is universally better: the standard deviation is more informative for roughly symmetric data and underpins much of statistical theory, while the interquartile range is more honest for skewed data or data with suspect extremes. Box plots display the median, the two quartiles and the fences together, which is why the interquartile range is the standard companion to that diagram.
In practice the interquartile range appears wherever a resistant summary is wanted. Income distributions, response times and measurement errors are commonly reported as a median with an interquartile range, because a few very large observations would distort a mean and a standard deviation. The measure is also the building block of the box-and-whisker plot and of simple outlier screening. The limits of this tool should be kept in view. It takes exactly five sorted values, so it cannot represent a full data set, and the chosen quartile convention is one among several. Use the calculator to understand the mechanics and to check your own arithmetic, then apply the same steps with an appropriate convention when the real data set is larger.
Formula
IQR = Q3 - Q1
Formula page →Subtract the lower quartile from the upper quartile. The result is the width of the central fifty per cent of the sorted observations and is expressed in the original units.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| IQR | Interquartile range | same as data | The spread of the middle half of the data, 11 for the default values. |
| Q1 | Lower quartile | same as data | The mean of x1 and x2 in this five-value model, equal to 5 by default. |
| Q3 | Upper quartile | same as data | The mean of x4 and x5 in this five-value model, equal to 16 by default. |
Q1 = (x1 + x2) / 2, Q3 = (x4 + x5) / 2
Formula page →With five ordered observations the median is x3, so each half contains two values and its midpoint is the mean of those two values.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| x1, x2 | Two smallest sorted values | same as data | Their average gives the lower quartile, (3 + 7) / 2 = 5 by default. |
| x4, x5 | Two largest sorted values | same as data | Their average gives the upper quartile, (12 + 20) / 2 = 16 by default. |
| x3 | Middle sorted value | same as data | The median, reported separately and equal to 8 by default. |
Upper fence = Q3 + 1.5 x IQR
Formula page →Extend the upper quartile by one and a half times the interquartile range. Values above the result are flagged as potential outliers rather than removed.
| Symbol | Meaning | Unit | Notes |
|---|---|---|---|
| Upper fence | Threshold for high-side outliers | same as data | Equal to 32.5 for the default values. |
| Q3 | Upper quartile | same as data | The starting point for the fence, 16 by default. |
| IQR | Interquartile range | same as data | The width used to scale the fence, 11 by default. |
How To Calculate The Interquartile Range
- 1
Sort the five values into ascending order
Place the smallest observation in x1, the next in x2, and so on up to the largest in x5. The default values 3, 7, 8, 12 and 20 are already in order. This precondition is essential because the quartile expressions take the first two and last two positions literally. If you enter an unsorted list, the result is a difference between two averages but not the interquartile range of the data. Check the order before touching any other step.
- 2
Identify the median
With exactly five sorted observations the median is the third value, x3. It is 8 for the default set. The median divides the list into a lower half of x1 and x2 and an upper half of x4 and x5. It is reported separately by the calculator but is not subtracted in the interquartile range formula, so do not confuse it with either quartile.
- 3
Find the lower quartile
Average the two values in the lower half. For x1 = 3 and x2 = 7 the lower quartile is (3 + 7) / 2 = 5. Averaging is appropriate here because there are two values in the half rather than one central value. If a different quartile convention is required, this is the step that must change, along with the corresponding upper-half calculation.
- 4
Find the upper quartile
Average the two values in the upper half. For x4 = 12 and x5 = 20 the upper quartile is (12 + 20) / 2 = 16. This value is also the base for the outlier fence. Keep the lower and upper quartiles distinct in your notes: subtracting them in the wrong order gives a negative number that signals a reversed subtraction rather than a meaningful spread.
- 5
Subtract and apply the fence
Compute the interquartile range as Q3 minus Q1, which is 16 - 5 = 11 for the default values. The upper fence follows from the same quartiles as Q3 + 1.5 x IQR, giving 16 + 16.5 = 32.5. Both figures are reported so you can see how the width of the central half determines where the outlier threshold falls.
Examples
Example 1: The default sorted set 3, 7, 8, 12, 20
- x1
- 3
- x2
- 7
- x3
- 8
- x4
- 12
- x5
- 20
| Step | Calculation | Result |
|---|---|---|
| Lower quartile | (x1 + x2) / 2 = (3 + 7) / 2 | 5 |
| Median | x3 | 8 |
| Upper quartile | (x4 + x5) / 2 = (12 + 20) / 2 | 16 |
| Upper fence | 16 + 1.5 x 11 | 32.5 |
| Interquartile range | 16 - 5 | 11 |
Result: The interquartile range is 11, with a lower quartile of 5, a median of 8, an upper quartile of 16 and an upper fence of 32.5.
Example 2: Lowering the largest value from 20 to 16
- x1
- 3
- x2
- 7
- x3
- 8
- x4
- 12
- x5
- 16
| Step | Calculation | Result |
|---|---|---|
| Lower quartile unchanged | (3 + 7) / 2 | 5 |
| Upper quartile | (12 + 16) / 2 | 14 |
| Interquartile range | 14 - 5 | 9 |
Result: With x5 reduced to 16 the interquartile range is 9, smaller than the default 11 because the upper quartile has fallen to 14.
Example 3: Lowering the smallest value from 3 to 1
- x1
- 1
- x2
- 7
- x3
- 8
- x4
- 12
- x5
- 20
| Step | Calculation | Result |
|---|---|---|
| Upper quartile unchanged | (12 + 20) / 2 | 16 |
| Lower quartile | (1 + 7) / 2 | 4 |
| Interquartile range | 16 - 4 | 12 |
Result: With x1 reduced to 1 the interquartile range is 12, larger than the default 11 because the lower quartile has fallen to 4.
Calculator
Interquartile range
11
- Lower quartile (Q1)
- 5
- Upper quartile (Q3)
- 16
- Median
- 8
- Upper outlier fence
- 32.5
Values update as you type. This calculator covers the single scenario its formula assumes — see Common Mistakes for what it leaves out.
Prefer a full-width tool? Open the The Interquartile Range calculator page.
Common Mistakes
Forgetting to sort the input values
The expressions average the first two and last two entries, so they only produce quartiles when the list is in ascending order. Entering the numbers in the order they were collected gives an arbitrary difference between two averages. Sort the five values first, and re-sort after any edit, before reading the output.
Assuming every source uses the same quartile convention
Including or excluding the median from each half, or interpolating at percentile ranks, can change the answer. With five observations the differences are visible. The value 11 is correct for the median-of-halves method used here, so name the convention whenever you compare results with a textbook or spreadsheet.
Confusing the interquartile range with the full range
The range is the largest value minus the smallest, which is 20 - 3 = 17 for the default data, whereas the interquartile range is 11. The range uses the extremes and reacts strongly to them. Mixing the two leads to claims about the middle half that are actually statements about the outermost observations.
Expecting the statistic always to rise when an extreme rises
Moving the largest value upward leaves Q1 untouched and raises Q3, so the interquartile range rises; but moving that same extreme downward lowers Q3 and shrinks the measure. In the worked case reducing x5 from 20 to 16 takes the interquartile range from 11 to 9. Always identify which quartile an edit affects before predicting the direction.
Treating a flagged point as an error to delete
The upper fence of 32.5 is a screening threshold, not proof that a value is wrong. Observations beyond it may be genuine tail events or evidence of a different population. Investigate the point and the collection process before deciding what to do, and report whether the summary was computed with or without it.
Using the interquartile range as if it were a deviation from the mean
The interquartile range describes the width of the central block, not the typical distance of values from the average. It is paired with the median, not the mean. Quoting it alongside a mean, or interpreting it with the empirical rule used for standard deviations, mixes two different descriptions of a distribution.
FAQ
What is the interquartile range?
It is the difference between the upper and lower quartiles, Q3 minus Q1. It measures the width of the middle fifty per cent of a sorted data set and is expressed in the same units as the data. Because it is based on positions rather than on every value, it is resistant to extreme observations.
How do you find the two quartiles in this calculator?
With five values already sorted, the lower quartile is the mean of x1 and x2 and the upper quartile is the mean of x4 and x5. The middle value x3 is the median. For the default set this gives Q1 = 5, Q3 = 16 and a median of 8.
Why must the values be sorted before entering them?
The expressions take the first two and last two positions literally. They only represent quartiles when the list is in ascending order. An unsorted entry still produces a number, but that number is the difference between two unrelated averages rather than a spread of the middle half.
What is the one and a half times IQR rule?
It sets outlier fences at Q1 minus 1.5 times the IQR and Q3 plus 1.5 times the IQR. For the default data the upper fence is 32.5 and the lower fence is -11.5. Points outside the fences are flagged for investigation, not automatically removed from the data.
Is the interquartile range better than the standard deviation?
It depends on the data. The interquartile range is more resistant to extremes and is natural for skewed distributions and box plots. The standard deviation uses every observation and supports much of statistical theory, but it reacts strongly to outliers. Report both when the shape of the distribution matters.
Does this method work for any number of observations?
The general definition of quartiles does, but the expressions here are specific to exactly five sorted values and the median-of-halves convention. Larger data sets need a consistent percentile rule, and sources differ on which one to use. Learn the mechanics here, then apply a stated convention to the real data.
References
- [1], Quartile — https://en.wikipedia.org/wiki/Quartile
- [2], Interquartile range — https://en.wikipedia.org/wiki/Interquartile_range
- [3], Outlier — https://en.wikipedia.org/wiki/Outlier
