Some infinite sets can be put into a list — the natural numbers, the integers, even the fractions. Cantor's diagonal argument shows that the real numbers cannot: any list of real numbers, however it is made, leaves some real number out. That is what it means for R\mathbb{R} to be uncountable, and it was the first proof that there are different sizes of infinity.

Theorem

The set of real numbers R\mathbb{R} is uncountable. There is no surjection from N\mathbb{N} to R\mathbb{R}.

A set is countable when its elements can be listed as r1,r2,r3,…r_1, r_2, r_3, \ldots, every element appearing at some finite position. It is enough to show that the interval [0,1)[0, 1) cannot be listed: a list of all reals would contain, as a sub-list, a list of all reals in [0,1)[0, 1).

Proof (Cantor's diagonal argument, 1891)

Take any sequence r1,r2,r3,…r_1, r_2, r_3, \ldots of real numbers in [0,1)[0, 1). We build a number in [0,1)[0, 1) that is not in it.

Write each rir_i as a decimal expansion:

ri=0.di1di2di3…r_i = 0.d_{i1}d_{i2}d_{i3}\ldots

If rir_i has two expansions, pick either one; it will not matter. Construct a new number x=0.x1x2x3…x = 0.x_1 x_2 x_3 \ldots whose ii-th digit differs from the diagonal digit diid_{ii}, choosing it from {4,5}\{4, 5\} only:

xi={4if dii=5,5otherwise.x_i = \begin{cases} 4 & \text{if } d_{ii} = 5, \\ 5 & \text{otherwise.} \end{cases}

Then x≠rix \neq r_i for every ii. Suppose instead x=rix = r_i. The only real numbers with two decimal expansions are those with one expansion ending in 000…000\ldots and the other ending in 999…999\ldots; the digits of xx are all 4s and 5s, so xx has exactly one expansion. The expansion we wrote down for rir_i is an expansion of xx, hence it is that one — yet the two differ in the ii-th place. So xx is in [0,1)[0, 1) and is not in the list, and no list contains every real in [0,1)[0, 1). ■\blacksquare

The proof is not really by contradiction: it is a recipe that turns any list into a number the list misses. The contradiction appears only when we assumed the list was complete.

Eight real numbers written out as rows of digits; the diagonal digits are collected and each is changed to build a new number d, which differs from every row at that row's own position.

A worked example

The card starts from 8 familiar numbers — π − 3, e − 2, √2 − 1, 1/3, 1/2, 1/7, φ − 1, ln 2 — written to 10 places. Reading down the diagonal, the first digit of the first row, the second of the second and so on, gives 0.11430798…0.11430798\ldots. Replacing each digit by the {4,5}\{4, 5\} rule gives d=0.55555555…d = 0.55555555\ldots. Step through the card and it points at the digit where dd parts from each row; for 1/21/2 that happens before its diagonal digit is even reached. Press "random list" and dd is rebuilt from the new diagonal: the recipe works the same whatever the list contains.

In binary mode the card flips each diagonal bit, 0→10 \to 1 and 1→01 \to 0. That is Cantor's own 1891 setting: he worked with infinite sequences of two symbols, not with decimals. For sequences the argument needs no repair at all — a sequence is its digits, so differing in one place means being a different sequence. Passing from binary sequences to real numbers needs one more step, because 0.0111…2=0.1000…20.0111\ldots_2 = 0.1000\ldots_2. The cleanest one: send the sequence b1b2b3…b_1 b_2 b_3\ldots to the number ∑2bn/3n\sum 2b_n/3^n, whose base-3 digits are only 0s and 2s. Different sequences give different numbers, so the reals contain an uncountable set.

Why the list cannot be repaired

The tempting reply is: "Then add xx to the list." Put xx first and shift everything else down one place. That is a new list, and the same construction applied to it gives a new number x′x' that it misses. Adding x,x′,x′′,…x, x', x'', \ldots — even infinitely many of them, interleaved — still gives just another list, and the argument applies to it as well. The theorem is not that one particular list is incomplete; it is that the map "list ↦\mapsto missing number" is defined on every list.

What it does not show: the rationals are countable

The same reasoning does not prove that Q\mathbb{Q} is uncountable, and seeing why makes the argument clearer. The rationals can be listed. Every positive fraction is m/nm/n for a pair of natural numbers, and pairs can be numbered one by one; the Cantor pairing function

π(m,n)=(m+n)(m+n+1)2+n\pi(m, n) = \frac{(m + n)(m + n + 1)}{2} + n

is a bijection from N×N\mathbb{N} \times \mathbb{N} to N\mathbb{N}, walking the grid of pairs along its anti-diagonals. Apply the diagonal construction to a list of all rationals in [0,1)[0, 1) and you get a number that is not on the list — and therefore not rational. No contradiction: the list was only ever supposed to contain rationals. The argument bites for R\mathbb{R} precisely because whatever digits xx ends up with, it is still a real number.

The same counting shows that the algebraic numbers (roots of integer polynomials) are countable, which is how Cantor first deduced in 1874 that transcendental numbers exist — almost all reals are transcendental. Likewise, there are only countably many computer programs, so almost every real number is not computable by any program.

Bigger infinities: Cantor's theorem

The diagonal idea works for any set. Cantor's theorem: for every set AA, no function f:A→P(A)f: A \to \mathcal{P}(A) onto the set of all subsets of AA exists, so ∣A∣<∣P(A)∣|A| < |\mathcal{P}(A)|. Given ff, consider

D={ a∈A:a∉f(a) }.D = \{\, a \in A : a \notin f(a) \,\}.

If D=f(d)D = f(d) for some dd, then d∈Dd \in D exactly when d∉f(d)=Dd \notin f(d) = D, which is impossible. So DD is missed. This is the diagonal again: row aa is the subset f(a)f(a), and DD disagrees with row aa about the element aa.

Infinite binary sequences are the same thing as subsets of N\mathbb{N} (bit nn says whether nn is in), so ∣P(N)∣=∣R∣=2ℵ0|\mathcal{P}(\mathbb{N})| = |\mathbb{R}| = 2^{\aleph_0}. Applying the theorem again gives ∣P(R)∣>∣R∣|\mathcal{P}(\mathbb{R})| > |\mathbb{R}|, and so on without end: there is no largest infinity.

What the argument does not settle is whether any set is strictly bigger than N\mathbb{N} and strictly smaller than R\mathbb{R}. The claim that none is, the continuum hypothesis, is independent of the standard ZFC axioms: Gödel (1940) showed it cannot be disproved from them, Cohen (1963) that it cannot be proved.

Where the diagonal reappears

  • Russell's paradox. Take ff to be the identity on "all sets": DD becomes {x:x∉x}\{x : x \notin x\}, the set of all sets that do not contain themselves. It contains itself exactly when it does not, so there is no set of all sets.
  • The halting problem. Suppose a program H(P,i)H(P, i) decides whether program PP halts on input ii. Build QQ that, given PP, asks H(P,P)H(P, P) and does the opposite: loops if PP would halt, halts otherwise. Then QQ run on itself contradicts HH. Turing (1936) built exactly this diagonal on the table of programs against inputs.
  • Gödel's incompleteness theorems rest on a diagonal lemma: a sentence that says of itself that it is unprovable.

Common misconceptions

  • "Infinity is infinity, so you can always make room." Adding finitely or countably many elements to a countable set keeps it countable. The obstacle is not a shortage of room; it is that every list misses something.
  • "The proof is only about decimal notation." With digits restricted to 4 and 5, or with Cantor's binary sequences mapped into base 3, the argument concerns numbers, not ways of writing them.
  • "It would prove the rationals uncountable too." It would only if the diagonal number were rational, and in general it is not.
  • "Uncountable means big in length." Size in the sense of counting is different from length: the Cantor set is uncountable yet has length zero, and the countable set Q∩[0,1]\mathbb{Q} \cap [0, 1] is dense in the interval.
  • "The diagonal argument was Cantor's first proof." His first proof that R\mathbb{R} is uncountable, in 1874, used nested intervals; the diagonal argument came in 1891 and was general enough to give ∣A∣<∣P(A)∣|A| < |\mathcal{P}(A)|.

Short answers

What is Cantor's diagonal argument in simple terms?

Take any list of real numbers between 0 and 1, written as decimals. Build a new number whose n-th digit differs from the n-th digit of the n-th number on the list. The new number differs from every listed number somewhere, so it is not on the list. No list, however long, contains all real numbers.

Why are the real numbers uncountable but the rationals countable?

The rationals can be listed: arrange the fractions m/n in a grid and walk it diagonally, skipping repeats. The diagonal construction applied to that list produces a number that is not rational, so it contradicts nothing. For the reals, the number it produces is a real number, and that is the contradiction.

Can you fix the list by adding the diagonal number to it?

No. Adding the missing number gives a new list, and the same construction applied to the new list produces another number missing from it. The argument works for every list, so no amount of patching ever completes one.

What about numbers like 0.4999… that equal 0.5?

Some numbers have two decimal expansions, so a new digit string could in principle name a number already on the list. The standard fix is to build the new number from the digits 4 and 5 only. Such a number has exactly one decimal expansion, so differing in a digit means differing as a number.

Does the diagonal argument prove the continuum hypothesis?

No. It shows the reals are strictly more numerous than the natural numbers. Whether some set lies strictly in between is the continuum hypothesis, which Gödel (1940) and Cohen (1963) showed can be neither proved nor disproved from the usual axioms of set theory.

How is the diagonal argument related to the halting problem?

Turing's proof that no program decides halting has the same shape. Assume a decider exists, build a program that does the opposite of what the decider predicts about that program run on itself, and the program differs from every entry on the diagonal of the table of programs and inputs.

Further reading

  • G. Cantor, "Über eine elementare Frage der Mannigfaltigkeitslehre", Jahresbericht der Deutschen Mathematiker-Vereinigung 1 (1891), 75–78. The diagonal argument, stated for sequences of two symbols.
  • G. Cantor, "Über eine Eigenschaft des Inbegriffes aller reellen algebraischen Zahlen", Journal für die reine und angewandte Mathematik 77 (1874), 258–262. The first proof of uncountability, and the countability of algebraic numbers.
  • M. Aigner, G. M. Ziegler, Proofs from THE BOOK, Springer. The chapter "Sets, functions, and the continuum hypothesis".
  • P. R. Halmos, Naive Set Theory, Van Nostrand, 1960. Countable sets, cardinals and Cantor's theorem, briefly and rigorously.
  • A. M. Turing, "On computable numbers, with an application to the Entscheidungsproblem", Proceedings of the London Mathematical Society (2) 42 (1936), 230–265.
  • P. J. Cohen, "The independence of the continuum hypothesis", Proceedings of the National Academy of Sciences 50 (1963), 1143–1148.