We usually picture a random variable as "a number that depends on chance". Rigorously, on a
probability space
(\Omega, \mathcal{F}, \mathbb{P}), a random
variable is a function
X : \Omega \to \mathbb{R}
that is measurable: for every
Borel set
B \subseteq \mathbb{R}, the preimage
X^{-1}(B) = \{\,\omega \in \Omega : X(\omega) \in B\,\} \in \mathcal{F}.
Equivalently — and this is the version you will use constantly — it is enough that
\{X \le x\} \in \mathcal{F} for every
x \in \mathbb{R}.
Why measurability is the whole point
Measurability is not red tape — it is exactly what lets us assign a probability to
statements about X. The event "X is at
most x" is the set
\{X \le x\} = X^{-1}\big((-\infty, x]\big). If that set lives in
\mathcal{F}, then \mathbb{P} can speak
about it, and we may define
F_X(x) = \mathbb{P}(X \le x).
Without measurability the preimage might not be an event at all, and
\mathbb{P}(X \le x) would be meaningless. So measurability is the
bridge that carries probability from the abstract space
\Omega over to the real line where we actually compute.
The {X ≤ x} criterion, derived
The definition demands X^{-1}(B) \in \mathcal{F} for
every Borel set B — uncountably many conditions to
check. The good news is that checking only the half-lines
(-\infty, x] suffices. Let us see why the two are equivalent.
(⇒) Measurable forces the half-lines. This direction is immediate: each
half-line (-\infty, x] is itself a Borel set, so if every Borel
preimage is an event then in particular
\{X \le x\} = X^{-1}\big((-\infty, x]\big) \in \mathcal{F} \quad \text{for every } x.
(⇐) The half-lines force measurable. This is the substantive direction.
The key fact is that the half-lines generate the Borel σ-algebra:
\mathcal{B}(\mathbb{R}) = \sigma\big(\{(-\infty, x] : x \in \mathbb{R}\}\big).
Suppose, then, that X^{-1}\big((-\infty, x]\big) \in \mathcal{F}
for every x. The preimage operation
X^{-1} respects all set operations — it commutes with
complements and with unions,
X^{-1}(B^{c}) = \big(X^{-1}(B)\big)^{c}, \qquad X^{-1}\!\left(\bigcup_i B_i\right) = \bigcup_i X^{-1}(B_i).
Therefore the collection of "good" target sets,
\mathcal{G} = \{\, B \subseteq \mathbb{R} : X^{-1}(B) \in \mathcal{F} \,\},
is closed under complements and countable unions and contains
\mathbb{R} — that is, \mathcal{G} is
itself a σ-algebra. By assumption it contains every half-line
(-\infty, x]. But
\mathcal{B}(\mathbb{R}) is the smallest σ-algebra
containing those half-lines, so it must be contained in
\mathcal{G}:
\mathcal{B}(\mathbb{R}) \subseteq \mathcal{G}.
In words: every Borel set B is "good", i.e.
X^{-1}(B) \in \mathcal{F}. That is exactly measurability. The two
conditions are equivalent, and the half-line test is all you ever check.
The half-lines are a tiny generating set, yet they bootstrap to all Borel sets
purely through the σ-algebra operations. For instance an open interval is reachable from
half-lines by complement and intersection,
(a, b] = (-\infty, b] \setminus (-\infty, a] = (-\infty, b] \cap (-\infty, a]^{c},
and a single point by a countable intersection of shrinking such intervals,
\{a\} = \bigcap_n (a - \tfrac1n, a]. Since closure under these
operations is exactly what a σ-algebra promises, controlling the half-lines controls
everything.
This is also why the collection
\sigma(X) = \{\, X^{-1}(B) : B \in \mathcal{B}(\mathbb{R}) \,\}
deserves to be called the information carried by X:
it is precisely the events you can decide just by observing the value of
X. Knowing X(\omega) \le x for every
x pins down which events of
\sigma(X) have occurred. When time enters the picture, a growing
family of such σ-algebras becomes a
filtration —
the accumulating record of what has been observed so far.
A random variable as a map
Let X be the sum of two dice, so
X : \Omega \to \{2, 3, \dots, 12\}. Each outcome
\omega on the left is carried by an arrow to its value
X(\omega) on the number line. Choose a target value below: the
diagram highlights the preimage — the set of outcomes mapping there — which
is an event in \mathcal{F}.
Let us build that preimage by hand. The sample space is the
36 ordered pairs
\Omega = \{(i, j) : 1 \le i, j \le 6\}, and
X(i, j) = i + j. The event "the sum is
7" is the preimage of the single value
7, i.e. every pair whose entries add to
7:
X^{-1}(\{7\}) = \{\,(i, j) \in \Omega : i + j = 7\,\}.
Walk i from 1 to
6; each choice fixes j = 7 - i, which
stays a legal face for every one of them:
X^{-1}(\{7\}) = \{(1,6),\,(2,5),\,(3,4),\,(4,3),\,(5,2),\,(6,1)\}.
That is a concrete subset of \Omega — an event living in
\mathcal{F} = 2^{\Omega} — with
\big|X^{-1}(\{7\})\big| = 6 outcomes. Because it is an
event, \mathbb{P} can speak about it:
\mathbb{P}(X = 7) = \tfrac{6}{36} = \tfrac{1}{6}. Measurability is
what guaranteed this preimage would be an event in the first place.