Quantiles and Percentiles

Cut a distribution into equal-sized groups. The box plot is what you get when you draw the cuts.

Overview

The definition

The q-th quantile is the value below which a fraction q of the data falls. The 0.5 quantile is the median: half below, half above. The 0.9 quantile is the value 90% of the data sits below.

Percentiles are the same idea on a 0–100 scale — the 90th percentile is the 0.9 quantile. Quartiles cut at 25, 50 and 75, cutting the data into four equal groups. Deciles cut into ten.

Quantiles and Percentiles

This module needs JavaScript: the numbers are computed in the page rather than recorded.

Worth knowing

The q-th quantile is the value below which a fraction q of the data falls. The median is q = 0.5.
Percentiles are the same thing on a 0-100 scale. Quartiles cut at 25, 50 and 75.
The IQR is Q3 − Q1: the range covering the middle half, and a spread measure that ignores outliers entirely.
Whiskers reach the furthest points within 1.5 IQR of the box. Anything beyond is drawn individually — a convention, not a test.

Quantiles and Percentiles

showing a spread by where its values sit rather than by blending them.

Why not just use the mean

A mean is a balance point. It moves when any of it moves. A quantile depends only on order, and that makes it solid.

Add a single huge value to a dataset and the mean shifts, possibly a lot. The median barely moves at all. The new value is simply "one more above the middle", even so of how far above.

That is why median income is reported rather than mean income, why latency is reported at percentiles, and why the box plot below exists.

The IQR — Q3 minus Q1 — is the spread measure that follows from the same idea. It covers the middle half of the data, and it's unaffected by any of it in the tails. Standard deviation, being built from squared distances from the mean, is the opposite: one extreme value moves it a lot.

Reading the box plot

The second panel is assembled from the quartiles in the first, and each part of it has a meaning:

The box spans Q1 to Q3. So It holds the middle 50% of the data.

The line inside is the median. Its spot within the box shows skew: off centre means the spread leans.

The whiskers reach the furthest data points still within 1.5 × IQR of the box edge.

The dots are all beyond that.

The 1.5 is a rule, not a test. It comes from Tukey, and for a normal spread it flags about 0.7% of points. Points beyond it are worth inspecting, and calling them "outliers" makes a claim the rule can't support — a skewed spread makes them by build rather than by error.

Grow the sample size and the number of flagged points grows roughly in proportion. That alone shows the rule is descriptive.

Percentiles in practice

Latency. No one reports mean response time, because one slow request buried in a million is invisible in a mean and obvious at p99. Services are given at p50, p95, p99 and p999 just because the tail is what users notice.

A trap follows right away: percentiles don't mean. The p99 of two servers isn't the mean of their p99s. Aggregating percentiles needs the underlying spreads or a structure like a t-digest.

Quantile regression predicts a chosen quantile rather than the mean. handy when the cost of over- and under-guess differ, or when you want a guess interval right.

Quantile binning turns a smooth feature into equal-sized buckets, which is solid to skew in a way that equal-width binning isn't.

Feature scaling. QuantileTransformer maps a feature to a uniform or normal spread through its quantiles, and is unaffected by outliers in a way standardisation isn't.

A wrinkle worth knowing

There's no single agreed meaning of a sample quantile. With 10 data points, "the value below which 25% falls" doesn't land on an reading, and there are a few defensible interpolations. NumPy offers nine methods. R offers the same nine. The defaults differ between languages, and between numpy.percentile and some SQL engines.

For large samples the differences are negligible. For small ones they aren't, and two tools can legitimately report different quartiles for the same data.

The definition ambiguity, on ten numbers

The wrinkle deserves numbers, because it's where two tools disagree on the same data. Take the ten values 1, 2, 3, …, 10 and ask for the 25th percentile. "The value below which 25% falls" doesn't land on an reading, and the defensible answers differ:

method25th percentilehow
linear interpolation3.25position (n−1)·0.25 = 2.25, so a quarter of the way from the 3rd value to the 4th
nearest-rank3the smallest value with at least 25% at or below it

Both are correct. They answer slightly different questions about what a "percentile" of a finite sample means. NumPy's default is the linear method, and it offers nine in total. Other tools default differently, which is why numpy.percentile and a SQL engine can report different quartiles for the same column. For a thousand points the gap between methods is negligible. For ten it's 0.25 out of a range of 9. This Is enough to change a choice. State the method when the sample is small and the number matters.

The reason to care sits in the tail. A service's latency is reported at p95 and p99 just because one slow request in a thousand is invisible in a mean and obvious in a high percentile. And those percentiles can't be averaged across servers, because the p99 of two machines isn't the mean of their p99s. Aggregating them needs the underlying spreads or a structure like a t-digest. Blending them understates the tail each time. This Is the one error this whole topic exists to prevent.

There's also no single agreed meaning of a sample quantile: on ten points the "value below which 25% falls" is a matter of interpolation, and NumPy alone offers nine methods. On large samples the choice is negligible. On small ones two honest tools can report different quartiles for the same data.

Where it goes wrong with Quantiles and Percentiles

Blending percentiles. The single most common error, and it always understates the tail.

Reading whisker points as errors. The rule is a drawing rule.

Checking box plots of very different sample sizes. More data means more flagged points, mechanically.

given your language's default matches another's. State the method when it matters.

Questions people ask about Quantiles and Percentiles

What is the difference between a quantile and a percentile? They are the same idea on different scales. The 0.9 quantile is the 90th percentile: the value below which 90 percent of the data lies.

Is the median a quantile? Yes, it is the 0.5 quantile, the 50th percentile and the second quartile.

Why do different tools give different percentiles? There are several conventions for interpolating between data points when the position falls between two values. The differences shrink as the sample grows.

Why use the median instead of the mean? The median ignores how extreme the extremes are. A single huge outlier moves the mean a lot and the median hardly at all.

What is the interquartile range? It is the 75th percentile minus the 25th. It measures spread in the middle half of the data and is the basis of the box plot whiskers.

How should I report skewed data like latency? Give percentiles such as p50, p95 and p99. The mean hides the slow tail, which is what users actually feel.

Nobody experiences the mean

Ten thousand response times with a long tail. The mean and the median tell one story. P95 and p99 tell the one your users live in.

example_01.pyNumPy
Output

Check yourself

0 of 3

Answer without scrolling back up.

  1. Why is the median unaffected by adding one enormous value?

  2. What do the whiskers on a box plot reach?

  3. Why can you not average the p99 of two servers?

Cheat sheet

Quantiles and Percentiles

Compute quantiles, percentiles and the interquartile range. See why rank-based summaries describe skewed data better than the mean.

MATHS · vizlearn.in/maths/quantiles_and_percentiles.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.