IQR Calculator
Find Q1, Q3 and the interquartile range with full steps. Paste comma-separated numbers or upload a CSV, compare up to eight groups, flag outliers with the 1.5 IQR rule, and see box plots, fences and the formulas behind every number.
⚡ 0. Quick Answer
An IQR calculator finds the interquartile range: the third quartile minus the first quartile, IQR = Q3 − Q1.
Sort the data, find Q1 (25th percentile) and Q3 (75th percentile), then subtract. For 46, 47, 48, 49, 50, 50, 51, 52, 53, 54, 55, 56, 57, 58, 61, 82, Excel’s QUARTILE.INC gives Q1 = 49.75 and Q3 = 56.25, so IQR = 6.5. Values outside Q1 − 1.5 × IQR and Q3 + 1.5 × IQR are outliers, so 82 is flagged.
Rule of thumb: report the median with the IQR when data are skewed or contain outliers, and always say which quartile method you used, because Excel, a TI-84 and a textbook can give different Q1 and Q3 for the same numbers.
🔑 Key Takeaways
- This IQR calculator returns Q1, the median, Q3, the IQR, fences and outliers for up to 8 groups at once.
- The IQR covers the middle 50% of your data, so one extreme value cannot change it much.
- The 1.5 × IQR rule flags outliers; values beyond 3 × IQR are extreme outliers.
- For normal data the IQR is about 1.349 × SD, so SD ≈ IQR ÷ 1.35.
- Four quartile methods are shown side by side, so your answer can match Excel, R, Python, SPSS or a TI-84.
📚 1. What Is the Interquartile Range (IQR)?
The interquartile range (IQR) is the distance between the first quartile (Q1) and the third quartile (Q3). Quartiles cut sorted data into four parts with the same number of values. Q1 has 25% of the data below it, the median (Q2) has 50% below it, and Q3 has 75% below it. The IQR is the width of the middle half.
What it measures: spread. A small IQR means the typical values sit close together. A large IQR means they are spread out. Because the IQR ignores the lowest 25% and the highest 25%, it is a robust measure: a single wrong value or extreme case barely moves it. The range and the standard deviation can both be pulled a long way by one point.
A worked one-liner: for 3, 5, 7, 8, 12, 13, 14, 21 (n = 8), the lower half 3, 5, 7, 8 has median 6 and the upper half 12, 13, 14, 21 has median 13.5. By hand, IQR = 13.5 − 6 = 7.5. Excel’s QUARTILE.INC gives 13.25 − 6.5 = 6.75. Both are correct, they simply use different rules.
Who uses it: clinicians report median (IQR) for length of stay and lab values, economists use it for income, ecologists use it for body size and home-range data, teachers use it for exam scores, and data scientists use the 1.5 IQR rule to clean data before modelling.
| Measure of spread | Uses | Affected by outliers? | Pair it with |
|---|---|---|---|
| IQR | Q1 and Q3, the middle 50% | Hardly at all | Median |
| Range | Only the minimum and maximum | Completely | Nothing on its own |
| Standard deviation | Every value, squared distance from the mean | Strongly | Mean |
| Median absolute deviation | Middle of absolute distances from the median | Hardly at all | Median |
🧮 2. Set Up Your Data
Type or paste numbers separated by commas (the default), spaces, tabs or new lines. Each box is one group, and its name is editable. Nothing is calculated until you press Calculate IQR.
Type one value per cell. Each column becomes a cluster and the header cell is its editable name. Empty cells are ignored, so groups can have different sizes.
🔄 Quick converters: IQR from mean and SD, or mean and SD from median and IQR
A. Mean and SD → Q1, Q3 and IQR
Assumes a normal distribution. Q1 = μ − 0.6745σ, Q3 = μ + 0.6745σ.
B. Median, Q1, Q3 → estimated mean and SD
Wan et al. (2014) method, used in meta-analysis when a paper reports median (IQR) only.
📊 3. Results
🧠 4. Interpretation of Results, In Detail
4.1 What the IQR actually tells you
The IQR is the width of the band that holds the middle half of your observations. If the IQR of systolic blood pressure is 18 mmHg, then half of the patients sit inside an 18 mmHg window. That is a concrete, easy statement, and it stays true whatever happens in the tails.
It does not tell you where the band is. An IQR of 18 could run from 110 to 128 or from 150 to 168. That is why the IQR is always reported with the median, and ideally with Q1 and Q3 as well, so the reader can see both the location and the width.
4.2 Reading Q1, the median and Q3 together
The three quartiles split the sorted data into four groups of equal size. Look at the two gaps inside the box. If the median sits in the middle of the box, the middle half is symmetric. If the gap from the median up to Q3 is larger than the gap down to Q1, the upper half is more spread out, which is right skew. Bowley skewness puts a number on this: (Q3 + Q1 − 2 × median) ÷ IQR. It runs from −1 to +1, and values beyond ±0.2 are worth mentioning.
4.3 The 1.5 IQR rule for outliers, and what to do with a flag
John Tukey proposed fences at 1.5 IQR below Q1 and above Q3. For normal data only about 0.7% of values fall outside them, so a value beyond a fence is unusual. Values beyond 3 IQR (the outer fences) are extreme. A flag is a question, not a verdict. First check for typing errors, unit mix-ups (grams entered as kilograms), and missing-value codes like −999. If the value is real, keep it and use methods that resist it, such as the median, the IQR, or a non-parametric test. Deleting real values because they are inconvenient is a form of bias.
The 1.5 IQR rule flags too many values in large samples. With n = 1,000 normal values you should expect about 7 flags even when nothing is wrong. For big datasets, or for heavily skewed data, consider the 2.2 multiplier of Hoaglin and Iglewicz or a log transform before screening.
4.4 Why your IQR may differ from Excel, a TI-84 or a textbook
There is no single agreed definition of a sample quartile. Hyndman and Fan (1996) listed nine. Excel’s QUARTILE.INC, R’s default and NumPy all use type 7, which interpolates at position 1 + (n − 1)p. Excel’s QUARTILE.EXC, Minitab and SPSS use type 6, position (n + 1)p. A TI-84 and most school textbooks take the median of the lower and upper halves. The differences are largest with small samples and odd n. With the textbook set 6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49, Q1 is 15 by hand but 25.5 in Excel. Neither is wrong. Pick one, state it, and use it for every group.
4.5 IQR versus standard deviation: which one to report
If the data are roughly normal, the SD and IQR carry the same information, and IQR ≈ 1.349 × SD. If the data are skewed, have outliers or are on an ordinal scale, the SD is inflated by the tail and describes nobody well. Then the median with IQR is the honest summary. The calculator reports the IQR ÷ SD ratio: well below 1.349 means heavy tails or outliers; near 1.349 means the two measures agree.
4.6 Comparing IQRs across groups
Comparing IQRs is a fair way to compare spread when groups differ in size or contain outliers. A group with an IQR twice as large has a middle half twice as wide. When the groups have very different medians, you can also compare the quartile coefficient of dispersion, (Q3 − Q1) ÷ (Q3 + Q1), which is unit-free. Remember that two different IQRs do not prove a real difference in spread; a Levene, Brown-Forsythe or Fligner-Killeen test does that.
4.7 Ties, ordinal data and an IQR of zero
With Likert scores or counts, many values tie. If more than half the values share one score, Q1 and Q3 can be equal and the IQR becomes 0. Then every other value lies outside the fences and the outlier rule flags them all, which is meaningless. When that happens, report the percentage in each category instead, or report the median and the full range.
4.8 Decision guide
| What you see | What it means | What to report |
|---|---|---|
| Median near the centre of the box, no outliers, IQR ÷ SD near 1.35 | Roughly normal | Mean (SD), optionally median (IQR) |
| Median closer to Q1, long upper whisker | Right skew | Median (IQR) [Q1, Q3] |
| One or two mild outliers | Possible errors or a natural tail | Median (IQR), and state how outliers were handled |
| Extreme outliers beyond 3 IQR | Data error or a different population | Check the records first, then median (IQR) |
| IQR = 0 | Heavy ties | Category percentages, median and range |
| Methods disagree a lot | Small n or odd n | Name the method and show Q1 and Q3 |
4.9 Common mistakes this calculator prevents
- Forgetting to sort the data before finding Q1 and Q3. The steps panel shows the sorted list first.
- Mixing quartile methods between groups or between software. The method table shows all four.
- Reporting the range as the spread when one value dominates it. The range and IQR sit side by side.
- Treating −999 or text entries as data. Non-numeric entries are skipped and named; missing-value codes trigger a warning.
- Deleting flagged values automatically. The output labels them mild or extreme and asks you to check them.
- Reporting IQR as a single number with no quartiles. The report templates give median (IQR) [Q1, Q3].
4.10 Practical judgement
Look at the box plot before you look at any number. Then read the IQR with the median, check whether the fences flag anything, and decide whether those flags are errors or real. Finally, pick your quartile method once and keep it for the whole study. In twelve years of field data on animal movement and body size, the most common problem has not been the formula but a stray decimal point or a missing-value code, and the 1.5 IQR screen catches exactly those.
✍ 5. How to Write Your Results in Research
When reporting IQR calculator results in APA format, give the median with the IQR, add Q1 and Q3 when space allows, name the quartile method, and say how outliers were defined and handled. The five templates below fill in automatically after you press Calculate.
📌 Key conventions for this style
- Write Mdn and IQR in italics in APA; both use the same units as the data.
- Many journals prefer Q1 and Q3 as a pair, written as [Q1, Q3] or "Q1 to Q3".
- Use the same number of decimals as your measurements, usually one or two.
- State the number of outliers and whether they were kept.
📌 Key conventions for this style
- Justify the choice of median and IQR with evidence of skew or outliers.
- Name the quartile definition; examiners ask when numbers differ from Excel.
- Describe the outlier rule and what you did with flagged values before seeing results.
- Name the software and version used.
📌 Key conventions for this style
- Say "the middle half of values" instead of IQR.
- Say "typical value" for the median.
- Give units every time.
- Describe unusual values in words, not as "outliers".
📌 Key conventions for this style
- Declare the format once, in the table note or methods line.
- Do not mix mean (SD) and median (IQR) rows without marking which is which.
- Keep decimal places the same down each column.
- In abstracts, the [Q1, Q3] form is clearer than the single IQR number.
📌 Key conventions for this style
- Give the exact function call, so another team gets identical numbers.
- Pre-register the fence multiplier and what happens to flagged values.
- Record whether outliers were removed before or after other analyses.
- Share the raw data, since quartiles cannot be rebuilt from summaries.
∑ 6. Formulas Used
🔀 7. IQR Calculation Flowchart, Step by Step
This flowchart shows how the IQR is calculated, step by step, from a raw column of numbers to Q1, Q3, the fences and the outlier decision. Every box uses the same worked example as the Excel, R and Python sections: 16 leaf lengths in millimetres from Site A, with one long leaf at 82 mm.
Check any box yourself: the Excel sheet in Section 9, the R script in Section 10 and the Python script in Section 11 all return Q1 = 49.75, Q3 = 56.25 and IQR = 6.5 for this dataset.
📝 8. How to Use This IQR Calculator
- Enter your data. Type or paste numbers into the first box, separated by commas as the placeholder shows: 52, 48, 55, 61, 47, ... Spaces, tabs and new lines also work, so a column copied from Excel is fine.
- Name each group. The name above each box is editable. Type something meaningful, such as Site A or Control, and it flows into the tables, charts and report sentences.
- Add more groups if you need them. Press Add cluster to compare up to eight groups side by side. Each box has its own Clear and Remove buttons.
- Or upload a CSV or Excel file. On the Upload tab, choose a file, then click every column you want. Each selected column is loaded as its own cluster, named after its header.
- Or use the manual table. Type values into the grid, one column per group, and press Use this table.
- Try a sample dataset. Ten built-in datasets cover clean data, skew, outliers, ties, small samples, three groups and a deliberately messy sensor log.
- Choose the quartile method. Inclusive matches Excel QUARTILE.INC, R and Python. Exclusive matches SPSS. Median of halves matches a TI-84 and most textbooks.
- Choose the fence multiplier. 1.5 is the standard Tukey rule. Use 2.2 for large samples or 3 to flag only extreme outliers.
- Press Calculate IQR. Nothing is computed until you press the button. Changing any input clears old results so you never read stale numbers.
- Read, check and export. Read the IQR and outlier panel, look at the four charts, copy a report sentence from Section 5, and download the text report or PDF.
📈 9. How to Calculate the IQR in Excel
Excel has no IQR function, but two quartile functions and one subtraction do the job. The part that confuses people is that Excel has two quartile functions that give different answers, and neither matches the hand method taught in most schools. This section uses the 16 leaf lengths from Section 7 and shows the spreadsheet at every step.
=QUARTILE.INC(A2:A17,3)-QUARTILE.INC(A2:A17,1). That is the IQR, 6.5 here.9.1 The functions you need
| You want | Excel function | Note |
|---|---|---|
| Q1, inclusive | =QUARTILE.INC(A2:A17,1) | Same as R type 7 and NumPy; the default on this page |
| Q3, inclusive | =QUARTILE.INC(A2:A17,3) | The 2 argument gives the median, 0 the min, 4 the max |
| Q1 and Q3, exclusive | =QUARTILE.EXC(A2:A17,1) | Same as SPSS and Minitab; needs at least 3 values |
| Any percentile | =PERCENTILE.INC(A2:A17,0.25) | Identical to QUARTILE.INC with k = 0.25 |
| Median | =MEDIAN(A2:A17) | Same in every method |
| IQR | =C4-C2 | Q3 cell minus Q1 cell |
| Count outliers | =COUNTIF(A2:A17,"<"&C6)+COUNTIF(A2:A17,">"&C7) | C6 and C7 hold the fences |
| Old name | =QUARTILE(A2:A17,1) | Kept for compatibility; same as QUARTILE.INC |
9.2 Step by step
1 Put the numbers in one column
Type or paste the values down column A with a label in A1. The quartile functions skip the text header automatically. You do not need to sort the data first; Excel sorts internally.
The 16 leaf lengths sit in A2:A17. Only the first eight rows are shown.
2 Find Q1 and Q3 with QUARTILE.INC
In a summary block, use 1 for Q1 and 3 for Q3. Add the median with MEDIAN so you have all three quartiles together.
=QUARTILE.INC(A2:A17,1)=MEDIAN(A2:A17)=QUARTILE.INC(A2:A17,3)C2 returns Q1 = 49.75, C3 the median 52.5 and C4 Q3 = 56.25.
3 Subtract to get the IQR
The IQR is simply Q3 minus Q1. Referencing the cells keeps the sheet live if the data change.
=C4-C2C5 returns IQR = 6.5, the same as R, Python and this calculator.
4 Build the 1.5 IQR fences and count outliers
The fences sit 1.5 IQR outside the box. COUNTIF then counts the values beyond them.
=C2-1.5*C5=C4+1.5*C5=COUNTIF(A2:A17,"<"&C6)+COUNTIF(A2:A17,">"&C7)Fences 40 (C6) and 66 (C7). C8 counts 1 outlier.
5 Flag each outlier row by row
On the data sheet, add a flag column so you can see which row is unusual. The dollar signs lock the fence cells on the Summary sheet when you fill the formula down.
=IF(OR(Summary!$C$6>A2,A2>Summary!$C$7),"Outlier","")Filled down to row 17, only 82 in A17 is flagged. Rows 12 to 17 are shown.
6 Check the exclusive version if you use SPSS
QUARTILE.EXC uses the (n + 1)p rule from SPSS and Minitab. It gives a wider IQR for small samples.
=QUARTILE.EXC(A2:A17,1)=QUARTILE.EXC(A2:A17,3)Q1 = 49.25 and Q3 = 56.75, so the exclusive IQR is 7.5, not 6.5.
9.3 The awkward cases: median and IQR together, groups, and odd n
Median and IQR in one cell, ready for a table: =TEXT(MEDIAN(A2:A17),"0.0")&" ("&TEXT(C5,"0.0")&")" returns 52.5 (6.5).
IQR for one group in a long table (values in A, group names in B): Excel 365 can filter inside the function.
=QUARTILE.INC(FILTER(A2:A200,B2:B200="Site A"),3)-QUARTILE.INC(FILTER(A2:A200,B2:B200="Site A"),1)
In older Excel, use a PivotTable to split the groups into columns first, then apply QUARTILE.INC to each column.
Matching the TI-84 or a textbook. Excel has no median-of-halves function. With n = 16, the lower half is A2:A9 once sorted, so =MEDIAN(SMALL(A2:A17,{1,2,3,4,5,6,7,8})) gives Q1 = 49.5 and =MEDIAN(LARGE(A2:A17,{1,2,3,4,5,6,7,8})) gives Q3 = 56.5. The easier route is to set the method in this calculator to Median of halves.
9.4 Why your Excel answer might differ from R, Python, SPSS or a calculator
| Software and function | Method | Q1 | Q3 | IQR |
|---|---|---|---|---|
| Excel QUARTILE.INC, Google Sheets QUARTILE | Type 7 | 49.75 | 56.25 | 6.5 |
R quantile(), IQR() | Type 7 | 49.75 | 56.25 | 6.5 |
Python np.percentile, scipy.stats.iqr, pandas | Linear (type 7) | 49.75 | 56.25 | 6.5 |
| Excel QUARTILE.EXC, SPSS, Minitab | Type 6 | 49.25 | 56.75 | 7.5 |
| TI-84 1-Var Stats, textbooks | Median of halves | 49.5 | 56.5 | 7 |
R fivenum(), boxplot() | Tukey hinges | 49.5 | 56.5 | 7 |
IQR() gives 6.5, but R’s own boxplot() draws its box from the hinges, 49.5 to 56.5. So the box in an R plot is 7 wide while the number printed is 6.5. Neither is a bug; they are different definitions.9.5 Making a box plot in Excel
- Select the data column, including the header.
- Insert → Insert Statistic Chart → Box and Whisker (Excel 2016 and later).
- Right-click the box, choose Format Data Series, and set Quartile Calculation to Inclusive median to match QUARTILE.INC, or Exclusive median to match QUARTILE.EXC.
- Tick Show outlier points. Excel uses the 1.5 IQR rule for the whiskers.
- For groups, put each group in its own column and select them all before inserting.
Chart 1 in Section 3 draws the same box plot with the fences marked, which Excel cannot show.
9.6 Excel errors you will probably hit
| Excel shows | Why | Fix |
|---|---|---|
#NUM! from QUARTILE.EXC | Too few values, or the quart argument is 0 or 4 | Use at least 3 values and a quart of 1, 2 or 3 |
#NUM! from QUARTILE.INC | The quart argument is below 0 or above 4 | Use 0 to 4 only |
#VALUE! | The quart argument is text | Type the number 1 or 3, not "Q1" |
| IQR too small or zero | Numbers stored as text are being skipped | Look for green triangles, then Convert to Number |
| Fence count looks wrong | Fence cells were not locked when copied | Use $C$6 and $C$7 in row-by-row flags |
| Different from your calculator | The TI-84 uses the median of halves | Compare with the method table in Section 3 |
📈 10. How to Calculate the IQR in R
R has a built-in IQR() function, so the number itself is one word. The script below goes further: it prints Q1, the median, Q3, the IQR, both sets of fences and every outlier with a plain-English verdict, then saves one publication-ready box plot at 300 dpi whose box matches the printed IQR. It uses base R only.
Rscript. Change only the x <- c(...) line to use your own data.10.1 The complete script
R, base only, saves iqr_plot.png
# ============================================================
# IQR, quartiles, Tukey fences and outliers with one box plot
# StatsUnlock - https://statsunlock.com/iqr-calculator/
# Base R only. No packages to install.
# ============================================================
# ---- 1. Your data ------------------------------------------
# Replace with your own values, or read a CSV:
# x <- read.csv("data.csv")$column_name
x <- c(52, 48, 55, 61, 47, 50, 58, 53,
49, 56, 51, 54, 46, 57, 50, 82)
x <- x[!is.na(x)] # drop missing values
label <- "Site A leaf length"
units <- "mm"
k <- 1.5 # fence multiplier (3 = extreme only)
# ---- 2. Quartiles and IQR ----------------------------------
q <- unname(quantile(x, c(0.25, 0.50, 0.75), type = 7))
q1 <- q[1]; med <- q[2]; q3 <- q[3]
iqr_x <- IQR(x, type = 7) # same as q3 - q1
# ---- 3. Fences and outliers --------------------------------
lower <- q1 - k * iqr_x
upper <- q3 + k * iqr_x
lower2 <- q1 - 2 * k * iqr_x # outer fences
upper2 <- q3 + 2 * k * iqr_x
outliers <- sort(x[x < lower | x > upper])
extreme <- sort(x[x < lower2 | x > upper2])
# ---- 4. Plain-English summary ------------------------------
cat(sprintf("n = %d\n", length(x)))
cat(sprintf("Q1 = %.3f Median = %.3f Q3 = %.3f\n", q1, med, q3))
cat(sprintf("IQR = %.3f %s\n", iqr_x, units))
cat(sprintf("Fences: %.3f to %.3f (outer %.3f to %.3f)\n",
lower, upper, lower2, upper2))
if (length(outliers) == 0) {
cat("Verdict: no outliers by the 1.5 x IQR rule.\n")
} else {
cat(sprintf("Verdict: %d outlier(s): %s\n", length(outliers),
paste(outliers, collapse = ", ")))
if (length(extreme) > 0)
cat(sprintf("Extreme (beyond outer fence): %s\n",
paste(extreme, collapse = ", ")))
}
cat(sprintf("Report: Mdn = %.2f %s (IQR = %.2f, Q1 = %.2f, Q3 = %.2f, n = %d)\n",
med, units, iqr_x, q1, q3, length(x)))
# ---- 5. One publication-ready box plot ---------------------
# bxp() draws the box from OUR type 7 quartiles. boxplot() would
# use Tukey hinges (49.5 and 56.5) and not match IQR().
inside <- x[x >= lower & x <= upper]
stats <- matrix(c(min(inside), q1, med, q3, max(inside)), ncol = 1)
png("iqr_plot.png", width = 2400, height = 1200, res = 300)
par(mar = c(4.5, 2, 2.5, 1))
bxp(list(stats = stats, n = length(x), out = outliers,
group = rep(1, length(outliers)), names = ""),
horizontal = TRUE, boxfill = adjustcolor("#16a34a", 0.30),
border = "#166534", medlwd = 3, outpch = 19, outcol = "#c2410c",
outcex = 1.6, ylim = range(c(x, lower, upper)), axes = FALSE)
axis(1)
box(bty = "l")
set.seed(42) # reproducible jitter
points(x, 1 + runif(length(x), -0.12, 0.12), pch = 16,
col = adjustcolor("grey30", 0.45), cex = 0.9)
abline(v = c(lower, upper), lty = 2, lwd = 1.5, col = "#9333ea")
title(main = sprintf("%s: IQR = %.2f %s", label, iqr_x, units),
xlab = sprintf("Value (%s)", units), font.main = 1)
dev.off()
cat("Saved iqr_plot.png\n")
Run it with Rscript iqr_plot.R, or paste it into the RStudio console. The figure appears as iqr_plot.png in the folder shown by getwd().
10.2 What each part does
| Line or function | What it does, and why it is there |
|---|---|
| x <- c(...) | Builds the numeric vector. Swap in read.csv("data.csv")$column to load a file. |
| x[!is.na(x)] | Drops missing values. quantile() stops with an error if any NA is present. |
| quantile(x, ..., type = 7) | Q1, median and Q3 with the same rule as Excel QUARTILE.INC. Change to type = 6 to match SPSS. |
| unname() | Strips the "25%" labels so the numbers print cleanly. |
| IQR(x) | Q3 minus Q1 with type 7. IQR(x, type = 6) gives the SPSS value. |
| k * iqr_x | The fence distance. k = 1.5 is Tukey’s standard; 3 gives the outer fences. |
| x[x < lower | x > upper] | Picks out the outliers. The vertical bar means "or". |
| sprintf() | Formats numbers; %.3f means three decimals. |
| png(..., res = 300) | Opens a 300 dpi file, the minimum most journals accept. |
| bxp() | Draws a box plot from statistics you supply, so the box uses your type 7 quartiles instead of R’s hinges. |
| abline(v = ...) | Adds the dashed fence lines so readers see why a point is flagged. |
| set.seed(42) | Fixes the jitter so the figure is identical every time. |
| dev.off() | Closes and saves the file. Forgetting it leaves an empty PNG. |
10.3 What the figure shows
The figure is a horizontal box plot. The box runs from Q1 = 49.75 to Q3 = 56.25 with a thick line at the median, 52.5. The whiskers stop at 46 and 61, the last values inside the fences. The dashed purple lines are the fences at 40 and 66, and the orange point at 82 is the outlier. Grey jittered dots show every raw value so readers can see the sample size.
10.4 Common R problems and fixes
| Symptom | Cause | Fix |
|---|---|---|
| Error: missing values and NaN not allowed | NA in the vector | Use quantile(x, .25, na.rm = TRUE) or clean first |
IQR() differs from the boxplot box | boxplot() uses Tukey hinges | Use bxp() as in the script, or report fivenum() |
| Different from SPSS | SPSS uses type 6 | quantile(x, c(.25,.75), type = 6) |
| Different from a TI-84 | The TI-84 uses the median of halves | fivenum(x) matches it when n is even |
| Empty PNG file | dev.off() was not run | Run dev.off() until it says "null device" |
| IQR by group needed | One vector only | tapply(df$value, df$group, IQR) |
10.5 Useful one-liners
| You want | R code |
|---|---|
| IQR | IQR(x) |
| Q1 and Q3 | quantile(x, c(0.25, 0.75)) |
| Five-number summary, Tukey hinges | fivenum(x) |
| Summary with quartiles | summary(x) |
| Outliers by the 1.5 IQR rule | boxplot.stats(x)$out |
| IQR by group (dplyr) | df |> group_by(g) |> summarise(iqr = IQR(v)) |
| Robust SD from IQR | IQR(x) / 1.349 |
| IQR in RStudio for a data frame column | IQR(df$column, na.rm = TRUE) |
📈 11. How to Calculate the IQR in Python
In Python the IQR is one line with NumPy, SciPy or pandas. The script below prints the same Q1, median, Q3, IQR, fences and outliers as R and Excel, then saves a 300 dpi box plot with the raw values and fences drawn on.
iqr() function, used as a cross-checkInstall once with pip install numpy scipy matplotlib pandas.
11.1 The complete script
Python 3, saves iqr_plot.png
# ============================================================
# IQR, quartiles, Tukey fences and outliers with one box plot
# StatsUnlock - https://statsunlock.com/iqr-calculator/
# pip install numpy scipy matplotlib
# ============================================================
import numpy as np
import matplotlib
matplotlib.use("Agg") # save without opening a window
import matplotlib.pyplot as plt
from scipy import stats
# ---- 1. Your data ------------------------------------------
x = np.array([52, 48, 55, 61, 47, 50, 58, 53,
49, 56, 51, 54, 46, 57, 50, 82], dtype=float)
# Or read a CSV:
# import pandas as pd
# x = pd.read_csv("data.csv")["column_name"].to_numpy(dtype=float)
x = x[~np.isnan(x)] # drop missing values
label = "Site A leaf length"
units = "mm"
k = 1.5 # fence multiplier (3 = extreme only)
# ---- 2. Quartiles and IQR ----------------------------------
q1, med, q3 = np.percentile(x, [25, 50, 75]) # linear = Excel QUARTILE.INC
iqr = q3 - q1
assert np.isclose(iqr, stats.iqr(x)) # SciPy agrees
# ---- 3. Fences and outliers --------------------------------
lower, upper = q1 - k * iqr, q3 + k * iqr
lower2, upper2 = q1 - 2 * k * iqr, q3 + 2 * k * iqr
outliers = np.sort(x[(x < lower) | (x > upper)])
extreme = np.sort(x[(x < lower2) | (x > upper2)])
# ---- 4. Plain-English summary ------------------------------
print(f"n = {x.size}")
print(f"Q1 = {q1:.3f} Median = {med:.3f} Q3 = {q3:.3f}")
print(f"IQR = {iqr:.3f} {units}")
print(f"Fences: {lower:.3f} to {upper:.3f} (outer {lower2:.3f} to {upper2:.3f})")
if outliers.size == 0:
print("Verdict: no outliers by the 1.5 x IQR rule.")
else:
listed = ", ".join(f"{v:g}" for v in outliers)
print(f"Verdict: {outliers.size} outlier(s): {listed}")
if extreme.size:
print("Extreme (beyond outer fence): " + ", ".join(f"{v:g}" for v in extreme))
print(f"Report: Mdn = {med:.2f} {units} (IQR = {iqr:.2f}, "
f"Q1 = {q1:.2f}, Q3 = {q3:.2f}, n = {x.size})")
# ---- 5. One publication-ready box plot ---------------------
fig, ax = plt.subplots(figsize=(8, 4))
box_kw = dict(whis=k, widths=0.5, patch_artist=True,
boxprops=dict(facecolor="#bbf7d0", edgecolor="#166534"),
medianprops=dict(color="#111827", linewidth=3),
flierprops=dict(marker="o", markerfacecolor="#c2410c",
markeredgecolor="#c2410c", markersize=9))
try:
ax.boxplot(x, orientation="horizontal", **box_kw) # Matplotlib 3.10+
except TypeError:
ax.boxplot(x, vert=False, **box_kw) # older Matplotlib
rng = np.random.default_rng(42) # reproducible jitter
ax.scatter(x, 1 + rng.uniform(-0.12, 0.12, x.size),
s=18, color="0.3", alpha=0.45, zorder=3)
for fence in (lower, upper):
ax.axvline(fence, linestyle="--", color="#9333ea", linewidth=1.5)
ax.set_yticks([])
ax.set_xlabel(f"Value ({units})")
ax.set_title(f"{label}: IQR = {iqr:.2f} {units}")
fig.savefig("iqr_plot.png", dpi=300, bbox_inches="tight")
print("Saved iqr_plot.png")
11.2 What each part does
| Line or function | What it does, and why it is there |
|---|---|
| np.array(..., dtype=float) | Stores the data as numbers, so NaN can be removed safely. |
| x[~np.isnan(x)] | Drops missing values; np.percentile returns NaN if any are present. |
| np.percentile(x, [25, 50, 75]) | Q1, median and Q3. The default method="linear" matches Excel QUARTILE.INC and R type 7. |
| stats.iqr(x) | SciPy’s IQR, used as a check that both routes agree. |
| (x < lower) | (x > upper) | A true or false mask that selects the outliers. Brackets are required. |
| ax.boxplot(..., whis=k) | Matplotlib places whiskers at k × IQR, using linear percentiles, so the box matches the printed IQR. |
| np.random.default_rng(42) | Seeds the jitter so the figure is reproducible. |
| savefig(..., dpi=300) | Writes a print-quality PNG; bbox_inches="tight" stops labels being cut off. |
11.3 What the figure shows
It is the same figure as the R version: a horizontal box from 49.75 to 56.25, a median line at 52.5, whiskers to 46 and 61, dashed fences at 40 and 66, the outlier at 82 in orange, and grey dots for every raw value.
11.4 Common Python problems and fixes
| Symptom | Cause | Fix |
|---|---|---|
| Result is nan | Missing values in the array | Use np.nanpercentile or drop NaN first |
| Different from SPSS | SPSS uses type 6 | np.percentile(x, [25, 75], method="weibull") |
TypeError on method= | NumPy older than 1.22 | Use interpolation="linear", or upgrade NumPy |
| pandas and NumPy disagree | A column read as text | pd.to_numeric(df["col"], errors="coerce") |
| Figure is blank | plt.show() called before savefig | Save first, then show |
| Labels cut off | Default bounding box | Keep bbox_inches="tight" |
11.5 Useful one-liners
| You want | Python code |
|---|---|
| IQR with NumPy | np.subtract(*np.percentile(x, [75, 25])) |
| IQR with SciPy | scipy.stats.iqr(x) |
| IQR with pandas | df["col"].quantile(0.75) - df["col"].quantile(0.25) |
| IQR by group in pandas | df.groupby("g")["v"].quantile([.25, .75]).unstack() |
| Remove outliers in pandas | df[df["v"].between(lower, upper)] |
| Summary with quartiles | df["col"].describe() |
| SPSS-style quartiles | np.percentile(x, [25, 75], method="weibull") |
📋 12. Reference Tables
12.1 Quartile positions for small samples (type 7, Excel QUARTILE.INC)
| n | Q1 position | Median position | Q3 position |
|---|---|---|---|
| 5 | 2 | 3 | 4 |
| 6 | 2.25 | 3.5 | 4.75 |
| 7 | 2.5 | 4 | 5.5 |
| 8 | 2.75 | 4.5 | 6.25 |
| 9 | 3 | 5 | 7 |
| 10 | 3.25 | 5.5 | 7.75 |
| 11 | 3.5 | 6 | 8.5 |
| 12 | 3.75 | 6.5 | 9.25 |
| 15 | 4.5 | 8 | 11.5 |
| 16 | 4.75 | 8.5 | 12.25 |
| 20 | 5.75 | 10.5 | 15.25 |
Conclusion: a position of 4.75 means "value 4 plus three quarters of the gap to value 5". Whole-number positions need no interpolation.
12.2 One dataset, four methods (textbook set, n = 11)
Data: 6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49.
| Method | Q1 | Q3 | IQR |
|---|---|---|---|
| Excel QUARTILE.INC, R type 7, NumPy | 25.5 | 42.5 | 17 |
| Excel QUARTILE.EXC, SPSS, Minitab | 15 | 43 | 28 |
| TI-84, median of halves | 15 | 43 | 28 |
| Tukey hinges | 25.5 | 42.5 | 17 |
Conclusion: with small odd samples the IQR can change by more than half depending on the method. Always state it.
12.3 Normal distribution facts for the IQR
| Quantity | Value in units of σ | Share of a normal population |
|---|---|---|
| Q1 and Q3 | μ ± 0.6745σ | 50% between them |
| IQR | 1.349σ | - |
| Inner fences, k = 1.5 | μ ± 2.698σ | 0.70% outside |
| Fences, k = 2.2 | μ ± 3.642σ | 0.027% outside |
| Outer fences, k = 3 | μ ± 4.721σ | 0.0002% outside |
Conclusion: the 1.5 IQR fences sit close to the familiar ±2.7 SD, so about 7 in 1,000 normal values are flagged by chance.
12.4 Expected false flags from the 1.5 IQR rule in normal data
| Sample size n | Expected values flagged | Chance of at least one flag |
|---|---|---|
| 10 | 0.07 | about 7% |
| 30 | 0.21 | about 19% |
| 100 | 0.70 | about 50% |
| 500 | 3.5 | about 97% |
| 1,000 | 7.0 | almost certain |
Conclusion: in large samples a few flags are normal. Use k = 2.2, or look at how far beyond the fence a value lies, before calling it an error. Figures use the asymptotic 0.70% rate; small samples flag somewhat more often.
12.5 Which spread measure goes with which centre
| Your data | Centre | Spread |
|---|---|---|
| Roughly normal, no outliers | Mean | SD |
| Skewed or with outliers | Median | IQR |
| Ordinal, Likert | Median | IQR, or category percentages |
| Very small n (under 8) | Median | Min and max, plus raw values |
| Robust comparison of variability | Median | IQR or MAD |
Conclusion: pair the median with the IQR and the mean with the SD. Mixing them, such as mean (IQR), confuses readers.
12.6 IQR converters at a glance
| You have | You want | Formula |
|---|---|---|
| Mean and SD (normal) | Q1, Q3, IQR | μ ± 0.6745σ, IQR = 1.349σ |
| IQR (normal) | SD | IQR ÷ 1.349 |
| Median, Q1, Q3 | Mean | (Q1 + M + Q3) ÷ 3 |
| Q1, Q3, n | SD | IQR ÷ 2Φ−1((0.75n − 0.125)/(n + 0.25)) |
| IQR | Semi-IQR | IQR ÷ 2 |
Conclusion: these conversions assume roughly normal data. Use them for planning and meta-analysis, never in place of the raw data.
📈 13. Example Results
Eight worked IQR calculation examples covering the cases you will meet: the textbook odd-n set, a clear outlier, an even set by hand, skewed income, clean normal data, a tiny sample, ordinal ties, and two groups. All numbers use the inclusive (type 7) method unless stated.
The classic odd-n quartile set
Where the quartile method changes the answer the most.
Eleven values from a textbook exercise: 6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49. Students solve it by hand and then check in Excel.
| Statistic | Value | Note |
|---|---|---|
| n | 11 | Number of values |
| Q1 | 25.5 | 25th percentile |
| Median | 40 | Middle value |
| Q3 | 42.5 | 75th percentile |
| IQR | 17 | Q3 minus Q1 |
| Fences | 0 to 68 | 1.5 x IQR rule |
| Outliers | none | Beyond the fences |
| SD | 15.87 | For comparison |
| Q1 / Q3 by hand (TI-84) | 15 / 43 | Median of halves |
| IQR by hand | 28 | Twice as wide |
| IQR in Excel QUARTILE.INC | 17 | Type 7 |
What it means: Excel gives Q1 = 25.5 and Q3 = 42.5, so IQR = 17. A TI-84 or the hand method gives Q1 = 15, Q3 = 43 and IQR = 28. Both are correct for their rule. The gap is large because n is small and odd, and because the low values 6, 7, 15 are far from the rest, so Q1 lands in a big gap whose position depends on the rule.
How to write it: "Scores had a median of 40 (IQR = 17, Q1 = 25.5, Q3 = 42.5; quartiles by the inclusive method, n = 11)."
One long leaf at Site A
The worked example used across this page.
Sixteen leaf lengths in millimetres. Fifteen fall between 46 and 61; one leaf measures 82 mm.
| Statistic | Value | Note |
|---|---|---|
| n | 16 | Number of values |
| Q1 | 49.75 | 25th percentile |
| Median | 52.5 | Middle value |
| Q3 | 56.25 | 75th percentile |
| IQR | 6.5 | Q3 minus Q1 |
| Fences | 40 to 66 | 1.5 x IQR rule |
| Outliers | 82 | Beyond the fences |
| SD | 8.491 | For comparison |
| Outer fences | 30.25 / 75.75 | 3 x IQR |
| Flag | 82 extreme | Beyond outer fence |
What it means: The IQR is 6.5 mm, so half of the leaves sit in a 6.5 mm band around the median of 52.5. The single 82 mm leaf lies beyond the inner fence of 66 and even the outer fence of 75.75, so it is an extreme outlier. The range of 36 mm is more than five times the IQR because of that one leaf, which is why the range misleads here.
How to write it: "Leaf length had a median of 52.5 mm (IQR = 6.5, Q1 = 49.75, Q3 = 56.25, n = 16); one leaf (82 mm) exceeded the 1.5 x IQR fence and was verified against field notes."
Eight numbers, two correct answers
How to calculate the IQR with an even set of numbers.
The values 3, 7, 8, 5, 12, 14, 21, 13. Sorted: 3, 5, 7, 8, 12, 13, 14, 21.
| Statistic | Value | Note |
|---|---|---|
| n | 8 | Number of values |
| Q1 | 6.5 | 25th percentile |
| Median | 10 | Middle value |
| Q3 | 13.25 | 75th percentile |
| IQR | 6.75 | Q3 minus Q1 |
| Fences | -3.625 to 23.375 | 1.5 x IQR rule |
| Outliers | none | Beyond the fences |
| SD | 5.805 | For comparison |
| Lower half | 3, 5, 7, 8 | Median 6 |
| Upper half | 12, 13, 14, 21 | Median 13.5 |
| IQR by hand | 7.5 | Median of halves |
What it means: With an even n, split the sorted list into two halves of four. The lower half median is 6 and the upper half median is 13.5, so the IQR by hand is 7.5. Excel QUARTILE.INC interpolates instead and gives 6.5 and 13.25, an IQR of 6.75. No value is near the fences, so there are no outliers.
How to write it: "Values had a median of 10 (IQR = 6.75, inclusive method; 7.5 by the median-of-halves method, n = 8)."
Household income in thousands
Why income is always reported as median (IQR).
Fifteen household incomes. Most are between 22 and 62 thousand; two households earn 90 and 210 thousand.
| Statistic | Value | Note |
|---|---|---|
| n | 15 | Number of values |
| Q1 | 32 | 25th percentile |
| Median | 40 | Middle value |
| Q3 | 51.5 | 75th percentile |
| IQR | 19.5 | Q3 minus Q1 |
| Fences | 2.75 to 80.75 | 1.5 x IQR rule |
| Outliers | 90, 210 | Beyond the fences |
| SD | 46.51 | For comparison |
| Bowley skewness | 0.179 | Upper half wider |
| IQR / SD | 0.419 | Far below 1.349 |
What it means: The IQR is 19.5 thousand while the SD is 46.5 thousand, a ratio of 0.42 instead of the normal 1.35. The SD is inflated by the two high earners. The fences are 2.75 and 80.75, so both 90 and 210 are flagged, and 210 is beyond the outer fence of 110. These are real households, not errors, so they stay in the data and the median and IQR become the right summary.
How to write it: "Household income had a median of 40 thousand (IQR = 19.5, Q1 = 32, Q3 = 51.5, n = 15). Two high incomes exceeded the 1.5 x IQR fence and were retained as genuine."
Exam scores with no outliers
When IQR and SD tell the same story.
Twenty exam scores out of 100 from one class, roughly bell shaped.
| Statistic | Value | Note |
|---|---|---|
| n | 20 | Number of values |
| Q1 | 69.75 | 25th percentile |
| Median | 74 | Middle value |
| Q3 | 78.25 | 75th percentile |
| IQR | 8.5 | Q3 minus Q1 |
| Fences | 57 to 91 | 1.5 x IQR rule |
| Outliers | none | Beyond the fences |
| SD | 6.164 | For comparison |
| IQR / SD | 1.379 | Close to 1.349 |
| Robust SD | 6.30 | IQR / 1.349 |
What it means: The IQR is 8.5 points and the SD is 6.16, giving a ratio of 1.38, almost exactly the normal value of 1.349. The robust SD from the IQR (6.30) agrees with the ordinary SD. Nothing lies beyond the fences of 57 and 91. Here mean (SD) and median (IQR) are equally honest.
How to write it: "Exam scores averaged 73.9 (SD = 6.2); median 74 (IQR = 8.5), n = 20, with no outliers."
Five measurements only
Why quartiles from tiny samples need care.
Five readings: 12, 15, 18, 22, 40.
| Statistic | Value | Note |
|---|---|---|
| n | 5 | Number of values |
| Q1 | 15 | 25th percentile |
| Median | 18 | Middle value |
| Q3 | 22 | 75th percentile |
| IQR | 7 | Q3 minus Q1 |
| Fences | 4.5 to 32.5 | 1.5 x IQR rule |
| Outliers | 40 | Beyond the fences |
| SD | 11.04 | For comparison |
| Type 6 IQR | 17.5 | Excel EXC |
| Halves IQR | 17.5 | TI-84 |
What it means: With n = 5, Q1 and Q3 are just the 2nd and 4th values in Excel, so the IQR is 7 and 40 is flagged as an outlier above the fence of 32.5. The exclusive and hand methods give an IQR of 17.5, and then 40 is not flagged at all. With so few values the outlier decision depends on the method, so show the raw numbers and avoid strong claims.
How to write it: "With only five readings, values are reported in full (12, 15, 18, 22, 40); median 18, IQR 7 by the inclusive method."
Satisfaction ratings on a 1 to 7 scale
How ties shrink the IQR.
Fifteen survey ratings with many 5s and 6s.
| Statistic | Value | Note |
|---|---|---|
| n | 15 | Number of values |
| Q1 | 5 | 25th percentile |
| Median | 5 | Middle value |
| Q3 | 6 | 75th percentile |
| IQR | 1 | Q3 minus Q1 |
| Fences | 3.5 to 7.5 | 1.5 x IQR rule |
| Outliers | 2, 3 | Beyond the fences |
| SD | 1.302 | For comparison |
| Ties at Q1 | five 5s | Q1 = median |
| Flags | 3 and 2 | Low ratings |
What it means: Q1 and the median are both 5 because five people chose 5, and Q3 is 6, so the IQR is just 1 point. The fences become 3.5 and 7.5, which flags the ratings of 3 and 2 as outliers. They are honest answers from unhappy customers, not errors. For Likert data, report the median and IQR but also the percentage choosing each point.
How to write it: "Median satisfaction was 5 (IQR = 1, Q1 = 5, Q3 = 6, n = 15); 13% of respondents rated 3 or lower."
Spread at two field sites
Comparing IQRs side by side.
Twelve plant heights (cm) at a sheltered site A and an exposed site B.
| Statistic | Value | Note |
|---|---|---|
| Site A n | 12 | Number of values |
| Site A Q1 | 39.5 | 25th percentile |
| Site A Median | 44.5 | Middle value |
| Site A Q3 | 49.75 | 75th percentile |
| Site A IQR | 10.25 | Q3 minus Q1 |
| Site A Fences | 24.125 to 65.125 | 1.5 x IQR rule |
| Site A Outliers | none | Beyond the fences |
| Site B n | 12 | Number of values |
| Site B Q1 | 39.75 | 25th percentile |
| Site B Median | 55.5 | Middle value |
| Site B Q3 | 72 | 75th percentile |
| Site B IQR | 32.25 | Q3 minus Q1 |
| Site B Fences | -8.625 to 120.375 | 1.5 x IQR rule |
| Site B Outliers | none | Beyond the fences |
What it means: Site A has IQR 10.25 cm and Site B 32.25 cm, so the middle half at Site B is about three times as wide even though the medians (44.5 and 55.5) are only 11 cm apart. Neither site has outliers. Different IQRs suggest different variability; a Brown-Forsythe test would tell you whether the difference is statistically reliable.
How to write it: "Plant height was more variable at Site B (Mdn = 55.5 cm, IQR = 32.25) than at Site A (Mdn = 44.5 cm, IQR = 10.25), n = 12 per site."
🧪 14. Data Collection Protocol
Study design: the IQR assumes a set of independent measurements of one variable on at least an ordinal scale, collected in a way that does not bias the tails.
- Define the variable and its unit before collecting. Mixed units, such as some lengths in cm and some in mm, are the most common source of false outliers.
- Decide the unit of observation. One value per animal, plant, patient or plot. Repeat readings of the same unit should be averaged or modelled, not entered as separate rows.
- Use a random or systematic sample. A convenience sample can shift both quartiles and give a precise IQR of the wrong group.
- Fix the measurement resolution. Rounding to whole numbers creates ties, and many ties can make the IQR 0.
- Record missing values as blank cells. Never use 0 or −999; the calculator will treat them as real values.
- Write the quartile method into the protocol. Choose type 7 if you will analyse in Excel, R or Python, or type 6 if you will use SPSS.
- Write the outlier rule in advance. State k (1.5 is standard) and what you will do with flagged values: check, keep, winsorise or remove.
- Plan the sample size. Aim for at least 20 per group for stable quartiles; with fewer than 8, report the raw values too.
- Keep a data log. Note who measured what and when, so a flagged value can be traced back.
- Store data one column per group, exactly as below, ready to paste or upload here.
| Site A (mm) | Site B (mm) | Site C (mm) |
|---|---|---|
| 52 | 47 | 58 |
| 48 | 51 | 62 |
| 55 | 49 | 60 |
One column per group, one row per unit, numbers only below the header row. Blank cells are ignored, so unequal group sizes are fine.
Minimum sample: the calculator needs 3 values, but quartiles from fewer than 8 values are unstable. A single new value can move Q1 or Q3 by a whole data step.
Pre-registration: record the quartile method, the fence multiplier and the outlier policy before seeing the data. Choosing them afterwards, to keep or drop a particular value, is a common hidden bias.
Common collection mistakes:
- Typing missing data as 0 or −999, which creates fake low outliers.
- Mixing units or decimal commas and points in one column.
- Rounding heavily at the point of measurement, which creates ties.
- Pooling two different populations in one column, which widens the IQR.
- Deleting values in the field because they "looked wrong", so the tails are never seen.
🎯 15. When to Use This IQR Calculator
This free IQR calculator is designed for students, teachers, researchers and analysts who need a robust measure of spread, a quick outlier screen, or a box plot with the numbers behind it.
Use the IQR when:
- ✓ The data are skewed, such as income, length of stay, reaction time or counts.
- ✓ There may be outliers and you want a spread measure they cannot distort.
- ✓ The variable is ordinal, such as Likert ratings or pain scores.
- ✓ You are reporting the median and need the matching spread.
- ✓ You want to screen data for errors before analysis.
- ✓ You are building a box plot or a five-number summary.
Use something else when:
- ✗ The data are normal and you will run a t-test or ANOVA: report the SD with the mean.
- ✗ You need the precision of an estimate: use a confidence interval.
- ✗ You need to test whether spreads differ: use Levene’s or Brown-Forsythe test.
- ✗ The data are nominal categories: report counts and percentages.
- ✗ More than half the values tie: the IQR may be 0, so use percentages per value.
Real-world examples:
- Clinical research: hospital stay of median 4 days (IQR 2 to 7), because a few patients stay for weeks.
- Ecology: home-range size of collared animals, where one wide-ranging individual would inflate the SD.
- Education: comparing the spread of exam scores between two teaching methods with a side-by-side box plot.
- Data cleaning: flagging sensor spikes before fitting a regression.
Design guidance: collect at least 20 values per group, keep units consistent, and decide the quartile method before you analyse.
Decision tree: Is the variable numeric or ordinal? If not, use percentages. Is it roughly normal with no outliers? Report mean (SD). Otherwise report median (IQR). Comparing groups? Use a Mann-Whitney U (two groups) or Kruskal-Wallis (three or more) for location, and Brown-Forsythe for spread.
🔧 16. Troubleshooting and Common Errors
My IQR does not match Excel
Cause: a different quartile method, or Excel skipping numbers stored as text. Fix: set the method to Inclusive for QUARTILE.INC or Exclusive for QUARTILE.EXC, then compare n with Excel’s =COUNT().
My IQR does not match my TI-84 or textbook
Cause: calculators and textbooks use the median of halves. Fix: choose Median of halves in the method menu. The method table shows all four answers anyway.
The IQR is 0
Cause: more than half the values are identical. Fix: report percentages for each value, or the median with the full range. Ignore the outlier flags, which become meaningless.
Almost every value is flagged as an outlier
Cause: a tiny IQR from ties or rounding. Fix: record more decimal places, or use k = 3, or skip the IQR outlier rule for this variable.
A value of −999 or 9999 is flagged
Cause: a missing-value code entered as data. Fix: delete it from the box and press Calculate again. The calculator warns you when it sees these codes.
Some entries were skipped
Cause: text such as NA, units like "12 cm", or a decimal comma. Fix: keep only numbers, use a full stop for decimals, and put units in the Unit box.
The uploaded file shows no columns to click
Cause: no column has at least two numeric cells, often because numbers were saved as text with symbols. Fix: clean the column in Excel, save as CSV, and upload again.
Charts do not appear
Cause: the Chart.js library was blocked by a network or browser extension. Fix: allow cdnjs.cloudflare.com. All tables and steps still work without the charts.
R’s boxplot box does not match IQR()
Cause: boxplot() uses Tukey hinges, IQR() uses type 7. Fix: use bxp() with your own statistics, as in Section 10.
Python gives a different IQR from SPSS
Cause: NumPy uses linear (type 7), SPSS uses type 6. Fix: use method="weibull" in np.percentile.
Results disappeared after I edited the data
Cause: this is intended; changing any input clears old results so you never read stale numbers. Fix: press Calculate IQR again.
⚖ 17. Assumptions and Limitations
Assumptions
- Values are ordered on a meaningful scale. Check: the variable is ordinal, interval or ratio. If it fails: quartiles of codes for unordered categories are meaningless.
- Observations are independent. Check: one value per unit. If it fails: repeated readings of a few units narrow the IQR and make the data look less variable than the population.
- The sample represents the population. Check: random or systematic sampling. If it fails: Q1 and Q3 shift toward the over-sampled part, biasing both location and spread.
- Enough data for stable quartiles. Check: n of 8 or more, ideally 20. If it fails: the IQR swings widely between samples and the methods disagree.
- Few exact ties at the quartiles. Check: the data-quality table. If it fails: the IQR shrinks toward 0 and the outlier rule over-flags.
- One population per column. Check: the histogram for two peaks. If it fails: the IQR widens to span both groups and describes neither.
Limitations
- The IQR ignores the outer 50% of the data, so it says nothing about how far the tails reach. Report the range or the outliers as well, or use a box plot.
- Sample quartiles have no single definition. Results depend on the method; always state it.
- The 1.5 IQR rule assumes roughly symmetric data. For skewed data it over-flags the long tail; consider a log transform or the adjusted box plot of Hubert and Vandervieren.
- The IQR is descriptive. It gives no p-value or confidence interval. For inference about spread, use Levene’s or Brown-Forsythe test, or a bootstrap confidence interval for the IQR.
- The IQR is less efficient than the SD for truly normal data, so it needs a larger sample for the same precision.
- The mean and SD conversions assume normality. For skewed data they can be badly wrong; use the raw data when you have it.
🏁 18. Conclusion
An IQR calculator answers a simple question: how wide is the middle half of my data? Sort the values, find Q1 and Q3, and subtract. That single number is hard to fool, which is why it sits beside the median in medical tables, inside every box plot, and at the heart of the most widely used outlier rule in statistics.
The calculation is easy; the details are where people go wrong. Quartiles have several valid definitions, so Excel, SPSS, R and a TI-84 can give different answers for the same numbers. The cure is not to find the "right" one but to choose one, name it, and use it everywhere. The method table on this page makes that choice visible, so you never have to guess why two numbers differ.
The 1.5 IQR rule is a screen, not a verdict. A flagged value deserves a second look at the raw record. Many flags turn out to be typing errors or missing-value codes; the rest are real, and real values belong in the analysis. Report how many values were flagged and what you did with them, and readers can judge for themselves.
Finally, pair the IQR with the median, give Q1 and Q3 when space allows, and show a box plot whenever you can. Those three habits make your spread statistics honest, reproducible and easy to read.
Run the calculator to add a conclusion written from your own numbers: Q1 = ___, Q3 = ___, IQR = ___, outliers = ___.
Paste your numbers above, read the box plot, check the fences, and come back to this IQR calculator whenever you need quartiles you can trust.
❓ 19. Frequently Asked Questions
Q1. What is the IQR?
The interquartile range (IQR) is the third quartile minus the first quartile, IQR = Q3 - Q1. It is the width of the middle 50% of the sorted data. Because it ignores the lowest and highest quarter, outliers barely affect it, which makes it the standard spread measure to report with the median.
Q2. How do you calculate the IQR step by step?
Sort the data from smallest to largest. Find the median. Find Q1, the median of the lower half (or the 25th percentile), and Q3, the median of the upper half (or the 75th percentile). Subtract: IQR = Q3 - Q1. For 3, 5, 7, 8, 12, 13, 14, 21, Q1 = 6 and Q3 = 13.5 by hand, so IQR = 7.5.
Q3. What is the formula to calculate the IQR?
IQR = Q3 - Q1. In Excel, R and Python the quartiles use the position h = (n - 1)p + 1, with p = 0.25 for Q1 and 0.75 for Q3, interpolating between neighbouring sorted values. The textbook method takes the medians of the lower and upper halves instead.
Q4. How do you calculate the IQR in Excel?
Put the data in A2:A17 and type =QUARTILE.INC(A2:A17,3)-QUARTILE.INC(A2:A17,1). QUARTILE.INC matches R and Python. QUARTILE.EXC matches SPSS and Minitab and gives a slightly wider IQR in small samples. Section 9 shows each step with spreadsheet screenshots.
Q5. How do you calculate the IQR in R?
Use IQR(x). It uses quantile type 7, the same as Excel QUARTILE.INC. quantile(x, c(0.25, 0.75)) gives Q1 and Q3, and boxplot.stats(x)$out lists the 1.5 IQR outliers. For SPSS-style quartiles use IQR(x, type = 6).
Q6. How do you calculate the IQR in Python?
With NumPy: q1, q3 = np.percentile(x, [25, 75]); iqr = q3 - q1. With SciPy: scipy.stats.iqr(x). With pandas: df["col"].quantile(0.75) - df["col"].quantile(0.25). All three use the linear method, matching Excel QUARTILE.INC.
Q7. What is the 1.5 IQR rule for outliers?
A value is a potential outlier if it is below Q1 - 1.5 x IQR or above Q3 + 1.5 x IQR. These cut-offs are called Tukey fences. Values beyond 3 x IQR from the box are extreme outliers. For normal data only about 0.7% of values fall outside the 1.5 IQR fences.
Q8. How do you calculate 1.5 IQR?
Multiply the IQR by 1.5, then subtract that from Q1 for the lower fence and add it to Q3 for the upper fence. With Q1 = 49.75, Q3 = 56.25 and IQR = 6.5, 1.5 x IQR = 9.75, so the fences are 40 and 66.
Q9. How do you calculate the IQR with an odd set of numbers?
Sort the data and find the middle value (the median). With the textbook method, leave the median out and take the medians of the lower and upper halves. For 6, 7, 15, 36, 39, 40, 41, 42, 43, 47, 49 that gives Q1 = 15 and Q3 = 43, IQR = 28. Excel QUARTILE.INC gives 17 for the same data.
Q10. Why does my IQR differ between Excel, a TI-84 and a textbook?
There are several valid definitions of a sample quartile. Excel QUARTILE.INC, R and NumPy use one, Excel QUARTILE.EXC and SPSS another, and the TI-84 and most textbooks a third. The differences shrink as n grows. Choose one method, state it, and use it for every group.
Q11. How do you find the IQR from a box plot?
Read the value at the left (or bottom) edge of the box, which is Q1, and the right (or top) edge, which is Q3. Subtract: IQR = Q3 - Q1. The line inside the box is the median, and the whiskers usually stop at the last values inside the 1.5 IQR fences.
Q12. Can you calculate the IQR from the mean and standard deviation?
Only if the data are normal. Then Q1 = mean - 0.6745 x SD, Q3 = mean + 0.6745 x SD, and IQR = 1.349 x SD. For skewed data there is no reliable conversion. The quick converter in Section 2 does this calculation.
Q13. How do you calculate the standard deviation from the IQR?
For roughly normal data, SD is about IQR / 1.35. For small samples, Wan et al. (2014) recommend dividing by 2 x z((0.75n - 0.125)/(n + 0.25)), which approaches 1.349 as n grows. This is used in meta-analysis when papers report only median (IQR).
Q14. How do you estimate the mean from the median and IQR?
A common estimate is mean = (Q1 + median + Q3) / 3, from Wan et al. (2014). It works for roughly symmetric data and is used to combine studies in meta-analysis. It is an estimate, not a replacement for the real mean.
Q15. Is a larger IQR better or worse?
Neither. A larger IQR means the middle half of the data is more spread out; a smaller IQR means values are more consistent. Whether that is good depends on context: a small IQR is good for manufacturing tolerances, while a wider IQR may simply reflect real natural variation.
Q16. Should I report IQR or standard deviation?
Report the median with the IQR when data are skewed, ordinal or contain outliers. Report the mean with the SD when data are roughly normal. A quick check: if IQR / SD is close to 1.349 and the box plot is symmetric, either is fine.
Q17. What does an IQR of zero mean?
It means Q1 and Q3 are equal, usually because more than half the values are identical, as often happens with ratings or counts. The outlier rule then flags almost everything. Report percentages for each value, or the median with the full range, instead.
Q18. What is the difference between range and IQR?
The range is maximum minus minimum and depends on only the two most extreme values. The IQR is Q3 minus Q1 and depends on the middle half. One outlier can double the range but barely moves the IQR.
Q19. How do I find the IQR on a TI-84 graphing calculator?
Enter the data in L1 with STAT, Edit. Then press STAT, CALC, 1-Var Stats, and scroll down to Q1 and Q3. Subtract them for the IQR. The TI-84 uses the median-of-halves method, so choose that method here to match it.
Q20. Can I use this IQR calculator for my thesis or research paper?
Yes for exploratory work, teaching and checking hand calculations. Name the quartile method and fence rule in your methods section, and reproduce the numbers in R, Python, SPSS or Excel for submission. You can cite it as StatsUnlock (2026), IQR calculator, https://statsunlock.com/iqr-calculator/.
📑 20. Cite This Tool
StatsUnlock. (2026). IQR calculator: Interquartile range, quartiles and outliers [Interactive statistical tool]. https://statsunlock.com/iqr-calculator/@misc{statsunlock_iqr_2026, title={IQR Calculator: Interquartile Range, Quartiles and Outliers}, author={{StatsUnlock}}, year={2026}, note={Interactive statistical tool}, url={https://statsunlock.com/iqr-calculator/}}Dispersion was summarised with the interquartile range using the StatsUnlock IQR Calculator (2026). Quartiles were estimated with the inclusive (type 7) definition, matching Excel QUARTILE.INC and the R default. Potential outliers were identified with Tukey fences at 1.5 times the IQR below Q1 and above Q3.🔗 21. Related Tools
Turn your quartiles into a styled box plot for reports and slides.
Open the tool →The spread measure to pair with the mean when your data are roughly normal.
Open the tool →Show how precisely your mean or proportion has been estimated.
Open the tool →Check whether your data are normal before choosing SD or IQR.
Open the tool →Plan the sample size you need for stable estimates.
Open the tool →Model your outcome after screening predictors for outliers with the IQR.
Open the tool →Fit curved relationships once your data have been cleaned.
Open the tool →Summarise species counts across sites, a common partner to IQR summaries in field studies.
Open the tool →📖 22. Glossary of Terms
| Term | Plain-English meaning |
|---|---|
| Box plot | A chart that draws the IQR as a box, the median as a line, and outliers as points. |
| Bowley skewness | A measure of lopsidedness built only from the quartiles and median. |
| Extreme outlier | A value beyond the outer fences, usually 3 IQR from the box. |
| Fence | A cut-off line, Q1 minus k times the IQR or Q3 plus k times the IQR. |
| Five-number summary | Minimum, Q1, median, Q3 and maximum. |
| Hinge | Tukey’s version of a quartile: the median of each half, with the median included when n is odd. |
| Interpolation | Taking a point part of the way between two sorted values. |
| Interquartile range (IQR) | Q3 minus Q1, the width of the middle half of the data. |
| Median | The middle value once the data are sorted; also called Q2. |
| Median absolute deviation (MAD) | The median of the distances of each value from the median. |
| Outlier | A value far from most others, here one beyond the inner fences. |
| Percentile | The value below which a given percent of the data fall. |
| Q1, first quartile | The value with 25% of the data at or below it. |
| Q3, third quartile | The value with 75% of the data at or below it. |
| Quartile | One of three values that cut sorted data into four equal parts. |
| Quartile coefficient of dispersion | (Q3 minus Q1) divided by (Q3 plus Q1), a unit-free spread measure. |
| Range | Maximum minus minimum. |
| Robust statistic | One that barely changes when a few extreme values change. |
| Semi-interquartile range | Half the IQR; also called the quartile deviation. |
| Standard deviation (SD) | The typical distance of values from the mean, sensitive to outliers. |
| Whisker | The line from the box to the last value inside the fences. |
📚 23. References
These peer-reviewed sources support the methods in this IQR calculator: quartile definitions, the 1.5 IQR outlier rule, box plots, robust spread, and converting between median (IQR) and mean (SD).
- Aguinis, H., Gottfredson, R. K., & Joo, H. (2013). Best-practice recommendations for defining, identifying, and handling outliers. Organizational Research Methods, 16(2), 270–301. https://doi.org/10.1177/1094428112470848
- Dawson, R. (2011). How significant is a boxplot outlier? Journal of Statistics Education, 19(2). https://doi.org/10.1080/10691898.2011.11889610
- Freedman, D., & Diaconis, P. (1981). On the histogram as a density estimator: L2 theory. Zeitschrift für Wahrscheinlichkeitstheorie und Verwandte Gebiete, 57(4), 453–476. https://doi.org/10.1007/BF01025868
- Frigge, M., Hoaglin, D. C., & Iglewicz, B. (1989). Some implementations of the boxplot. The American Statistician, 43(1), 50–54. https://doi.org/10.1080/00031305.1989.10475612
- Hoaglin, D. C., & Iglewicz, B. (1987). Fine-tuning some resistant rules for outlier labeling. Journal of the American Statistical Association, 82(400), 1147–1149. https://doi.org/10.1080/01621459.1987.10478551
- Hoaglin, D. C., Iglewicz, B., & Tukey, J. W. (1986). Performance of some resistant rules for outlier labeling. Journal of the American Statistical Association, 81(396), 991–999. https://doi.org/10.1080/01621459.1986.10478363
- Hozo, S. P., Djulbegovic, B., & Hozo, I. (2005). Estimating the mean and variance from the median, range, and the size of a sample. BMC Medical Research Methodology, 5, 13. https://doi.org/10.1186/1471-2288-5-13
- Hubert, M., & Vandervieren, E. (2008). An adjusted boxplot for skewed distributions. Computational Statistics & Data Analysis, 52(12), 5186–5201. https://doi.org/10.1016/j.csda.2007.11.008
- Hyndman, R. J., & Fan, Y. (1996). Sample quantiles in statistical packages. The American Statistician, 50(4), 361–365. https://doi.org/10.1080/00031305.1996.10473566
- Krzywinski, M., & Altman, N. (2014). Visualizing samples with box plots. Nature Methods, 11(2), 119–120. https://doi.org/10.1038/nmeth.2813
- Langford, E. (2006). Quartiles in elementary statistics. Journal of Statistics Education, 14(3). https://doi.org/10.1080/10691898.2006.11910589
- Leys, C., Ley, C., Klein, O., Bernard, P., & Licata, L. (2013). Detecting outliers: Do not use standard deviation around the mean, use absolute deviation around the median. Journal of Experimental Social Psychology, 49(4), 764–766. https://doi.org/10.1016/j.jesp.2013.03.013
- Luo, D., Wan, X., Liu, J., & Tong, T. (2018). Optimally estimating the sample mean from the sample size, median, mid-range, and/or mid-quartile range. Statistical Methods in Medical Research, 27(6), 1785–1805. https://doi.org/10.1177/0962280216669183
- McGill, R., Tukey, J. W., & Larsen, W. A. (1978). Variations of box plots. The American Statistician, 32(1), 12–16. https://doi.org/10.1080/00031305.1978.10479236
- Rousseeuw, P. J., & Croux, C. (1993). Alternatives to the median absolute deviation. Journal of the American Statistical Association, 88(424), 1273–1283. https://doi.org/10.1080/01621459.1993.10476408
- Rousseeuw, P. J., & Hubert, M. (2011). Robust statistics for outlier detection. WIREs Data Mining and Knowledge Discovery, 1(1), 73–79. https://doi.org/10.1002/widm.2
- Schwertman, N. C., Owens, M. A., & Adnan, R. (2004). A simple more general boxplot method for identifying outliers. Computational Statistics & Data Analysis, 47(1), 165–174. https://doi.org/10.1016/j.csda.2003.10.012
- Shi, J., Luo, D., Weng, H., Zeng, X.-T., Lin, L., Chu, H., & Tong, T. (2020). Optimally estimating the sample standard deviation from the five-number summary. Research Synthesis Methods, 11(5), 641–654. https://doi.org/10.1002/jrsm.1429
- Wan, X., Wang, W., Liu, J., & Tong, T. (2014). Estimating the sample mean and standard deviation from the sample size, median, range and/or interquartile range. BMC Medical Research Methodology, 14, 135. https://doi.org/10.1186/1471-2288-14-135
- Weissgerber, T. L., Milic, N. M., Winham, S. J., & Garovic, V. D. (2015). Beyond bar and line graphs: Time for a new data presentation paradigm. PLOS Biology, 13(4), e1002128. https://doi.org/10.1371/journal.pbio.1002128
