Subscribe
AI
7 min read

What Is the Halting Problem? The 1936 Proof That Bounds What Any AI Can Ever Decide About Code

Every tool that checks code for you has a quiet limitation it will never advertise. No linter, no verifier, no coding agent and no future model can guarantee, for every possible program, whether that program will eventually stop or run forever. This is not an engineering gap. It is a mathematical theorem, proved in 1936, and it is the reason "will it halt?" sits at the boundary of what any machine can decide. What Hilbert asked, and what Church and Turing answered In the early 20th century Da

What Is the Halting Problem? The 1936 Proof That Bounds What Any AI Can Ever Decide About Code

Every tool that checks code for you has a quiet limitation it will never advertise. No linter, no verifier, no coding agent and no future model can guarantee, for every possible program, whether that program will eventually stop or run forever. This is not an engineering gap. It is a mathematical theorem, proved in 1936, and it is the reason "will it halt?" sits at the boundary of what any machine can decide.

What Hilbert asked, and what Church and Turing answered

In the early 20th century David Hilbert posed the Entscheidungsproblem, the decision problem: is there a general mechanical procedure that can decide the truth or provability of any statement of first-order logic? Alonzo Church answered first, in a paper published in April 1936, by proving that no such procedure exists for the equivalent problem in elementary number theory, using his lambda calculus as the definition of "effective calculability" (Church 1936). Alan Turing independently delivered the same verdict in a paper received in May 1936, and in doing so introduced the machine model the field now runs on: a tape, a head, a finite state table (Turing 1936, Stanford Encyclopedia of Philosophy on the Church-Turing thesis).

Turing's framing was that no machine can decide which other Turing machines print an infinite sequence of digits without getting stuck forever, his "circle-free" problem. The modern textbook version abstracts this into the halting problem, and it took a retrospective look in 2024 to note how much of the popular story is a later reconstruction: Turing's 1936 paper contains all the core ideas of an undecidability proof, but the tidy "program X halts or does not halt on input Y" formulation and its self-referential diagonal proof are mostly postwar pedagogy (Hamkins and Nenu 2024).

The claim, and the two-line intuition

The halting problem asks for a program H that takes any program P and any input x and always terminates with a correct yes-or-no answer: does P(x) eventually halt? The standard proof says no such H can exist. Suppose H exists. Build a machine D that feeds a program to H and then does the opposite of what H predicts on that same program's own source: if H says "halts", D loops forever; if H says "loops", D halts immediately. Now ask the only interesting question: what does D do when you hand it its own code? Halting implies looping and looping implies halting, so D cannot exist, and neither can H. The contradiction comes from self-reference, which is the same mechanism Gödel used on provability in 1931.

What the theorem actually forbids is a universal decider. Given a particular program, you may well prove it terminates, and most software you meet on a Tuesday is provably loop-free by boring induction on a loop counter. Undecidability says no mechanical procedure can be right on all programs at once, and no oracle for the halting problem can be computed by any program.

A punched tape looping out of a reading machine and back into its own input slot

Rice's theorem: the generalization that makes it your problem

In 1953 Henry Gordon Rice proved the general form (statement summarized at Wolfram MathWorld, Trans. Amer. Math. Soc. 74, 1953): any non-trivial semantic property of programs, any behavioral property that some programs have and others do not, is undecidable. Halting is just the first example. So are these: will this program ever print anything? Will it crash on some input? Will it accept every valid JSON? Is it equivalent to this other program? Does it ever execute this line?

This is why the program-analysis industry is structured the way it is. Static analyzers, bug finders and model checkers are all, knowingly or not, approximations: they either restrict the programs they analyze (bounded loops, no recursion) or restrict the guarantees they offer ("may crash", never "will never crash"). An agent that runs your generated code in a sandbox and kills it after 30 seconds is not deciding halting; it is applying a timeout, which is a policy, not a proof.

Busy beavers: the finite questions nobody could answer

Tibor Radó turned the undecidability of halting into a function in 1962. The busy beaver value BB(n) is the maximum number of steps any n-state, 2-symbol Turing machine can take on a blank tape before halting. Because a general halting decider would compute BB, and because BB outgrows every computable function, BB itself is uncomputable (Radó 1962).

Here is the strange part: uncomputability in general does not stop you from answering specific instances. BB(1)=1, BB(2)=6 and BB(3)=21 were settled by exhaustive case analysis in the 1960s, and BB(4)=107 in 1983 (Radó 1962, Wikipedia census of the values). BB(5) resisted for four more decades, until the crowdsourced bbchallenge collaboration announced in July 2024 that it had decided the halting behavior of all 181,385,789 candidate 5-state machines, using specially designed "deciders" backed by a formal proof in the Coq proof assistant. The winner, found by Heiner Marxen and Jürgen Buntrock, runs 47,176,870 steps before halting, and the human-readable paper published on arXiv in September 2025 states the result as BB(5)=47,176,870. No contradiction with Turing: the collaboration did not build a universal decider, it resolved one finite slice of the space, machine by machine and pattern by pattern. BB(6) is already known to be vastly larger than anything the same methods can reach, and among the still-open 6-state machines is "Antihydra", whose behavior relates directly to the Collatz conjecture.

The floor keeps falling. Aaronson and Yedidia built an explicit 7,910-state machine whose behavior cannot be proved to be non-halting in ZFC set theory, assuming ZFC is consistent (arXiv 1605.04343), an application of Gödel's incompleteness to concrete Turing machines.

A staircase of plain machine boxes growing taller until the last one extends past the frame

The Collatz bridge

The halting problem leaks into elementary arithmetic. In 1972 John Conway proved that a natural generalization of Collatz-style iteration ("Unpredictable Iterations", cited in arXiv 2303.08141) is algorithmically undecidable: generalized Collatz maps can simulate universal Turing machines. The original 3x+1 conjecture remains open, and the strongest general result is Terence Tao's 2022 theorem that almost all Collatz orbits attain almost bounded values (arXiv 1909.03562). The lesson for anyone hoping a smart enough model could just grind through such questions: a problem statement two lines long can sit directly on top of undecidable territory.

What this means for LLMs specifically

Three consequences are worth stating plainly.

First, there is a formal limit on automated AI safety checking. A 2024 paper proved by reduction to Rice's theorem that deciding whether an arbitrary model satisfies a non-trivial alignment predicate on its inputs is undecidable (de Melo et al. 2024). Any guarantee machinery for agents has to be built from restrictions and conservative bounds, exactly like static analysis.

Second, models can be shown to fail the trivial version of the halting question in practice. On hand-built program sets where the correct answer is known, frontier LLMs make mistakes on simple loops and crash-free patterns, an informal but reproducible demonstration that scale does not purchase a halting oracle (Sultan 2024). A 2025 theory paper puts this on the map formally: undecidable instances are one of the computational boundaries where hallucination is not a training defect but an inevitability, because the model is forced to guess what no procedure can compute (arXiv 2508.07334).

Third, the theorem bounds what agents can promise each other. A coding agent that says "I verified the fix" has, at best, tested behavior on sampled inputs or proved termination under restrictions. There will never be a checker that says "this repository contains no infinite loop" and means it in general. Verification keeps working, and keeps getting better; it just cannot be total.

What the halting problem does not say

It does not say some programs cannot be proved terminating; it says no algorithm proves them all. It does not say mathematics cannot prove non-halting for interesting machines; the Coq proof of BB(5) is tens of thousands of machine-checkable non-halting arguments. And it does not say AI progress is capped by it, because almost no real workload asks the universal question. What it does say is the oldest and cleanest hard limit in computer science: a precise boundary between what is computable and what merely looks computable, and every assistant that writes code lives inside it.

Sources

AILLMeducational