Statistics & Probability Percentiles, Z-Scores & Distribution Shape Sample quantile definitions (Hyndman & Fan, 1996)

Percentile Calculator

Enter a data set and a percentile and this calculator returns the value at that point in the sorted data, together with the rank position it came from. Three standard methods are offered, because a percentile is a definition rather than a fact: the linear interpolation used by Excel's PERCENTILE.INC and R's default, the exclusive variant used by PERCENTILE.EXC, and the classic nearest-rank rule that always returns an observed value. A ladder of common percentiles is built from whichever you choose.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Data valuesSeparate numbers with commas, spaces or line breaks. The calculator sorts them for you.120, 135, 128, 410, 142, 133, 150, 129, 138, 260
PercentileThe percentage of the data you want to fall at or below the answer - 90 for the 90th percentile.90 %
Rank methodMatch the method your course, SLA definition or software uses; they can differ by a whole observation on small data sets.Linear interpolation, rank 1 + (n-1)p - Excel PERCENTILE.INC, R type 7

It returns

  • Value at that percentile — Read off the sorted data at the rank the chosen method gives.
  • Rank position used
  • Observations at or below that value
  • 25th percentile (Q1)
  • 50th percentile (median)
  • 75th percentile (Q3)
  • Count n

The formula

L=1+(n1)P100
L=nP100

In plain text: rank L = 1 + (n - 1) x P/100; value = x_floor(L) + (L - floor L) x (x_floor(L)+1 - x_floor(L))

  • LRank position in the sorted data, counting from 1 (position)
  • nNumber of observations (count)
  • PRequested percentile (%)
  • x_(k)The k-th smallest observation (same as the data)

The three methods differ only in how L is formed: 1 + (n-1)p for the inclusive form, (n+1)p for the exclusive form, and the ceiling of np for nearest rank. Hyndman and Fan catalogue nine such definitions; these are the three in general software use.

Updated Category Percentiles, Z-Scores & Distribution Shape Verified against published test cases Reading time 10 min

What a percentile is

The P-th percentile is the value below which P percent of the data fall. If the 90th percentile of your response times is 275 ms, then 90% of requests completed in 275 ms or less and 10% took longer. That is the whole idea, and it is why percentiles dominate anywhere the tail matters more than the average: service level agreements, growth charts, standardised test scores, salary bands and latency dashboards.

Percentiles describe position, not distance. Moving the slowest request from 410 ms to 4,100 ms does not change the 90th percentile at all, because the observation stays in the same place in the order. That resistance is the reason a P95 latency figure is far more informative than a mean latency figure: the mean is dragged around by a handful of pathological requests, while the percentile tells you what a user at a specific point in the distribution actually experiences.

Quartiles are percentiles with familiar names. Q1 is the 25th percentile, the median is the 50th, and Q3 is the 75th; their difference is the interquartile range. Deciles cut at every 10th percentile and quintiles at every 20th, which is how income distributions are usually reported.

Rank, interpolation, and why three methods exist

Every percentile calculation has two steps. First convert the requested percentage into a rank - a position in the sorted data. Then read the value at that position, interpolating if the position is not a whole number.

The awkwardness is in step one, because n observations divide the number line into more than n regions, so there is no single obviously correct mapping from a percentage to a position. Three answers are in general use.

  • Inclusive interpolation, L = 1 + (n - 1)P/100. The smallest observation is the 0th percentile and the largest is the 100th, with everything spread evenly between. This is Excel's PERCENTILE.INC, R's type 7 default and NumPy's default, so it is what most people get without choosing.
  • Exclusive interpolation, L = (n + 1)P/100. Treats the sample as if it came from a larger population in which observations sit at positions 1/(n+1), 2/(n+1) and so on. It cannot resolve percentiles below 1/(n+1) or above n/(n+1) - with ten observations, nothing below the 9.09th or above the 90.91st - and Excel's PERCENTILE.EXC returns an error there. This is R's type 6.
  • Nearest rank, L = ceiling(n x P/100). No interpolation at all: round the rank up and return that observation. The answer is always a value that genuinely occurred, which is why many service level agreements are written this way.

Once the rank is fixed, interpolation is straightforward. If L = 9.1, take the 9th sorted value, add 0.1 of the gap to the 10th, and that is your answer. The quartile calculator offers the same choice in the specific case of the 25th and 75th percentiles.

Hyndman and Fan's 1996 review catalogues nine distinct sample quantile definitions used in statistical software. The three here cover almost everything you will meet in practice, but the lesson of that paper stands: state which definition you used.

Worked example: the 90th percentile of ten response times

Ten requests are timed, in milliseconds: 120, 135, 128, 410, 142, 133, 150, 129, 138, 260.

  1. Sort them. 120, 128, 129, 133, 135, 138, 142, 150, 260, 410. So n = 10.
  2. Convert the percentile to a proportion. P = 90, so p = 0.90.
  3. Find the rank, inclusive method. L = 1 + (10 - 1) x 0.90 = 1 + 8.1 = 9.1.
  4. Identify the neighbours. The 9th sorted value is 260 and the 10th is 410.
  5. Interpolate. The fractional part of the rank is 0.1, so the answer is 260 + 0.1 x (410 - 260) = 260 + 15 = 275 ms.

Now do the same with nearest rank. L = ceiling(10 x 0.90) = ceiling(9) = 9, so the answer is the 9th sorted value, 260 ms. And with the exclusive method, L = 11 x 0.90 = 9.9, giving 260 + 0.9 x 150 = 395 ms.

Three defensible methods, three answers spanning 135 ms on the same ten numbers. That spread is not a defect of the arithmetic; it is what happens when you ask ten observations to locate a point that only about one observation lies beyond. If this were an SLA, the difference between promising 260 ms and promising 395 ms would be a commercial decision, and the contract needs to say which definition applies.

For comparison, the mean of these ten values is 1,745 / 10 = 174.5 ms - lower than every one of the three percentile answers, because two slow requests pull it up while eight fast ones hold it down. The mean answers "what is the total time divided by the count"; the percentile answers "how slow is a slow request".

Reading a percentile, and how much data you need

Read a percentile as a promise about position. The 95th percentile is the value that 95% of observations do not exceed; equivalently, 1 in 20 observations exceeds it. That reciprocal is the useful mental conversion: P90 means 1 in 10, P95 means 1 in 20, P99 means 1 in 100, P99.9 means 1 in 1,000.

It follows immediately that you cannot measure a percentile more extreme than your sample supports. With 10 observations, a single value covers 10 percentage points of the distribution, so a 99th percentile is not measured - it is the maximum with a label on it. As a working rule you want on the order of 100 observations before quoting a 99th percentile and 1,000 before a 99.9th, and even then the estimate moves substantially from sample to sample because it rests on the handful of most extreme points.

Central percentiles are far better behaved. The median is the most stable percentile in any data set, and the quartiles are close behind. If your sample is small, quote the median and quartiles and say nothing about the tail.

Two properties are worth keeping in mind when comparing groups. Percentiles are invariant under any strictly increasing transformation - the 90th percentile of the logarithms is the logarithm of the 90th percentile - which makes them convenient for skewed data. But percentiles do not add: the 95th percentile of a sum of two latencies is not the sum of their 95th percentiles, and averaging the P95 figures of several servers does not give the P95 of the whole fleet. To get that, pool the raw observations and recompute.

How the three methods differ on the integers 1 to 10

Every cell was produced by running this calculator's own rank formulas on the data set 1, 2, 3, ..., 10.
PercentileInclusive rankInclusive valueExclusive rankExclusive valueNearest rank value
10th1.901.901.101.101
25th3.253.252.752.753
50th5.505.505.505.505
75th7.757.758.258.258
90th9.109.109.909.909
95th9.559.5510.45undefined10

On evenly spaced data the interpolated value happens to equal the rank, which makes the pattern easy to see. The two interpolating methods agree at the median; nearest rank does not, because it returns the 5th sorted value rather than the average of the 5th and 6th. All three diverge steadily as you move into the tails.

Traps to avoid

  • Averaging percentiles. The mean of four servers' P95 latencies is not the fleet P95. Percentiles are order statistics and do not combine linearly. Pool the raw data and recompute.
  • Not stating the method. On a small sample the three definitions can differ by a whole observation. Any SLA, report or comparison that quotes a percentile without saying how it was computed is under-specified.
  • Quoting a percentile the sample cannot support. A P99 from 50 observations is the maximum wearing a label. Check that at least a few observations lie beyond the point you are quoting.
  • Confusing percentile with percentage. Scoring in the 80th percentile on a test does not mean scoring 80%. It means outscoring 80% of the other candidates, which could correspond to any raw mark at all.
  • Assuming percentiles are equally spaced. The gap between P50 and P60 is usually far smaller than the gap between P90 and P99, because data thin out in the tails. A ten-point move in percentile is not a fixed move in value.
  • Interpolating on discrete or categorical data. If the values are counts of defects or scores on a five-point scale, an interpolated percentile of 3.25 is not a possible observation. Use the nearest-rank method there.

Percentiles alongside the other summaries

A percentile locates one point in a distribution you already have. A z-score does something different: it locates a point relative to a mean and a standard deviation, and then converts to a percentile only if you are willing to assume a normal distribution. On raw empirical data the percentile calculator makes no distributional assumption at all, which is why it is the right tool for latencies, incomes and any other visibly skewed measurement.

The 25th, 50th and 75th percentiles together form the box of a box plot, and the IQR calculator adds the 1.5 x IQR fences that determine the whiskers. For a single figure describing the centre, the median is the 50th percentile by another name, and the standard deviation describes spread by distance where the IQR describes it by position.

When you do have a fitted distribution rather than raw data, percentiles come from the inverse cumulative function instead of from a rank. For a normal model, the inverse normal calculator converts a percentile directly into a z value and then into a raw score, and the normal distribution calculator goes the other way. Those tools extrapolate into the far tail where raw data run out; whether that extrapolation is trustworthy depends entirely on whether the normal model actually fits, which for latency data it almost never does.

Frequently asked questions

Which percentile method should I use?

Use the inclusive interpolation method unless you have a reason not to, because it is the default in Excel, R, NumPy and pandas, so it is what a reader will reproduce. Use nearest rank when the answer must be a value that actually occurred, which is common in service level agreements. Use the exclusive method when you are matching a textbook or an existing report that specifies it.

What is the difference between the 90th percentile and the top 10%?

They are two views of the same cut. The 90th percentile is the value at the boundary; the top 10% is the set of observations above it. Latency work usually quotes the boundary value, income work usually quotes the group. Either way, about one observation in ten lies beyond the cut - the exact count depends on ties and on which rank method you used.

Why does my spreadsheet give a different answer?

Almost certainly because it uses a different rank formula. Excel's PERCENTILE and PERCENTILE.INC use 1 + (n-1)p, PERCENTILE.EXC uses (n+1)p, and older statistical texts often teach nearest rank. Set this calculator's method to match and the answers will agree exactly.

How many data points do I need for a P99?

As a working rule, at least 100, and preferably several hundred. Below 100 observations there is nothing beyond the 99th percentile to interpolate towards, so the answer collapses onto the maximum. The estimate also remains unstable well past that point, because it depends on the few most extreme observations in the sample.

Can I average the P95 values from several servers?

No. Percentiles are order statistics and do not combine by averaging: the mean of the per-server P95s can be well above or well below the true fleet P95 depending on how the load and the latency distributions differ. Pool the raw observations, or keep per-server histograms and merge those.

Is the 50th percentile always the same as the median?

Under the inclusive and exclusive interpolation methods, yes - both give the standard median including the two-value average when n is even. Under nearest rank it can differ: with ten observations, nearest rank returns the 5th sorted value rather than the average of the 5th and 6th.

Can a percentile be a value that is not in my data?

Yes, whenever the rank falls between two observations and the method interpolates. The 90th percentile of the worked example on this page is 275 ms, and no request took 275 ms. If you need an answer that actually occurred, choose the nearest-rank method.

Do percentiles work on skewed data?

Yes, and that is their main advantage. They make no assumption about the shape of the distribution and are unchanged by any strictly increasing transformation of the data, so the 90th percentile of the logged values is the log of the 90th percentile. That is why percentiles rather than means are the standard summary for latencies, incomes and durations.

References

  • Sample Quantiles in Statistical Packages, The American Statistician 50(4), 361-365 — Hyndman & Fan, 1996
  • Engineering Statistics Handbook: PercentilesNIST/SEMATECH
  • Exploratory Data Analysis — Addison-Wesley, 1977 (John W. Tukey)