🎉 75% of content is free forever — Unlock Premium from $10/mo →
CW
NEWSLIVESearch All Content
💼 Servicesℹ️ About✉️ ContactView Pricing Plansfrom $10

Percentiles and Quartiles — Calculation and Interpretation

Foundations of StatisticsDescriptive Statistics🟢 Free Lesson

Percentiles and Quartiles

Descriptive Statistics

Where Does Any Value Stand Relative to the Rest?

Percentiles tell you the relative standing of any value within a dataset. Quartiles are special percentiles that divide data into four equal parts.

  • Percentile rank — "You scored better than 85% of test takers"
  • Quartiles — Q1, Q2 (median), Q3 split data into four equal groups
  • Deciles — Ten equal groups for finer-grained comparison
  • Interpolation methods — Different calculators give slightly different answers; know why

What You'll Learn

  • 1Explain the percentile contract: the value below which p percent of observations fall
  • 2Compute quartiles and arbitrary percentiles by hand using the linear interpolation position formula
  • 3Read percentile rank in its weak, strict, and averaged variants and choose the right one
  • 4Diagnose why two tools report different quartiles for the same data and pick a documented method

A single mean flattens a distribution into one number, losing the story of who sits at the top, who lags, and where the crowd actually clusters. Percentiles restore that structure without assuming any distributional shape. When a product page reports a P95 latency of 400 milliseconds, or a test board publishes the 90th-percentile score, the claim is a positional one: p percent of the mass lies at or below that threshold. This lesson builds the calculation behind those claims and the conventions that make two tools disagree by small but auditable amounts.

What the pth Percentile Actually Promises

Formally, the th percentile is a value satisfying and in the population, with sample versions defined by counting. Quartiles are the special cases ; deciles are ; the median is simply the 50th percentile, and the "quintiles" of sports drafts are the 20th, 40th, 60th, and 80th percentiles. Two properties make percentiles robust enough for production reporting: they are invariant under any strictly increasing transformation (squaring every latency preserves its percentiles' ordering), and they ignore how extreme an extreme value is — a 900 ms outlier cannot drag the median the way it drags the mean.

Fractional positions are the entire point: when lands between two observations, the percentile is interpolated, which is why quartiles of small datasets often carry decimals.

The Interpolation Formula, Worked by Hand

Take twelve exam scores sorted ascending: 12, 15, 18, 20, 22, 25, 27, 30, 35, 38, 40, 42. With , the span controls every position.

python
import numpy as np
from scipy import stats

scores = np.array([12, 15, 18, 20, 22, 25, 27, 30, 35, 38, 40, 42])
q1, med, q3 = np.percentile(scores, [25, 50, 75])
print(f"n = {scores.size}")
print(f"Q1 = {q1:.2f}  (hand check: 19.50)")
print(f"Median = {med:.2f}  (hand check: 26.00)")
print(f"Q3 = {q3:.2f}  (hand check: 35.75)")
print(f"IQR = {q3 - q1:.2f}")
print(f"P90 = {np.percentile(scores, 90):.2f}  (hand check: 39.80)")

Percentile Rank: The Inverse Question

Percentile functions answer "what value sits at p percent?" while percentile rank answers the mirror question: "where does this value sit?" Suppose a student scores 30 on the twelve-score exam. The weak (at-or-below) rank counts everyone at or under 30, which is eight of twelve, or the 66.7th percentile. The strict (below-only) rank counts seven of twelve, or the 58.3rd percentile. SciPy's percentileofscore exposes both through its kind parameter: weak, rank, strict, and mean, with rank averaging the two boundary positions. Exams usually publish the weak version because it rewards ties generously; anomaly detectors often prefer strict ranks so that repeated identical values do not cluster artificially at one percentile.

kindRuleScore 30 among twelveReading
weakcount of values less than or equal8/12 = 66.7"At or below"
strictcount of values strictly below7/12 = 58.3"Below"
rankhalfway between strict and weak62.5Tie-averaged
meanaverage of ranks of tied values62.5 hereSymmetric option
python
score = 30
for kind in ['weak', 'rank', 'strict', 'mean']:
    pct = stats.percentileofscore(scores, score, kind=kind)
    print(f"kind='{kind}': score {score} is at the {pct:.1f}th percentile")

Quartiles, Deciles, and the Five-Number Summary

Bundling the minimum, Q1, median, Q3, and maximum produces the five-number summary, the backbone of every box plot and of Tukey's outlier fences. The fences extend below Q1 and above Q3; on the twelve-score data the lower fence is and the upper fence is , so nothing in this dataset qualifies as a fence-breaking outlier. Deciles add resolution inside the tails: D9 of the same data sits at , interpolating to . Reporting deciles alongside quartiles is common in income statistics, where the D9-to-D1 ratio summarizes top-end concentration.

LandmarkPercentilePosition with n = 12Value
Minimump = 0h = 112
Q125thh = 3.7519.5
Median50thh = 6.526
Q375thh = 9.2535.75
D990thh = 10.939.8
Maximum100thh = 1242
python
def five_num_summary(arr, label=''):
    q1, med, q3 = np.percentile(arr, [25, 50, 75])
    iqr = q3 - q1
    lo, hi = q1 - 1.5 * iqr, q3 + 1.5 * iqr
    outliers = arr[(arr < lo) | (arr > hi)]
    if label:
        print(f"\n=== {label} ===")
    print(f"Min {arr.min():.1f} | Q1 {q1:.2f} | Med {med:.2f} | Q3 {q3:.2f} | Max {arr.max():.1f}")
    print(f"IQR {iqr:.2f} | fences [{lo:.2f}, {hi:.2f}] | outliers: {outliers.size}")

np.random.seed(42)
exam = np.random.normal(75, 12, 200).clip(0, 100)
five_num_summary(exam, "Exam Scores")

Why Calculators Disagree

Excel, NumPy, R, Minitab, and your textbook can each emit different quartiles for the same small dataset, and none of them is wrong — they implement different published conventions. NumPy's default linear method is the rule used above. The lower and higher methods snap to the adjacent observation instead of interpolating; nearest rounds ; midpoint averages the two neighbors when is fractional. R's quantile function exposes nine type codes, of which type 7 matches NumPy's linear default and type 6 matches Minitab's practice. For large samples the variants converge to within rounding; for under about 20 they can differ by several percent, which is exactly the regime of A/B tests and small clinical pilots. The professional fix is to name your method in the report — "quartiles computed with NumPy's linear convention" — so a reviewer can reproduce your table digit for digit.

python
d = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
for method in ['linear', 'lower', 'higher', 'midpoint', 'nearest']:
    val = np.percentile(d, 50, method=method)
    print(f"  method='{method}': median = {val}")

small = np.array([2, 4, 6, 8, 10, 12])
print("\nQ1 of a six-value set by method:")
for method in ['linear', 'lower', 'higher', 'nearest']:
    print(f"  {method}: {np.percentile(small, 25, method=method):.2f}")

Percentiles in Production: Latency Budgets and Outlier Fences

Service-level objectives live on percentiles. Consider ten observed request latencies in milliseconds: 120, 122, 125, 127, 128, 130, 135, 140, 400, 900. The mean is 232.7 ms, which describes no real user experience. The median is 129 ms, capturing the typical request. The P95 sits at , interpolating between 400 and 900 to 675 ms — and an SLA promising P95 below 500 ms is already violated even though the average looks acceptable. This is why latency dashboards report P50, P95, and P99 rather than means: the tail is the user complaint. The same percentile machinery clips features before scaling, bins skewed predictors into equal-frequency groups, and defines the quantile targets that quantile regression predicts when the mean is the wrong summary.

python
latencies = np.array([120, 122, 125, 127, 128, 130, 135, 140, 400, 900])
p50, p95, p99 = np.percentile(latencies, [50, 95, 99])
print(f"Mean  = {latencies.mean():.1f} ms")
print(f"P50   = {p50:.1f} ms")
print(f"P95   = {p95:.1f} ms   (SLA target: under 500 -> {'PASS' if p95 < 500 else 'FAIL'})")
print(f"P99   = {p99:.1f} ms")

# Equal-frequency binning with percentile edges
skewed = np.random.lognormal(3, 1, 1000)
edges = np.percentile(skewed, [0, 25, 50, 75, 100])
binned = np.digitize(skewed, edges[1:-1])
print(f"\nQuantile bin edges: {edges.round(1)}")
print(f"Counts per bin: {np.bincount(binned)}")

💡Percentiles never extrapolate

A percentile is a statement about observed order statistics. The 110th percentile of your latency sample does not exist, and predicting one requires a parametric tail model — which is exactly what extreme value theory provides when the stakes justify it.

Common Mistakes

Comparing quartiles computed by different tools without checking methods

Fix: Small samples diverge across conventions; standardize on one library and state the method in your write-up.

Averaging percentiles across groups or time windows

Fix: Percentiles are not linear: recompute from pooled data, or use a weighted quantile method designed for streaming merges.

Using percentile rank and percent-of-below interchangeably in tied data

Fix: Weak, strict, and averaged ranks differ when ties exist; declare the kind parameter so the number is reproducible.

Best Practices

  • Report P50 alongside P95 and P99 for any latency or cost metric
  • Document the interpolation convention whenever sample sizes are small
  • Use the interquartile range fences, not 3-sigma rules, to screen skewed data for outliers
  • Prefer percentile targets over means when the loss function is asymmetric

Key Takeaways

  • Percentile position h = 1 + (n − 1) p / 100 with linear interpolation reproduces NumPy's default convention
  • Quartiles split data into equal-frequency quarters; the IQR covering the middle half drives robust outlier fences
  • Percentile rank has weak, strict, and averaged variants that diverge under ties
  • P95 and P99 latency budgets expose tail behavior that means hide, which is why SLAs are written in percentiles

Frequently Asked Questions

Is the median always the average of Q1 and Q3?

No. The median, Q1, and Q3 are computed independently at their own interpolation positions. On skewed data the median can sit much closer to Q1 than to Q3; that asymmetry is the skewness you then go on to measure.

Why does my calculator give a different quartile than NumPy?

Because quartiles of small samples are convention-dependent. NumPy's linear default matches R's type 7, while Minitab and several textbooks use rules closer to lower or type 6. The values converge as n grows, so disagreement is a small-sample property, not an error.

Do percentiles require a normal distribution?

No — that is their advantage. Percentiles are fully non-parametric: any strictly increasing rescaling of the data rescales percentiles the same way, and no bell curve is ever assumed. Parametric alternatives are only needed when you must extrapolate beyond the observed range.

Interview Questions

Q1: How do you compute the 75th percentile of an eight-value dataset by hand?

With h = 1 + (n − 1) p / 100 you get h = 1 + 7 × 0.75 = 6.25, so take the sixth value and add 0.25 times the gap to the seventh value. That linear interpolation is NumPy's default.

Q2: Why do SLAs quote P95 rather than the mean latency?

A mean hides the tail: one 900 ms request among nine fast ones moves the average slightly but ruins ten percent of experiences. P95 surfaces exactly the slowest five percent of requests that drive user complaints.

Q3: What are Tukey's outlier fences and how are quartiles involved?

Fences sit at Q1 − 1.5 × IQR and Q3 + 1.5 × IQR, where IQR = Q3 − Q1. Observations beyond a fence are flagged as outliers by the box plot convention, which is robust because both anchors are percentiles.

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-14

—
☆☆☆☆☆
0 ratings

Rate & Feedback

Need Expert Statistics Help?

Get personalized tutoring, project support, or professional consulting.

Advertisement