Ten numbers between 0 and 1 go into a list: 1/3, 1/7, √2 − 1, π − 3, e − 2 and five more. Take the first digit of the first number, the second digit of the second, and so on down the diagonal, change each one, and the result is 0.5556555555, a number that differs from every entry on the list in at least one place. The same trick works on any list, of any length, including an infinitely long one. That’s Georg Cantor’s diagonal argument, the proof that there are more real numbers than whole numbers, and it fits in about a dozen lines of Python.
Where the argument comes from
An 1891 paper
Cantor published the argument in “Ueber eine elementare Frage der Mannigfaltigkeitslehre” (“On an Elementary Question of Set Theory”), in the first volume of the Jahresbericht der Deutschen Mathematiker-Vereinigung, dated 1890/91, according to its EuDML record.
Not his first proof
As Wikipedia’s article on the argument notes, the diagonal argument wasn’t Cantor’s first proof that the real numbers can’t be counted; that appeared in 1874. The diagonal version became the famous one because it’s simpler and because the same idea carries over to many other problems.
What “countable” means
A set is countable if its members can be put in a list indexed by 1, 2, 3 and so on, with every member appearing somewhere. The whole numbers are countable by definition. So are the even numbers, the primes and the perfect squares, each of which can be listed in order even though each is a smaller-looking slice of the whole numbers. Cantor’s question was whether the real numbers between 0 and 1 could be listed that way.

Building the diagonal number
The list
A script wrote out the first ten decimal digits of ten numbers between 0 and 1:
| # | Number | First ten digits | Diagonal digit | Replaced with |
|---|---|---|---|---|
| 1 | 1/3 | 0.3333333333 | 3 | 5 |
| 2 | 1/7 | 0.1428571428 | 4 | 5 |
| 3 | √2 − 1 | 0.4142135623 | 4 | 5 |
| 4 | π − 3 | 0.1415926535 | 5 | 6 |
| 5 | e − 2 | 0.7182818284 | 8 | 5 |
| 6 | φ − 1 (golden ratio) | 0.6180339887 | 3 | 5 |
| 7 | ln 2 | 0.6931471805 | 1 | 5 |
| 8 | 1/2 | 0.5000000000 | 0 | 5 |
| 9 | 0.1234567890… | 0.1234567890 | 9 | 5 |
| 10 | 1/9 | 0.1111111111 | 1 | 5 |
The rule
Read the bolded digits down the diagonal: 3, 4, 4, 5, 8, 3, 1, 0, 9, 1. Replace each digit with 5, unless it already is 5, in which case use 6. The new number is 0.5556555555.
Why it’s missing
The new number differs from entry 1 in the first digit, from entry 2 in the second, and so on. It can’t equal any number on the list, because it disagrees with the nth number in the nth place. The script checked the ten-digit strings directly and found no match.
Why it works for infinite lists
Any list at all
Nothing in the construction depended on which numbers were listed. Suppose someone claims a complete list of every real number between 0 and 1, infinitely long. Apply the same rule to its diagonal, and the result is a real number between 0 and 1 that differs from every entry. The list wasn’t complete after all.
The conclusion
No list can be complete, so the real numbers between 0 and 1 can’t be counted. There are more of them than there are whole numbers, in the precise sense that no one-to-one matching between the two sets exists.
Why the digits 5 and 6
The choice avoids a technical trap. Some numbers have two decimal forms: 0.1000… equals 0.0999…. If the replacement rule could produce a number ending in endless 9s or 0s, the new number might secretly equal a listed number written the other way. Using only 5 and 6 makes that impossible.

“Just add it to the list”
The usual objection
The most common response to the argument is to put the missing number on the list and declare the problem fixed. The script tried exactly that: it placed 0.5556555555 at the top, kept the original ten numbers below it, extended every entry to eleven digits, and ran the diagonal again.
The new diagonal
Reading the 11 diagonal digits gives 5, 3, 2, 2, 5, 8, 9, 8, 0, 0, 1. Applying the same rule produces 0.65556555555, which differs from the newly added number in its first digit and from each of the others somewhere along the diagonal. Fixing the list created a new gap.
Why it never ends
This isn’t a quirk of the order chosen. Every time a number is added, the diagonal shifts, and the construction produces another number that the longer list lacks. Adding infinitely many numbers doesn’t help either: whatever the final infinite list is, its diagonal yields a number that isn’t on it. The argument isn’t about a particular list being badly made. It shows that every possible list, however it’s built, leaves something out.
The rationals can be counted
A surprise in the other direction
Fractions look more numerous than whole numbers, since there are infinitely many between any two integers. But they can be listed. Arrange positive fractions p/q by the sum p + q, then by numerator, skipping any that aren’t in lowest terms.
The first twenty
The script’s list begins: 1, 1/2, 2, 1/3, 3, 1/4, 2/3, 3/2, 4, 1/5, 5, 1/6, 2/5, 3/4, 4/3, 5/2, 6, 1/7, 3/5, 5/3.
Where familiar fractions land
| Fraction | Position in the list |
|---|---|
| 1/2 | 2 |
| 22/7 | 263 |
| 355/113 | 66,677 |
Every positive fraction appears at some finite position. The diagonal trick fails on this list because the number it would build isn’t a fraction in general; it’s an arbitrary decimal, and the rationals don’t include most of those. That difference is the whole content of the theorem: the rationals are countable, the reals aren’t.

Cantor’s theorem, checked exhaustively
The general version
The same diagonal idea proves a broader result, known as Cantor’s theorem: for any set S, there’s no way to match each member of S with a subset of S so that every subset gets used. The set of all subsets is always strictly bigger. Wikipedia’s article describes this generalized form.
The diagonal set
Given any assignment f, which pairs each element x with a subset f(x), build the set D of all elements x that are not members of their own assigned subset. D can’t equal f(x) for any x: if x is in D, then x isn’t in f(x), so f(x) differs from D at x; if x isn’t in D, then x is in f(x), and again they differ.
Every case for small sets
For finite sets the theorem can be checked by brute force:
| Size of S | Number of subsets | Possible assignments f | Assignments using every subset | Times D appeared among the f(x) |
|---|---|---|---|---|
| 3 | 8 | 512 | 0 | 0 |
| 4 | 16 | 65,536 | 0 | 0 |
For finite sets the result is obvious from counting alone, since 2ⁿ is always more than n. The point of running the check is that D was never among the assigned subsets in any of the 66,048 cases, exactly as the diagonal argument predicts, without relying on the counting at all. That’s the version that extends to infinite sets, where counting gives no help.
Where else the diagonal shows up
Logic and computing
The Wikipedia article notes that the diagonal technique has been used in a wide range of proofs, including the first of Gödel’s incompleteness theorems and Turing’s answer to the decision problem. Each builds an object that differs from every member of a supposedly complete list, whether of numbers, provable statements or programs.
The halting problem in one paragraph
Suppose some program could decide, for any program and input, whether it eventually stops. Build a new program that takes a program as input, asks the decider whether that program halts when fed itself, and then does the opposite. Feeding the new program to itself produces a contradiction, the same move as changing the diagonal digit. No such decider can exist.
A one-line idea with a long reach
The diagonal argument takes almost no machinery: a list, a rule for changing one entry per row, and the observation that the result disagrees with every row. The script that builds it is shorter than this paragraph. Its consequence, that some infinities are larger than others, is still one of the more surprising facts in mathematics.
Sources
- G. Cantor, “Ueber eine elementare Frage der Mannigfaltigkeitslehre,” Jahresbericht der Deutschen Mathematiker-Vereinigung 1 (1890/91), EuDML record: https://eudml.org/doc/144383
- Wikipedia, “Cantor’s diagonal argument” (used as a pointer for the 1874 proof and later applications): https://en.wikipedia.org/wiki/Cantor%27s_diagonal_argument
