Search

Search papers and lessons

Cumulative Distribution Function

Level 2 · 8 min read

The cumulative distribution function gives the chance that a random variable is at or below each value, and it works for every kind of random variable.

On this page

  • Colour = topic mix
  • Calculus
  • Probability
  • Discrete math
  • Sign in to see your progress

TL;DR

The cumulative distribution function, or CDF, answers one question for a random variable XX: how likely is it that XX is at most some value xx? You write it F(x)=P(X≤x)F(x) = P(X \le x). It starts at 0 on the far left, rises as xx moves right, and ends at 1 on the far right.

Unlike a density, the CDF exists for every random variable, whether its values are discrete, continuous, or a mix of both.

Where you'll see it: in computing percentiles and p-values, in sampling a random value by inverting a uniform draw, and in checking whether data matches a model with the Kolmogorov–Smirnov test.

Intuition

Running total of probability

Picture a pile of sand that represents all the probability of XX, spread along the number line. The CDF at xx is how much sand lies to the left of xx, including whatever sits exactly at xx. Moving xx to the right can only add sand, so the CDF never goes down. Once all the sand is counted, it stays at 1.

This is why the CDF is the natural object to study. A density can be awkward: a coin flip has no density at all, because all its probability sits on two points. But "how much sand is to the left of xx" always makes sense.

00.511.522.533.5400.20.40.60.81xF(x) = P(X ≤ x)
  • rate 1
  • rate 0.5
CDFs of two exponential waiting times. Both start at 0, climb, and approach 1. The slower one (rate 0.5) climbs more gently.

The math

Definition

Definition: Cumulative distribution function

For a random variable XX, the cumulative distribution function is

F(x)=P(X≤x),x∈R.F(x) = P(X \le x), \qquad x \in \mathbb{R}.

Here xx is any real number, and P(X≤x)P(X \le x) is the probability that XX takes a value no bigger than xx. The CDF is defined the same way for every random variable, so it is the one description that does not depend on whether XX is discrete or continuous.

Properties

Every CDF has these properties:

  1. Non-decreasing: if a<ba \lt b then F(a)≤F(b)F(a) \le F(b), because the event {X≤a}\{X \le a\} is contained in {X≤b}\{X \le b\}.
  2. Limits: F(x)→0F(x) \to 0 as x→−∞x \to -\infty, and F(x)→1F(x) \to 1 as x→+∞x \to +\infty.
  3. Right-continuous: at a jump, FF takes the value after the jump. For example, F(3)F(3) includes all the probability sitting at 3.

Any function with these three properties is the CDF of some random variable.

Probabilities from the CDF

Almost every question about XX reduces to FF:

P(X>x)=1−F(x)P(a<X≤b)=F(b)−F(a)P(X=x)=F(x)−F(x−)\begin{aligned} P(X \gt x) &= 1 - F(x) \\ P(a \lt X \le b) &= F(b) - F(a) \\ P(X = x) &= F(x) - F(x^-) \end{aligned}

The last line is the size of a jump at xx. For a continuous variable FF has no jumps, so P(X=x)=0P(X = x) = 0 for every single value. Probability lives in intervals.

Discrete and continuous cases

For a discrete variable, FF is a staircase: flat between the possible values, and jumping by P(X=x)P(X = x) at each one. For a continuous variable with density ff, FF is the running integral of that density:

F(x)=∫−∞xf(t) dt.F(x) = \int_{-\infty}^{x} f(t)\,dt.

Where ff is continuous, the derivative F′(x)=f(x)F'(x) = f(x) by the fundamental theorem of calculus. So the CDF and the density carry the same information, and you can move between them with an integral or a derivative.

For the standard Gaussian, the CDF has no elementary closed form, but it can be written with the error function:

Φ(x)=12(1+erf⁡ ⁣(x2)).\Phi(x) = \frac{1}{2}\left(1 + \operatorname{erf}\!\left(\frac{x}{\sqrt{2}}\right)\right).
−3−2−1012300.20.40.60.81xΦ(x)
  • Φ(x), standard Gaussian
The Gaussian CDF is an S-shaped curve. It passes through 0.5 at the mean, and the markers at ±1 match the 68% rule from the Gaussian lesson.

Worked examples

Example
A fair die

Let XX be the result of one roll of a fair six-sided die. The values are 1 to 6, each with probability 1/61/6.

  1. Count the mass at or below xx. For 1≤x<21 \le x \lt 2 it is 1/61/6; for 2≤x<32 \le x \lt 3 it is 2/62/6; and so on.
  2. So F(x)=⌊x⌋/6F(x) = \lfloor x \rfloor / 6 for 1≤x≤61 \le x \le 6, F(x)=0F(x) = 0 for x<1x \lt 1, and F(x)=1F(x) = 1 for x≥6x \ge 6.
  3. F(3)=3/6=1/2F(3) = 3/6 = 1/2. Note that F(3)F(3) includes the mass at 3 itself, so F(2.9)=2/6F(2.9) = 2/6 but F(3)=1/2F(3) = 1/2.
  4. P(2<X≤5)=F(5)−F(2)=5/6−2/6=1/2P(2 \lt X \le 5) = F(5) - F(2) = 5/6 - 2/6 = 1/2.
  5. P(X>4)=1−F(4)=1−4/6=1/3P(X \gt 4) = 1 - F(4) = 1 - 4/6 = 1/3. The event "strictly above 4" leaves only the outcomes 5 and 6, which is two sixths.
Example
Lifetime of a light bulb

A bulb's lifetime TT, in hours, has CDF F(t)=1−e−t/100F(t) = 1 - e^{-t/100} for t≥0t \ge 0.

  1. The chance it fails by 100 hours is F(100)=1−e−1≈0.6321F(100) = 1 - e^{-1} \approx 0.6321.
  2. The chance it survives past 200 hours is P(T>200)=1−F(200)=e−2≈0.1353P(T \gt 200) = 1 - F(200) = e^{-2} \approx 0.1353.
  3. The chance it fails between 50 and 150 hours is F(150)−F(50)=(1−e−1.5)−(1−e−0.5)=e−0.5−e−1.5≈0.6065−0.2231=0.3834F(150) - F(50) = (1 - e^{-1.5}) - (1 - e^{-0.5}) = e^{-0.5} - e^{-1.5} \approx 0.6065 - 0.2231 = 0.3834.
  4. The median is the value mm where F(m)=1/2F(m) = 1/2: e−m/100=1/2e^{-m/100} = 1/2, so m=100ln⁡2≈69.3m = 100 \ln 2 \approx 69.3 hours. Half the bulbs fail before about 69 hours.
Example
A Gaussian score

Adult heights are roughly N(170,102)\mathcal{N}(170, 10^2) cm. What fraction are at most 190 cm?

  1. Standardise: z=(190−170)/10=2z = (190 - 170)/10 = 2.
  2. F(190)=Φ(2)≈0.9772F(190) = \Phi(2) \approx 0.9772.
  3. About 97.7% of adults are 190 cm or shorter, so about 2.3% are taller.

Tradeoffs and failure modes

The CDF is the most general description of a distribution, so it is the right tool when you do not know or do not want to assume a density. It also turns percentiles into a direct read-off, and it stays meaningful for data that has ties or point masses.

Its drawbacks show up in practice:

SituationProblemBetter choice
You need a probability for one exact value of a continuous variableP(X=x)P(X = x) is 00 here, which is uselessUse the density ff and talk about small intervals
You want to see how a shape looks by eyeAn S-curve hides detail in the tailsPlot the density, or a quantile-quantile plot
You have a sample, not a modelYou do not know FFUse the empirical CDF, which is the fraction of samples at or below xx
You need the value for a given probabilityInverting FF by hand is hard for most distributionsUse the quantile function F−1F^{-1}, computed by a library

A common mistake is to confuse P(X<x)P(X \lt x) with P(X≤x)P(X \le x). For continuous variables they are equal. For discrete ones, they differ by the mass at xx. Forgetting this gives off-by-one errors with dice, counts, and integer scores.

History

Accumulating probability is an old idea: early work on errors of measurement already asked how likely a value was to fall below a threshold. The modern, general definition came with Andrey Kolmogorov's measure-theoretic foundation of probability in 1933, which gave the distribution function a precise role for every random variable. It caught on because it removed the need to treat discrete and continuous cases separately.

Later work made the CDF central to statistics. The empirical CDF, built from a sample, is the basis of the Kolmogorov–Smirnov test, which measures the largest gap between a sample's CDF and a model's CDF. Inverting the CDF gives a way to turn uniform random numbers into samples from any distribution, which is why it appears throughout simulation.

Check yourself

QuestionWhat are the limits of F(x)=P(X≤x)F(x) = P(X \le x) as xx goes to −∞-\infty and to +∞+\infty, and why?Show answer

The limits are 0 and 1. As xx goes to −∞-\infty, the event {X≤x}\{X \le x\} shrinks to nothing, so its probability goes to 0. As xx goes to +∞+\infty, the event grows to cover every outcome, so its probability goes to 1.

QuestionA fair die has CDF F(x)=⌊x⌋/6F(x) = \lfloor x \rfloor / 6 on [1,6][1, 6]. What is P(X≥4)P(X \ge 4)?Show answer

P(X≥4)=1−P(X<4)=1−P(X≤3)=1−F(3)=1−1/2=1/2P(X \ge 4) = 1 - P(X \lt 4) = 1 - P(X \le 3) = 1 - F(3) = 1 - 1/2 = 1/2. The subtle step is writing P(X<4)P(X \lt 4) as P(X≤3)P(X \le 3), which is valid because XX takes only whole-number values. Counting the outcomes 4, 5, 6 gives 3/6=1/23/6 = 1/2, the same answer.

QuestionWhy does the CDF work for every random variable when the density does not?Show answer

A density only exists when probability is spread smoothly over values. A discrete variable puts its probability on separate points, so its density would have to be a point mass, which is not an ordinary function. The CDF counts probability to the left of xx, and that quantity is always defined, even when FF has jumps.

QuestionA web service's response time TT (in milliseconds) has F(200)=0.95F(200) = 0.95. What does this say about the 95th percentile, and what fraction of requests take longer than 200 ms?Show answer

The 95th percentile is 200 ms, because 95% of responses take at most 200 ms. The fraction taking longer is P(T>200)=1−F(200)=0.05P(T \gt 200) = 1 - F(200) = 0.05, or 5%. This is the kind of statement a latency target is written as.

Sources