Skip to content
simstat.com Statistics by simulation

IQR calculator: quartiles, fences and outliers

This IQR calculator finds the first and third quartiles of your data, the interquartile range (IQR = Q3 − Q1), the inner and outer fences, and any mild or extreme outliers, and draws a box plot. Choose the quartile method your textbook, calculator or software uses, and it shows every step of the working. Everything runs in your browser.

Separate values with commas, spaces or new lines, and leave out thousands separators. The example is the weight, in thousands of pounds, of the 32 cars in the mtcars data set that ships with R (from Motor Trend magazine, 1974).

Result

IQR = 1.1075

n
32
Q1
2.5425
Median
3.325
Q3
3.65
IQR
1.1075
Tukey fences
Fence Lower Upper
Inner (1.5 × IQR) 0.88125 5.31125
Outer (3 × IQR) −0.78 6.9725
  • Mild outliers (beyond an inner fence only): 5.345, 5.424
  • Extreme outliers (beyond an outer fence): none
  • Five-number summary (min, Q1, median, Q3, max): 1.513, 2.5425, 3.325, 3.65, 5.424
  • Whiskers end at 1.513 and 5.25
    Box plot with Tukey fences Box plot of 32 values: box from Q1 = 2.5425 to Q3 = 3.65, median 3.325, whiskers from 1.513 to 5.25, 2 mild outliers (5.345, 5.424) and no extreme outliers. 0123456
    Box: Q1 to Q3, with a thick line at the median. Whiskers: to the most extreme values inside the inner fences. Dashed lines: inner fences. Dotted lines: outer fences, when they fall inside the plotted range. Hollow circles: mild outliers. Filled diamonds: extreme outliers.

    Step by step

    Sorted data (x₁ is the smallest value):

    1.513, 1.615, 1.835, 1.935, 2.14, 2.2, 2.32, 2.465, 2.62, 2.77, 2.78, 2.875, 3.15, 3.17, 3.19, 3.215, 3.435, 3.44, 3.44, 3.44, 3.46, 3.52, 3.57, 3.57, 3.73, 3.78, 3.84, 3.845, 4.07, 5.25, 5.345, 5.424

    1. n = 32 is even, so the data split into two halves of 16 values.
    2. Median: the mean of the 16th and 17th values, (x₁₆ + x₁₇) / 2 = (3.215 + 3.435) / 2 = 3.325.
    3. Q1: the lower half is x₁ to x₁₆ (16 values). Its median is (x₈ + x₉) / 2 = (2.465 + 2.62) / 2 = 2.5425.
    4. Q3: the upper half is x₁₇ to x₃₂ (16 values). Its median is (x₂₄ + x₂₅) / 2 = (3.57 + 3.73) / 2 = 3.65.
    5. IQR = Q3 − Q1 = 3.65 − 2.5425 = 1.1075.
    6. Inner fences: Q1 − 1.5 × IQR = 0.88125 and Q3 + 1.5 × IQR = 5.31125.
    7. Outer fences: Q1 − 3 × IQR = −0.78 and Q3 + 3 × IQR = 6.9725.
    8. Outliers: mild outliers (beyond an inner fence only): 5.345, 5.424; no extreme outliers.
    9. Whiskers reach the most extreme values inside the inner fences: 1.513 and 5.25.

    To report it: The median was 3.325 (IQR 1.1075; Q1 = 2.5425, Q3 = 3.65, n = 32), with quartiles found as the median of each half of the data. Two values (5.345, 5.424) lay beyond the inner fences (0.88125 and 5.31125). Numbers are rounded to six significant digits for display; the calculation keeps full precision.

    What the interquartile range measures

    The quartiles split sorted data into four parts with about a quarter of the values in each. The interquartile range is the distance from the first quartile Q1 to the third quartile Q3, so it "indicates the spread of the middle half or the middle 50% of the data" (Illowsky and Dean, 2023). Unlike the range or the standard deviation, it ignores the most extreme values, which makes it a natural yardstick for spotting them. The subtraction is the easy part; the work, and the disagreement between textbooks and software, lies in finding Q1 and Q3.

    How this interquartile range calculator finds the quartiles

    Write x(1) ≤ … ≤ x(n) for the sorted data. All three methods use the ordinary median. Median of halves splits the data at the median; when n is odd the median belongs to neither half. Q1 and Q3 are the medians of the two halves:

    Q1=median⁡(x(1),…,x(m)),Q3=median⁡(x(n−m+1),…,x(n)),m=⌊n/2⌋Q_1 = \operatorname{median}\big(x_{(1)},\dots,x_{(m)}\big),\quad Q_3 = \operatorname{median}\big(x_{(n-m+1)},\dots,x_{(n)}\big),\quad m = \lfloor n/2 \rfloor

    This is the method of Illowsky and Dean (2023), and the "exclusive" method that Langford (2006) found in several textbooks and in the TI-83 Plus. The TI-84 Plus guidebook defines Q1 as "the median of points between minX and Med (median)", and Langford adds: "The TI-84 Plus and TI-89 seem to use the same method." Texas Instruments' TI-84 Plus CE activity Give Me Five! works the values 1 to 9 this way: Q1 is 2.5, the median of 1, 2, 3 and 4.

    The other two methods place each quartile at a position h in the sorted data and interpolate between the two nearest values, in the notation of Hyndman and Fan (1996) and R's quantile():

    Q(p)=x(j)+g (x(j+1)−x(j)),j=⌊h⌋,g=h−jQ(p) = x_{(j)} + g\,\big(x_{(j+1)} - x_{(j)}\big),\qquad j = \lfloor h \rfloor,\quad g = h - j
    type 7: h=(n−1)p+1,type 6: h=(n+1)p\text{type 7: } h = (n-1)p + 1, \qquad \text{type 6: } h = (n+1)p

    with p = 1/4 for Q1 and 3/4 for Q3. Type 7 is R's default. Microsoft describes QUARTILE.INC as based on percentiles "from 0..1, inclusive" and QUARTILE.EXC as "from 0 to 1, exclusive"; the examples on Microsoft's help pages match the type 7 and type 6 values, which our tests check. With n = 1 or 2, the type 6 position falls outside the data: the calculator then uses the minimum or maximum, as R does, while Excel "will return #NUM! error" when it cannot interpolate (Microsoft, PERCENTILE.EXC).

    Worked example

    Worked example: car weights, median of halves

    Take the weights of the 32 cars in R's mtcars data (R Core Team, 2024), in thousands of pounds: the calculator's default data. Sorted, the 16th and 17th values are 3.215 and 3.435, so the median is 3.325. With n even, each half has 16 values. The lower half runs from x₁ to x₁₆, so Q1 = (x₈ + x₉) / 2 = (2.465 + 2.62) / 2 = 2.5425. The upper half, x₁₇ to x₃₂, gives Q3 = (x₂₄ + x₂₅) / 2 = (3.57 + 3.73) / 2 = 3.65. So IQR = 3.65 − 2.5425 = 1.1075.

    The inner fences are 2.5425 − 1.5 × 1.1075 = 0.88125 and 3.65 + 1.5 × 1.1075 = 5.31125; the outer fences are −0.78 and 6.9725. The Chrysler Imperial (5.345) and the Lincoln Continental (5.424) lie above the upper inner fence but below the outer one, so they are mild outliers. The upper whisker stops at the next heaviest car, the Cadillac Fleetwood at 5.25.

    Upper and lower fences and outliers

    inner: Q1−1.5 IQR,  Q3+1.5 IQR;outer: Q1−3 IQR,  Q3+3 IQR\text{inner: } Q_1 - 1.5\,\mathrm{IQR},\ \ Q_3 + 1.5\,\mathrm{IQR}; \qquad \text{outer: } Q_1 - 3\,\mathrm{IQR},\ \ Q_3 + 3\,\mathrm{IQR}

    The fences belong to the box plot, which Tukey set out in Exploratory Data Analysis (1977; Langford, 2006). R's boxplot.stats(), whose documentation cites Tukey's book, draws whiskers that "extend to the most extreme data point which is no more than" 1.5 times the length of the box away from the box. R's box itself is drawn from Tukey's hinges, which equal the median of halves for even n and R's type 7 quartiles for odd n, so its fences can differ from this tool's default. The NIST/SEMATECH e-Handbook defines the inner and outer fences above and classifies the points: "A point beyond an inner fence on either side is considered a mild outlier. A point beyond an outer fence is considered an extreme outlier." This upper and lower fence calculator applies that rule strictly: a value exactly on a fence is not beyond it.

    As an outlier calculator, the tool flags values; it cannot explain them. A flagged value may be a typing error, a measurement problem or a genuine, important case. As Illowsky and Dean (2023) put it, "Potential outliers always require further investigation." Do not delete a value only because it lies beyond a fence.

    Why the quartile methods give different answers

    Langford (2006) counted "at least a dozen different ways" of computing quartiles in introductory courses and software, and Hyndman and Fan (1996) argue "that there is a need to adopt a standard definition for sample quantiles so that the same answers are produced by different packages". The methods differ only in where they put each quartile. For Q1 with n = 32, the positions are 8.5 (median of halves), 8.75 (type 7) and 8.25 (type 6). For odd n, the median of halves and type 6 always coincide, with Q1 at position (n + 1)/4 and Q3 at 3(n + 1)/4; for the values 1 to 9, Q1 is 2.5 by the median of halves, 3 by type 7 and 2.5 by type 6.

    The shift matters most near a fence. For the car weights:

    Quartiles, fences and outliers of the car weights by quartile method
    MethodQ1Q3IQRUpper inner fenceOutliers
    Median of halves 2.5425 3.65 1.1075 5.31125 5.345, 5.424
    R type 7 / QUARTILE.INC 2.58125 3.61 1.02875 5.15313 5.25, 5.345, 5.424
    QUARTILE.EXC / R type 6 2.50375 3.69 1.18625 5.46938 none

    The same data give 2, 3 or 0 outliers. None of the methods is wrong. Use the one your course, calculator or software uses, so that your numbers can be checked, and say which one you used.

    How to report it

    Give the median with the IQR (or the quartiles), n, the quartile method and the outlier rule. For example:

    The median was 3.325 (IQR 1.1075; Q1 = 2.5425, Q3 = 3.65, n = 32), with quartiles found as the median of each half of the data. Two values (5.345, 5.424) lay beyond the inner fences (0.88125 and 5.31125).

    For the working by hand, read our guides on how to find IQR and on upper and lower fences.

    For a single picture of the data, show the box plot. To see how a statistic such as the median varies from sample to sample, try our sampling distribution simulator; for an interval around the median, our bootstrap confidence interval tool.

    References