On this page
You can test a program on a million inputs and still not know whether it stops on the next one. In a paper published in 1936–37, Alan Turing proved a closely related question undecidable, and the same idea shows no program can decide halting for every program and input. Here is the standard proof in six plain steps, its link to Georg Cantor's diagonal trick, and what it rules out for coders.
What is the halting problem?
The halting problem is the task of deciding, for every program and every input, whether that program will eventually stop or run forever. The Stanford Encyclopedia of Philosophy entry on Turing machines states it as the problem to decide for every Turing machine T whether or not T will halt, and shows that no Turing machine can do it.
Turing's paper, On Computable Numbers, with an Application to the Entscheidungsproblem, appeared in the Proceedings of the London Mathematical Society. The encyclopedia notes that his own question was close to, but not quite, today's halting problem.
How does the proof that it is undecidable work, step by step?
The proof is by contradiction. Assume the impossible tool exists and watch it break.
Suppose someone hands you a program halts(P, x). It always finishes, and it answers yes if program P stops on input x, no if P runs forever.
A program is just text, so you can feed a program its own source code as input.
Build a new program D. On input P, D asks halts(P, P). If the answer is yes, D loops forever. If the answer is no, D stops at once.
Now run D on its own source: D(D).
If halts(D, D) says yes, D loops forever, so the answer was wrong. If it says no, D stops, so the answer was wrong again.
Either way halts is wrong about D on D. So no program halts can be right for every program and input.
Why is it the same trick as Cantor's diagonal argument?
Cantor's diagonal argument, published in 1891, shows that the infinite binary sequences cannot be listed one by one. Write any list of sequences as rows. Go down the diagonal and flip each digit. The new sequence differs from row n at position n, so it is missing from the list. The same fact is behind how the Cantor set has uncountably many points yet length zero.
The halting proof is the same table. The rows are all programs, the columns are all inputs (which are also programs), and each entry says H for halts or L for loops. D flips the diagonal: where program n halts on itself, D loops, and the reverse. So D differs from every row. But D is a program, so it must be a row. That clash is the contradiction, and the same article calls the standard halting proof essentially a diagonal argument. More on sizes of infinity: how two injections give a bijection.
A worked example: run the diagonal by hand
Take five programs P1 to P5. Suppose the diagonal entries, P1 on P1 down to P5 on P5, read H, L, H, H, L.
D flips each one, so D on P1 to P5 behaves as L, H, L, L, H.
Compare D with P2: on input P2, P2 loops but D halts. They differ.
The same holds for every n: D disagrees with Pn on input Pn.
Now add D as a sixth row and fill in the cell D on D. Whatever you write, D's rule says the opposite. That cell is the halting problem.
What does Rice's theorem add?
Rice's theorem states that all non-trivial semantic properties of programs are undecidable. Semantic means about what the program does, not how its text looks; non-trivial means true for some programs and false for others. Henry Gordon Rice proved it in his 1951 doctoral dissertation at Syracuse University and published it as Classes of recursively enumerable sets and their decision problems in the Transactions of the American Mathematical Society in 1953.
So these questions, asked about every possible program, have no general algorithm:
Does this program stop on input 0?
Does it stop on every input?
Does it always return 0?
Does it do the same thing as this other program?
No tool can check every program for correctness. Practical checkers still help by accepting only programs in a restricted form, or by catching many bugs but not all.
How do you study a proof like this?
To rebuild any diagonal proof, ask three questions:
What is being listed? Sequences, real numbers, or programs.
What is the diagonal, and what does flipping it build?
Why must the new object already be in the list, and what breaks when it is?
Then rewrite the halting proof from memory and explain it aloud in two minutes. If step 3 feels slippery, look up countability in the Fermi Concept Library, which covers concepts across mathematics and computing.



