How to Calculate the Interquartile Range (IQR)

The Interquartile Range (IQR) measures the spread of the middle 50% of a dataset. It's the difference between the 75th percentile (Q3) and the 25th percentile (Q1), making it a robust measure of variability that isn't distorted by outliers.

The Formula

IQR = Q3 − Q1

Step-by-Step Example

Dataset: 45

Step 1: Sort the data (already sorted above).

Step 2: Find the median (Q2). Median = 21 (5th value in 9-element set)

Step 3: Find Q1 — the median of the lower half 15. Q1 = (7 + 8) / 2 = 7.5

Step 4: Find Q3 — the median of the upper half 45. Q3 = (30 + 32) / 2 = 31

Step 5: Calculate IQR. IQR = 31 − 7.5 = 23.5

Using IQR to Detect Outliers

A common rule: any value below Q1 − 1.5×IQR or above Q3 + 1.5×IQR is considered an outlier.

Lower fence: 7.5 − 1.5×23.5 = 7.5 − 35.25 = −27.75 Upper fence: 31 + 1.5×23.5 = 31 + 35.25 = 66.25

No values in our dataset fall outside these fences, so there are no outliers.

IQR vs. Standard Deviation

IQR is preferred over standard deviation when:

  • The data is skewed or has outliers
  • You want a median-based summary (IQR pairs with median; SD pairs with mean)
  • You're analyzing income, home prices, or other right-skewed distributions

Use our IQR calculator for any dataset.