Statistics Probability Data Science 12 min read April 25, 2026
BY: Statistics Fundamentals Team
Reviewed By: Kinza A (Data Science & ML Writer)

Random Variables in Statistics — Everything You Need to Know

A random variable assigns a number to each outcome of a random process. Roll a die, measure a person's height, count daily website visitors — each of those is a random variable.

This guide covers the definition, discrete vs continuous types, probability distributions, expected value, variance, transformations, and real-world examples. Everything in one place, with worked calculations throughout.

What Is a Random Variable?

A random variable is a function that maps each outcome of a random experiment to a real number. You write it as a capital letter — X, Y, or Z — to signal that its value is not fixed until the experiment runs.

Roll a standard die. Call the result X. Before you roll, X could be 1, 2, 3, 4, 5, or 6. After you roll, X becomes one specific number. That uncertainty before the roll, and the mapping of outcomes to numbers, is what makes X a random variable.

💡
Quick Answer

A random variable is a variable whose value is determined by the outcome of a random process. It is not random in the sense of being unknowable — its probability distribution describes every possible value and how likely each one is.

Formally, if Ω is the sample space of all possible outcomes, a random variable X is a function X: Ω → ℝ. Each outcome ω maps to a real number X(ω). You use lowercase x to denote a specific observed value: P(X = x) is the probability that the random variable X takes the value x.

🔑 Key Takeaways

The core ideas you need before going deeper into probability and statistics.

A random variable maps outcomes to numbers. It turns the language of events into the language of arithmetic.

Discrete variables take countable values. Number of heads, defects, or goals — all are discrete.

Continuous variables take any value in a range. Height, temperature, and time are continuous.

Expected value is the long-run average. It tells you where the distribution is centered.

Variance measures spread around the mean. Small variance means values cluster tightly.

Random variables are the foundation of probability. Every distribution, hypothesis test, and model starts here.

Notation and Sample Space

Getting the notation right prevents a lot of confusion later. Here is the standard convention used across textbooks and software.

Symbol Meaning Example
X, Y, Z Random variable (capital letter) X = number on a die
x, y, z Specific observed value (lowercase) x = 4
P(X = x) Probability X takes value x P(X = 4) = 1/6
P(X ≤ x) Cumulative probability up to x P(X ≤ 4) = 4/6
E[X] or μ Expected value (mean) E[X] = 3.5
Var(X) or σ² Variance Var(X) = 2.92

The sample space Ω for a coin toss is {H, T}. If X = 1 for heads and X = 0 for tails, then X maps Ω → {0, 1}. That mapping is the random variable. The domain is the sample space. The range is a set of real numbers.

Types of Random Variables: Discrete vs Continuous

Every random variable falls into one of two main categories. The distinction determines which formulas you use and which distributions apply.

Discrete Random Variables

A discrete random variable takes a countable number of distinct values. Countable means you can list them out: 0, 1, 2, 3, and so on. There may be infinitely many possible values, but they are still countable in the mathematical sense.

Examples: number of heads in 10 coin tosses, number of customers entering a shop per hour, number of defective items in a batch of 50.

Continuous Random Variables

A continuous random variable can take any value within an interval. Between any two values there are infinitely many possibilities. You cannot list them.

Examples: the exact height of a randomly selected student, the time until a light bulb burns out, the temperature at noon tomorrow.

Feature Discrete Continuous
Values Countable (0, 1, 2, …) Any real number in a range
Distribution Probability Mass Function (PMF) Probability Density Function (PDF)
P(X = exact value) Can be greater than 0 Always equals 0
Probability of range Sum of PMF values Area under the PDF curve
Named examples Binomial, Poisson, Geometric Normal, Exponential, Uniform
🔍
How to classify a random variable

Ask yourself: can I list all possible values with gaps between them? If yes, it is discrete. Can the variable take any value within an interval with no gaps? Then it is continuous. Height rounded to the nearest centimeter behaves like discrete data — but true height is continuous.

Probability Distributions for Discrete Variables

Probability Mass Function (PMF)

The PMF gives the probability that X equals each specific value. It satisfies two conditions: P(X = x) ≥ 0 for all x, and the sum of all probabilities equals 1.

For a fair die, the PMF is:

x 1 2 3 4 5 6
P(X = x) 1/6 1/6 1/6 1/6 1/6 1/6

Each value has probability 1/6. All six probabilities sum to 1. That is a valid PMF.

1 2 3 4 5 6 1/6 0 Value of X P(X = x)

Cumulative Distribution Function (CDF)

The CDF gives F(x) = P(X ≤ x). For the die example, F(3) = P(X ≤ 3) = 3/6 = 0.5. The CDF always starts at 0, ends at 1, and never decreases.

Named Discrete Distributions

Distribution Counts Mean Variance
Bernoulli(p) Single trial: success or failure p p(1 − p)
Binomial(n, p) Successes in n trials np np(1 − p)
Poisson(λ) Events in a fixed time/space λ λ
Geometric(p) Trials until first success 1/p (1 − p) / p²

Probability Distributions for Continuous Variables

Probability Density Function (PDF)

For a continuous random variable, the PDF f(x) satisfies f(x) ≥ 0 and the total area under the curve equals 1. The probability that X falls in the interval [a, b] is the area under f(x) from a to b.

One key fact trips people up: for any single exact value, P(X = x) = 0. This is not an error. With infinitely many possible values, no single point can carry positive probability. You ask instead: what is P(2.0 ≤ X ≤ 2.5)?

a b P(a ≤ X ≤ b) = shaded area area = probability

Named Continuous Distributions

Distribution Used For Mean Variance
Normal(μ, σ²) Heights, test scores, measurement errors μ σ²
Uniform(a, b) Equally likely values over a range (a + b) / 2 (b − a)² / 12
Exponential(λ) Time between events, component lifetimes 1 / λ 1 / λ²

Expected Value (Mean) of a Random Variable

The expected value E[X] is the long-run average you would get if you repeated the random experiment many times. Think of it as the center of gravity of the distribution.

Formula for Discrete Variables

E[X] = Σ x · P(X = x)

Multiply each value by its probability, then add everything up.

Worked Example

Expected Value of a Fair Die

Each face shows with probability 1/6.

E[X] = 1(1/6) + 2(1/6) + 3(1/6) + 4(1/6) + 5(1/6) + 6(1/6)

E[X] = (1 + 2 + 3 + 4 + 5 + 6) / 6 = 21 / 6 = 3.5

No single roll ever lands on 3.5. But over thousands of rolls, the average converges to 3.5. That is what expected value captures.

Formula for Continuous Variables

E[X] = ∫ x · f(x) dx, integrated over all possible values of x.

Key Properties of Expected Value

  • E[aX + b] = a · E[X] + b — scale and shift work through linearly
  • E[X + Y] = E[X] + E[Y] — this holds whether X and Y are independent or not
  • E[constant] = that constant
  • E[g(X)] ≠ g(E[X]) in general — this is Jensen's inequality territory

Real-World Example

Insurance Payout

A policy pays out as follows: 0 with probability 0.90, $1,000 with probability 0.08, $5,000 with probability 0.02.

E[payout] = 0(0.90) + 1000(0.08) + 5000(0.02)

E[payout] = 0 + 80 + 100 = $180

The insurer expects to pay out $180 per policy on average. Setting the premium above $180 covers expected losses plus profit.

Variance and Standard Deviation

Expected value tells you where the distribution sits. Variance tells you how spread out the values are around that center.

Variance Formula

Var(X) = E[(X − μ)²] = E[X²] − (E[X])²

The second form — E[X²] minus the square of E[X] — is usually faster to calculate by hand.

Standard deviation: σ = √Var(X). Because standard deviation is in the same units as X, it is easier to interpret than variance.

Worked Example — Step by Step

Variance of the Fair Die

x P(X = x) x · P(X = x) x² · P(X = x)
11/60.16710.167
21/60.33340.667
31/60.50091.500
41/60.667162.667
51/60.833254.167
61/61.000366.000
Total13.515.167

E[X] = 3.5, E[X²] = 15.167

Var(X) = 15.167 − (3.5)² = 15.167 − 12.25 = 2.917

σ = √2.917 ≈ 1.708

Die rolls scatter about 1.7 units from the mean on average.

Key Properties of Variance

  • Var(aX + b) = a² · Var(X) — adding a constant does not change spread; multiplying by a scales variance by a²
  • Var(X + Y) = Var(X) + Var(Y) when X and Y are independent
  • Variance is always ≥ 0
E[X]
Long-run average
Var(X)
Squared spread
σ
Standard deviation
F(x)
Cumulative probability

Transformations of Random Variables

You often need to work with a function of a random variable rather than the variable itself. If X has a known distribution, what does Y = g(X) look like?

Linear Transformations

For Y = aX + b:

  • E[Y] = a · E[X] + b
  • Var(Y) = a² · Var(X)
  • σ_Y = |a| · σ_X

Example

Converting Celsius to Fahrenheit

Let X = temperature in Celsius with E[X] = 20 and Var(X) = 25. The Fahrenheit version is Y = 1.8X + 32.

E[Y] = 1.8(20) + 32 = 36 + 32 = 68°F

Var(Y) = (1.8)² · 25 = 3.24 · 25 = 81

σ_Y = 1.8 · 5 = 9°F

Standardisation

Given X with mean μ and standard deviation σ, the standardised variable is:

Z = (X − μ) / σ

Z always has E[Z] = 0 and Var(Z) = 1. When X is normal, Z follows the standard normal distribution N(0, 1). This is the basis for z-scores and normal distribution tables.

Sum of Random Variables

Many real problems involve adding or combining random variables. Two rules carry the work.

  • E[X + Y] = E[X] + E[Y] — always, regardless of independence
  • Var(X + Y) = Var(X) + Var(Y) + 2·Cov(X, Y)

When X and Y are independent, Cov(X, Y) = 0, so Var(X + Y) = Var(X) + Var(Y).

Covariance

Covariance measures how two variables move together. Cov(X, Y) = E[XY] − E[X] · E[Y].

Positive covariance: X and Y tend to be large together. Negative: when one is high, the other is often low. Covariance = 0 means no linear relationship, though the two variables may still be related in nonlinear ways.

⚠️
Independence vs Uncorrelated

Independent random variables are always uncorrelated (Cov = 0). But uncorrelated variables are not always independent. Two variables can have zero covariance and still be related in a nonlinear way.

Real-World Examples of Random Variables

Situation Random Variable X Type Distribution
Rolling a die Face value shown Discrete Discrete Uniform
Free throws in a game Number of baskets made Discrete Binomial
Customer arrivals per hour Count of arrivals Discrete Poisson
Student heights in a class Height in cm Continuous Normal
Time until a machine fails Time in hours Continuous Exponential
Stock daily return Percentage change Continuous Approximately Normal
Number of defects per batch Count of defects Discrete Poisson or Binomial
Waiting time at a hospital Time in minutes Continuous Exponential or Gamma

Common Mistakes and Misconceptions

These are the errors that show up most often in homework, exams, and data work.

Mistake What Actually Happens
Confusing P(X = x) with P(X ≤ x) P(X = 4) is a single value. P(X ≤ 4) is the cumulative probability including all values up to 4.
Assuming uncorrelated means independent Zero covariance rules out a linear relationship, not all relationships. X and X² have Cov = 0 but are clearly related.
Using E[g(X)] = g(E[X]) This only holds for linear g. E[X²] ≠ (E[X])². The correct shortcut is Var(X) = E[X²] − (E[X])².
Using discrete formulas on a continuous variable For continuous X, P(X = x) = 0. Use the PDF and integration, not a probability table.
Treating X (random) and x (observed) as the same X is the variable before observation. x is the specific number you got. The distinction matters in formulas.

Random Variables vs Other Statistical Terms

Term What It Is Example
Random variable Function mapping outcomes to numbers X = number on a die
Random event A subset of the sample space "Rolling an even number"
Statistic A function of observed sample data Sample mean x̄ = (x₁ + x₂ + … + xₙ) / n
Parameter Fixed but unknown population value True population mean μ
Probability distribution Full description of probabilities for a random variable Normal distribution with μ = 0, σ = 1

FAQs

A random variable is a number whose value depends on the outcome of a random process. Roll a die and call the result X — that is a random variable. Before the roll, X could be 1 through 6. After the roll, it becomes one specific value.

A discrete random variable takes countable values — 0, 1, 2, and so on. A continuous random variable can take any value within an interval. Number of goals scored is discrete. Player running speed is continuous.

For a discrete variable, multiply each value by its probability and sum the results: E[X] = Σ x · P(X = x). For a continuous variable, the calculation uses integration: E[X] = ∫ x · f(x) dx.

Yes. A random variable can take any real number as a value, including negative ones. Profit from a trade can be negative. Temperature in Celsius can be negative. The definition places no restriction on sign.

A continuous random variable has infinitely many possible values in any interval. The probability must be spread across all of them, so the probability of landing on any single exact value is zero. You work with ranges instead: P(1.5 ≤ X ≤ 2.5).

X and Y are independent when knowing the value of one gives you no information about the other. Mathematically, P(X = x and Y = y) = P(X = x) · P(Y = y) for all values of x and y.

The expected value of a constant c is just c. E[c] = c. There is no randomness, so the "average" is simply the constant itself. This fact is used frequently when applying the linearity rule E[aX + b] = a · E[X] + b.

Read More Articles

Probability Calculator

Calculate probabilities for different random variable scenarios.

Read More →

Z Table

Use Z values to analyze probability distributions.

Read More →

Statistics and Probability

Explore the theory behind random variables and distributions.

Read More →