Skip to content
simstat.com Statistics by simulation

How to Find IQR (Interquartile Range): Formula and Examples

How to find IQR, the interquartile range: sort the data, split them at the median, and find the median of each half. The median of the lower half is the first quartile Q1, the median of the upper half is the third quartile Q3, and IQR = Q3 − Q1: the spread of the middle half of the data. Because it ignores the lowest and highest quarters, one extreme value barely moves it. Calculators and software place the quartiles in slightly different ways, so state the method you used.

Last updated · by the simstat.com editorial team · How we write

What is IQR?

Quartiles cut sorted data into four parts with about a quarter of the values in each. The first quartile, Q1, has about a quarter of the data below it; the third quartile, Q3, has about a quarter above it. The interquartile range (IQR) is the distance between them. Illowsky and Dean (2023) describe it as “a number that indicates the spread of the middle half or the middle 50% of the data”.

That definition explains why the IQR is used. It looks only at the middle half, so the lowest and highest quarters of the data, where any outliers lie, do not enter it. The NIST/SEMATECH e-Handbook contrasts it with the range and the standard deviation: “the range only uses the two most extreme points and the interquartile range only uses the middle portion of the data”, and “for data with extreme values in the tails, the median absolute deviation or interquartile range can provide a more stable estimate of spread than the standard deviation”. In other words, the IQR is resistant to outliers: one wild value cannot drag it far. The e-Handbook recommends the IQR, or a similar measure, when data are not normal, “in particular if there are long tails”.

The IQR pairs naturally with the median: both are read off the sorted data, and neither depends on the most extreme values.

The IQR formula

The IQR formula is a single subtraction (Illowsky and Dean, 2023):

IQR=Q3−Q1\mathrm{IQR} = Q_3 - Q_1

The work lies in finding Q1 and Q3. The method OpenStax teaches, and the default of our calculator, is the median of halves. Write x₁ ≤ x₂ ≤ … ≤ xₙ for the sorted data and m = ⌊n/2⌋ for the size of each half (n divided by 2, rounded down). Then

Q1=median⁡(x1,…,xm)Q_1 = \operatorname{median}(x_1, \dots, x_m)
Q3=median⁡(xn−m+1,…,xn)Q_3 = \operatorname{median}(x_{n-m+1}, \dots, x_n)

When n is odd, the overall median is the middle value and belongs to neither half. Langford (2006) calls this the “Exclusive” method: “in the case of n odd, the median value is excluded from both halves”. He lists several textbooks that use it, found that the TI-83 Plus uses it on his test data, and adds that the TI-84 Plus and TI-89 “seem to use the same method”.

How to find the interquartile range by hand

  1. Sort the data from smallest to largest and count them (n).
  2. Find the median. For odd n it is the middle value; for even n, the mean of the two middle values.
  3. Split the data into a lower and an upper half. For odd n, leave the median out of both halves.
  4. Find Q1 and Q3, the medians of the lower and upper halves.
  5. Subtract: IQR = Q3 − Q1.

Example with an odd number of values

The data come from Example 2.22 of the OpenStax textbook (Illowsky and Dean, 2023).

Worked example: minutes of exercise, n odd

A school principal asks 15 students how many minutes a day they exercise: 0, 40, 60, 30, 60, 10, 45, 30, 300, 90, 30, 120, 60, 0, 20.

Sort. 0, 0, 10, 20, 30, 30, 30, 40, 45, 60, 60, 60, 90, 120, 300. There are n = 15 values.

Median. n is odd, so the median is the 8th value, x₈ = 40.

Halves. Leaving the median out, each half has 7 values. Lower half: 0, 0, 10, 20, 30, 30, 30. Upper half: 45, 60, 60, 60, 90, 120, 300.

Quartiles. Each half has an odd number of values, so its median is its middle (4th) value: Q1 = x₄ = 20 and Q3 = x₁₂ = 60.

IQR = 60 − 20 = 40 minutes. About half of the students exercise between 20 and 60 minutes a day, the same values the textbook gives.

Example with an even number of values

Worked example: fourteen values, n even

Illowsky and Dean (2023) introduce quartiles with these 14 values: 1, 11.5, 6, 7.2, 4, 8, 9, 10, 6.8, 8.3, 2, 2, 10, 1.

Sort. 1, 1, 2, 2, 4, 6, 6.8, 7.2, 8, 8.3, 9, 10, 10, 11.5. There are n = 14 values.

Median. n is even, so the median is the mean of the 7th and 8th values: (6.8 + 7.2) / 2 = 7.

Halves. With n even, the data split cleanly into two halves of 7: x₁ to x₇ (1, 1, 2, 2, 4, 6, 6.8) and x₈ to x₁₄ (7.2, 8, 8.3, 9, 10, 10, 11.5).

Quartiles. Q1 is the middle value of the lower half, x₄ = 2; Q3 is the middle value of the upper half, x₁₁ = 9.

IQR = 9 − 2 = 7. The textbook gives the same median and quartiles.

When a half has an even number of values, its median is the mean of its two middle values, exactly as for the whole data. OpenStax’s Example 2.13 has 13 house prices, so each half has 6: Q1 is the mean of $230,500 and $387,000, $308,750; Q3 is the mean of $639,000 and $659,000, $649,000; and the IQR is $340,250.

Reading the IQR from a box plot

A box plot is built from five values: “the minimum value, the first quartile, the median, the third quartile, and the maximum value” (Illowsky and Dean, 2023). The box runs from Q1 to Q3, so the length of the box is the IQR, and “Approximately the middle 50 percent of the data fall inside the box”. To read the IQR off a box plot, read the values at the two ends of the box on the axis and subtract.

Here is the box plot of the exercise data, drawn by our calculator’s code:

−1000100200300

Box plot of the minutes of exercise. Box: Q1 to Q3, with a thick line at the median. Whiskers: to the most extreme values not beyond the inner fences (dashed lines). Dotted lines: outer fences. Filled diamond: a value beyond an outer fence.

The box spans 20 to 60, so the IQR is 40; the line inside it marks the median, 40. Some box plots mark outliers separately, and then, as OpenStax notes, “the whiskers are not extending to the minimum and maximum values”. The rule in OpenStax and in the NIST/SEMATECH e-Handbook puts fences 1.5 × IQR beyond the quartiles:

Q1−1.5×IQRandQ3+1.5×IQRQ_1 - 1.5 \times \mathrm{IQR} \quad \text{and} \quad Q_3 + 1.5 \times \mathrm{IQR}

Here 1.5 × IQR = 1.5 × 40 = 60, so the fences are 20 − 60 = −40 and 60 + 60 = 120. The upper whisker stops at 120, the largest value not beyond the fence (the rule R’s boxplot.stats() documentation gives; NIST’s wording, “smaller than” the fence, would stop it at the next value down, so a value exactly on a fence is a borderline case), and 300 is plotted on its own: Illowsky and Dean (2023) call it a potential outlier. The NIST/SEMATECH e-Handbook adds outer fences at 3 × IQR, here at 180, and our plot marks 300 as lying beyond that one too.

IQR vs range vs standard deviation

What does one outlier do to each measure of spread? OpenStax recomputes the exercise summary without the 300-minute answer and finds the same quartiles. Here are three measures with and without it:

Measure of spreadAll 15 studentsWithout 300 (n = 14)
Range (max − min)300120
Standard deviation74.033.8
IQR (median of halves)4040

One student’s answer makes the range 2.5 times and the standard deviation 2.2 times as large, while the IQR stays at 40 (Q1 = 20 and Q3 = 60 either way). That is the stability the e-Handbook describes. It cuts both ways: the IQR says nothing about the tails, so a data set can have a modest IQR and extreme values. Look at the box plot, or the frequency distribution and histogram, as well as the number.

The standard deviation still has its place. NIST/SEMATECH notes that when the data are “reasonably approximated by a normal distribution, then it makes sense to use the standard deviation as the estimate of scale”. R’s documentation of IQR() adds a link between the two: a normal distribution’s IQR is 1.349 standard deviations, so IQR / 1.349 estimates the standard deviation.

Why quartile methods differ

If your answer disagrees with a calculator or with software, check the quartile method first. Langford (2006) found that the calculation of quartiles in an elementary statistics course “is done in at least a dozen different ways, depending on the text or computer/calculator package being used”. Hyndman and Fan (1996) compared the definitions most often found in statistical packages and argued “that there is a need to adopt a standard definition for sample quantiles so that the same answers are produced by different packages”.

The interpolating methods put a quantile at a position h in the sorted data and, when h falls between two values, go part of the way from one to the next. R’s documentation (R Core Team, 2024), following Hyndman and Fan (1996), writes every quartile in this form:

Q(p)=xj+g (xj+1−xj),j=⌊h⌋,g=h−jQ(p) = x_j + g\,(x_{j+1} - x_j), \qquad j = \lfloor h \rfloor,\quad g = h - j

with p = 0.25 for Q1 and 0.75 for Q3. Type 7, R’s default, uses h = 1 + (n − 1)p; NIST/SEMATECH says this “is the method used by Excel and is the default method for R”. Type 6 uses h = (n + 1)p, the method the e-Handbook itself describes. Microsoft describes its Excel function QUARTILE.INC as based on percentiles “from 0..1, inclusive” and QUARTILE.EXC as “from 0 to 1, exclusive” (Microsoft, n.d.); the examples on its help pages give exactly the type 7 and type 6 values.

For the 14 values, Q1 sits at position 4 by the median of halves, 4.25 by type 7 and 3.75 by type 6. Q3 by type 7 sits at position 10.75, between x₁₀ = 8.3 and x₁₁ = 9, so g = 0.75 and Q3 = 8.3 + 0.75 × (9 − 8.3) = 8.825. The three methods give:

Quartile methodQ1Q3IQRIQR, exercise data
Median of halves29740
R type 7 / QUARTILE.INC2.58.8256.32535
QUARTILE.EXC / R type 629.257.2540

The first three columns are for the 14 values. For the exercise data, with n odd, the median of halves and type 6 agree, as they always do for odd n; type 7 gives Q1 = 25 and IQR = 35.

None of these is wrong; they are different conventions. Langford (2006) quotes Freund and Perles (1987) on why the choice still matters: “if quartiles are used, say to establish criteria for making decisions, the method of their calculation becomes of critical concern”. Use the method your course, calculator or software uses, and say which one you used. The examples in this article use the median of halves.

How to report the IQR

Give the median with the IQR (or with Q1 and Q3), the sample size and the quartile method:

The students exercised a median of 40 minutes a day (IQR 40; Q1 = 20, Q3 = 60; n = 15), with quartiles found as the medians of the lower and upper halves. One answer, 300 minutes, lay beyond the upper fence Q3 + 1.5 × IQR = 120.

Report Q1 and Q3 as well as their difference when you can: they show where the middle half lies, not just how wide it is. If you flag outliers, name the rule.

Common mistakes

Forgetting to sort. Quartiles are positions in ordered data. Taking the “middle” of the raw list gives a number with no meaning.

Including the median in both halves when your course excludes it. For odd n, Langford’s (2006) “Inclusive” method puts the median in both halves and the “Exclusive” method leaves it out. With the exercise data, including it gives Q1 = 25 instead of 20. Check which one your textbook uses.

Checking a hand answer against software that uses another method. R’s IQR() computes quantile(x, 3/4) − quantile(x, 1/4) with type 7 by default, so for the exercise data it returns 35, not 40. R’s boxplot() draws its box at Tukey’s hinges, which R’s documentation says “equal the quartiles for odd n”, meaning its type 7 quartiles: here the box starts at 25, the upper fence falls at 112.5, and both 120 and 300 are flagged. Before deciding which answer is wrong, compare the methods.

Reporting the IQR as an interval. “IQR = 20–60” is the pair of quartiles, not the IQR. The IQR is one number, Q3 − Q1 = 40.

Deleting the values beyond the fences. A fence flags a value for a closer look; it does not prove an error. Illowsky and Dean (2023) put it plainly: “Potential outliers always require further investigation.”

Where to go next

Our IQR calculator finds the quartiles by all three methods, with the fences, outliers, box plot and working shown. To flag outliers by hand, read about upper and lower fences; the statistics hub collects our other guides and calculators. The IQR of a sample varies from sample to sample like any statistic; the guide to the sampling distribution explains that variation, and the guide to bootstrap confidence intervals shows one way to put an interval around a median or another statistic.

References

  1. Illowsky, B. & Dean, S. (2023). Introductory Statistics 2e, Section 2.3: Measures of the Location of the Data. OpenStax, Rice University.
  2. Illowsky, B. & Dean, S. (2023). Introductory Statistics 2e, Section 2.4: Box Plots. OpenStax, Rice University.
  3. NIST/SEMATECH (2012). e-Handbook of Statistical Methods, Section 1.3.5.6: Measures of Scale. National Institute of Standards and Technology.
  4. NIST/SEMATECH (2012). e-Handbook of Statistical Methods, Section 1.3.3.7: Box Plot. National Institute of Standards and Technology.
  5. NIST/SEMATECH (2012). e-Handbook of Statistical Methods, Section 7.2.6.2: Percentiles. National Institute of Standards and Technology.
  6. Langford, E. (2006). Quartiles in Elementary Statistics. Journal of Statistics Education, 14(3).
  7. Hyndman, R. J. & Fan, Y. (1996). Sample Quantiles in Statistical Packages. The American Statistician, 50(4), 361–365.
  8. R Core Team (2024). R documentation: quantile(), IQR() and boxplot.stats() (stats and grDevices packages). R Foundation for Statistical Computing.
  9. Microsoft (n.d.). QUARTILE.INC function (Microsoft Support help page; the QUARTILE.EXC page is at support.microsoft.com/en-us/office/quartile-exc-function-5a355b7a-840b-4a01-b0f1-f538c2864cad). Microsoft (undated help pages, accessed December 2026).

Try it

Related reading