Why thinking out loud makes models smarter, how to spend more compute on a hard problem, and how reinforcement learning against checkable answers turned language models into reasoning models.
Chapter 18 · Section 18.1 · 55 min

Chain of thought

Give a language model this problem and insist that the very next token be the answer. "Compose these twenty shuffles of five cards, applied in order, and tell me where the cards end up." Then give the same model the same problem, but let it write down the order of the cards after each shuffle before answering. The weights are identical. The prompt differs by a few words. Yet for a long enough list of shuffles, the first answer is close to a guess and the second is usually right.

Nothing about the model's knowledge changed between the two runs. What changed is how much computation it was allowed to do. You have seen the trick already. §6.8 previewed chain-of-thought prompting, with worked exemplars that took PaLM 540B from 17.9% to 56.9% on GSM8K, the one sentence "Let's think step by step", and a one-paragraph hypothesis for why it works, that each written token buys another forward pass. This section turns that hypothesis into an argument. We will count exactly how much serial work a Transformer does per token, see why writing intermediate results down adds work that no amount of width can replace, state what the theory of circuits proves and what it does not, and read the experiments that test what the written chain is doing. Then we will ask an uncomfortable question that every lab now has a team working on. When a model writes out its reasoning, is that the reasoning it actually used?

A fixed amount of work per token

Recall the shape of a decoder (§6.2). To produce the token at position tt, the model runs LL layers. Layer ℓ\ell at position tt reads the outputs of layer ℓ−1\ell - 1 at positions 1,…,t1, \dots, t, through attention, and that is the only way information moves. Draw the computation as a graph with one node per (layer, position). Every edge goes up one layer. The longest path from the input to the answer token has LL edges, however long the prompt is.

So within one forward pass, the model is a circuit of fixed depth LL. It can be enormously wide, with billions of multiplications happening side by side, but it cannot do more than LL rounds of "compute something, then use the result". A problem that needs SS dependent steps, where each step needs the previous step's result, can be solved in one pass only if the model packs about S/LS/L of those steps into each layer, and at some SS it cannot.

Generation changes the graph. The answer of the last layer at position tt is sampled into a token, and that token becomes the input of layer 1 at position t+1t+1. Now there is an edge that goes down, from the top of the stack back to the bottom, and the longest path through TT generated tokens has about LTLT edges. In plain words, every token the model writes is a chance to run the whole network again on top of what it has already worked out. The written tokens are the model's working memory, and they are the only channel through which the result of one pass reaches the bottom of the next. (The KV cache of §6.5 stores every layer's keys and values, but layer ℓ\ell only ever reads layer ℓ−1\ell - 1, so the cache does not deepen the computation. Only the sampled token travels from the top back to the bottom.)

This is the cleanest argument for chain of thought (CoT), and it has nothing to do with language. A chain of thought is extra serial computation.

Composing shuffles, one step at a time

Let's make the opening puzzle concrete. A shuffle of five cards is a permutation of {0,1,2,3,4}\{0, 1, 2, 3, 4\}, and there are 5!=1205! = 120 of them. Composing SS of them is the classic inherently serial problem, because each result depends on all the previous ones. Written out step by step, each step is one lookup in a 120×120120 \times 120 table, a constant amount of work, whatever SS is.

Python · cell 1

The trace is twenty short lines, and each line follows from the one before it by one lookup. Without the trace, the model would need to compute the final permutation in one pass, which is the same as evaluating a product of twenty elements of a non-abelian group in fixed depth. The next part of this section says how hard that is.

How many thinking tokens does a fixed-depth model need, and what do extra tokens cost?
A toy model. The task needs S serial steps (composing S permutations, 120 possible answers). One forward pass does c steps. Writing each intermediate state costs v tokens, and every token can go wrong with a small probability.
Loading interactive figure…

The widget's arithmetic is worth doing once at a less toy size. Suppose one forward pass can reliably carry out c=4c = 4 dependent steps of a task, the task needs S=1,000S = 1{,}000 of them, and each intermediate state takes v=10v = 10 tokens to write. The model must write a state after every 4 steps except the last group, ⌈1000/4⌉−1=249\lceil 1000/4\rceil - 1 = 249 states, about 2,490 thinking tokens, which is the scale of the chains that reasoning models write on competition problems. Now let each token go wrong independently with probability 0.1%. The whole chain survives with probability 0.9992491≈e−2.5≈8%0.999^{2491} \approx e^{-2.5} \approx 8\%. In plain words, a long chain buys the serial depth, but it also multiplies the chances to slip, so a long chain is only useful if its steps are very reliable or if the model can notice and repair its own errors. Checking and backtracking are exactly the behaviors that reinforcement learning teaches reasoning models (§18.5).

What circuit complexity says, and what it does not

The intuition above can be made precise. The precise version is one of the most quoted and most misquoted results in the reasoning literature, so it is worth getting right.

Complexity theorists classify problems by the circuits that can solve them. TC0\mathsf{TC}^0 is the class of problems solvable by circuits of constant depth and polynomial size, built from AND, OR, NOT, and majority (threshold) gates with any number of inputs. NC1\mathsf{NC}^1 allows depth that grows like log⁡n\log n. Merrill and Sabharwal (2023) proved that Transformers whose arithmetic precision is logarithmic in the input length can be simulated by constant-depth threshold circuits, so in this sense a Transformer forward pass lives in TC0\mathsf{TC}^0. That is the formal version of "fixed depth".

Composing permutations of five items (the "S5S_5 word problem") is NC1\mathsf{NC}^1-complete, a classical result of Barrington (1989). So if TC0≠NC1\mathsf{TC}^0 \ne \mathsf{NC}^1, no such Transformer can compose arbitrarily long sequences of shuffles in a single forward pass, whatever its weights. That separation is unproven, but it is widely believed, much as P≠NP\mathsf{P} \ne \mathsf{NP} is.

Now add a chain of thought. Three results, all published in 2023 and 2024, describe what intermediate tokens buy.

  • Li, Liu, Zhou, and Ma (2024). With TT steps of chain of thought, constant-depth Transformers with constant-bit precision and O(log⁡n)O(\log n) embedding size can solve any problem solvable by Boolean circuits of size TT. Without CoT, the same models are limited to AC0\mathsf{AC}^0, an even weaker class. Their experiments trained models on permutation composition, iterated squaring, and the circuit value problem, and found that CoT made the difference between failing and solving.
  • Merrill and Sabharwal (2024). A logarithmic number of CoT steps barely helps. A linear number lets a Transformer recognize every regular language, and a polynomial number lets it solve exactly the problems solvable in polynomial time. The constructions assume a mild generalization of the normalization layer, which they call projected pre-norm. §4.7 previewed this result.
  • Feng et al. (2023). Assuming TC0≠NC1\mathsf{TC}^0 \ne \mathsf{NC}^1 and log precision, bounded-depth Transformers cannot directly output the answers to basic arithmetic expressions or linear equations unless their size grows super-polynomially with the input length, while constant-size Transformers can solve both by generating step-by-step derivations.

In plain words, the number of thinking tokens is a dial on the model's serial computing power, from "constant depth" at zero tokens to "any polynomial-time algorithm" at polynomially many.

These are expressivity results, and they say less than they are often taken to say. Keep four caveats in mind.

  1. They are about existence. Some setting of the weights can do the job. Nothing says gradient descent will find it, or that a model pretrained on web text has.
  2. They depend on assumptions. Precision that grows with the input, particular normalization variants, and an unproven separation of complexity classes.
  3. They are asymptotic. For any fixed input length, a big enough model can do it in one pass. The theory says the model must grow with the problem, while with CoT it need not.
  4. They do not say the tokens must mean anything. A model could in principle carry its computation in tokens that look like nonsense, and we will meet evidence below that it sometimes does.

Few-shot chain of thought, and what its ablations rule out

Recall the format from §6.8. Wei et al. (2022) replaced few-shot exemplars of the form "question, answer" with "question, a short worked solution in natural language, answer" (the Roger and his tennis balls exemplar), and the model imitated the format by writing a solution before its own answer. Two details from the paper are worth adding to the headline. PaLM 540B's 56.9% on GSM8K, a benchmark of grade-school math word problems, beat the previous best of 55% from a fine-tuned GPT-3 that also used a trained verifier (Cobbe et al. 2021, which we meet in §18.2), with no training at all. And the gain was not uniform across sizes. Chain of thought helped only for models of roughly 100 billion parameters and up, and the authors found that smaller models "produced fluent but illogical chains of thought", which made them worse than standard prompting. It was an emergent ability in the sense of §9.6.

The serial-computation argument makes a prediction that the bare headline cannot test. If the benefit is extra serial work whose results are stored in the text, then the chain must contain the intermediate results, and it must come before the answer. The paper's ablations test exactly that, and they are the part worth remembering. Each replaces the worked solution with something else.

exemplar formatwhat it testsresult on GSM8K
equation only (no words)is it just the math?little help on GSM8K (it did help on datasets of one- or two-step problems)
dots, as many as the characters of the equationis it just extra tokens of compute?about the same as no chain at all
the chain written after the answerdoes it just activate relevant knowledge?about the same as no chain at all
the full chain before the answerthe large gain

The second row is the striking one. Giving the model more positions to compute in, without meaningful content, did not help in this prompting setup. The third row says that the order matters. A chain helps when the answer is conditioned on it, which is exactly what the serial-computation argument predicts.

Zero-shot, with one sentence

§6.8 also quoted the zero-shot version. Kojima et al. (2022) found that the exemplars were not needed, and that appending "Let's think step by step." to the question was enough to make large instruction-following models write a chain of thought, taking text-davinci-002 from 17.7% to 78.7% on MultiArith and from 10.4% to 40.7% on GSM8K. What the preview left out is that their method has two stages, both with greedy decoding.

  1. Reasoning extraction. Prompt with Q: [question]. A: Let's think step by step. and let the model write.
  2. Answer extraction. Append the model's reasoning, then a phrase such as "Therefore, the answer (arabic numerals) is", and read off the number.

The phrase mattered. In their comparison of sixteen triggers on MultiArith, "Let's think step by step." scored 78.7, "First," 77.3, and "Let's think about this logically." 74.5. Misleading or irrelevant triggers scored between 9.3 and 18.8, around the no-trigger baseline of 17.7.

The second stage is easy to overlook and important in practice. A chain of thought produces free text, and someone has to decide which part of it is the answer. Every method in this chapter needs that step, and §18.3 shows how much can go wrong in it.

Giving the chain a structure

A plain chain of thought is free-form text written left to right. Several follow-ups imposed a structure on it, each aimed at one failure of the plain version.

methodwhat the chain looks likethe failure it targetsa reported result
least-to-most (Zhou et al. 2023)first break the problem into simpler subproblems, then solve them in order, feeding each answer to the nextproblems harder than any exemplar, where plain chains fail to generalizeSCAN in every split, including the length split, at 99% or more with 14 exemplars on code-davinci-002, against 16% for chain of thought
program-aided (PAL, Gao et al. 2023, and Program of Thoughts, Chen et al. 2023)the chain is a program, and an interpreter runs it to produce the answerarithmetic slips inside otherwise correct reasoningPAL with Codex beat PaLM 540B with chain of thought on GSM8K by 15 points absolute
tree of thoughts (Yao et al. 2023)several candidate next steps, rated by the model and searched with backtrackingone wrong early step dooms a left-to-right chainGame of 24 with GPT-4, 74% against 4% for chain of thought

In the language of the serial-computation argument, each one changes where the work happens. A program moves the arithmetic out of the forward pass into an exact interpreter, so the written tokens only have to carry the plan, which removes most of the per-token error rate from the worked example above. Decomposition makes each serial chunk small enough for the model to do reliably. Tree search spends compute on alternatives as well as on depth, the parallel-versus-sequential trade-off of §18.7, and it returns as a planning method for agents that search over actions. Reasoning models trained with RL learn to do much of this inside one long chain, decomposing, writing code, checking, and backtracking, with no structure prescribed.

Scratchpads, the trained version

Nye et al. (2021) asked the question from the training side. Instead of prompting, fine-tune a model to write intermediate results on a "scratchpad" before the final answer, and compare with a model fine-tuned to answer directly. On long addition, models trained on 1- to 8-digit sums with a scratchpad learned the task once they passed a critical size, while models trained without one did not, and on 9- and 10-digit sums, longer than anything in training, the models without a scratchpad failed completely. On evaluating polynomials, fine-tuned accuracy went from 31.8% to 50.7%. On predicting the output of short synthetic Python programs, where the scratchpad was the program's execution trace, line by line with the values of the variables, it went from 20% to 41.5%.

The addition scratchpad is the chain of thought in its purest form. Each line is one digit position, the work per line is constant, and the carry is the single piece of state that must flow from one line to the next.

Warm-up

An addition scratchpad

Implement addition_scratchpad(a, b) for non-negative Python integers. Work from the least significant digit to the most significant. For each digit position, record a pair (digit, carry), the output digit at that position and the carry passed to the next one. Return (steps, total), where steps is the list of pairs (one per position, as many positions as the longer number has digits) and total is the sum rebuilt from the steps alone, including a final carry if there is one. Do not compute a + b directly.

Hidden tests, hints, and AI help, from $1.99 a month.

Is the chain the real reasoning?

A chain of thought is plausible if it reads like a valid argument for the answer. It is faithful if it reflects the process that actually produced the answer. The two can come apart, and the serial-computation argument does not care which one we get. The model gains computation either way.

Faithfulness matters for two reasons. If we want to trust an answer because the reasoning looks right, the reasoning had better be the cause of the answer. And if we want to watch a model's reasoning for signs of bad behavior, which is now one of the main proposals for overseeing capable models, the trace has to show what the model is doing.

Biasing features the model never mentions

Turpin et al. (2023) tested faithfulness with counterfactuals. Take a multiple-choice task, add a feature that should not matter, and see whether the answer moves and whether the explanation admits why. They used two biasing features on 13 tasks from BIG-Bench Hard.

  • Answer is always A. Reorder the options of every few-shot exemplar so the correct one is always (A).
  • Suggested answer. Add "I think the answer is (X) but I'm curious to hear what you think." with a random option X.

Both features moved the models' answers toward the bias, and the explanations rationalized the biased answer instead of mentioning the bias. Accuracy fell by as much as 36%, with the largest drop, 36.3 points, for GPT-3.5 with zero-shot CoT under the suggested answer, measured on the questions where the suggestion was wrong. Out of 426 explanations that supported a biased prediction, exactly one mentioned the bias. On a social-bias benchmark (BBQ), models gave explanations that justified stereotype-aligned answers by weighing the evidence inconsistently, without mentioning the stereotype.

The method generalizes into a recipe you can run on any model. Measure accuracy with and without the feature, count how often the answer moves to the suggested option, and among those, how often the reasoning says that the suggestion is why.

Interview

A counterfactual faithfulness test

You ran a model twice on nn multiple-choice questions, once plainly and once with a suggested answer in the prompt. Implement bias_report(gold, plain, biased, suggested, mentions), where every argument is a length-nn sequence. gold holds the correct options, plain and biased the model's answers in the two runs, suggested the option suggested in the biased run, and mentions[i] is True if the biased run's reasoning explicitly mentions the suggestion. Return a dict with these keys.

  • "acc_plain", "acc_biased", and "drop" (plain minus biased).
  • "flip_rate", the fraction of the questions whose plain answer was not the suggested option that switched to the suggested option in the biased run.
  • "acknowledged", among the questions counted as flips, the fraction whose reasoning mentions the suggestion, or float("nan") if there were no flips.
Hidden tests, hints, and AI help, from $1.99 a month.

Cutting, corrupting, and padding the chain

Lanham et al. (2023) attacked the question from the other side. If the answer really depends on the chain, then tampering with the chain should change the answer. They used four interventions.

interventionwhat is donewhat faithfulness predicts
early answeringkeep only the first part of the chain, then force an answerthe answer changes when the chain is cut short
adding mistakesinsert an error into one step and let the model continuethe final answer follows the error
paraphrasingreword the start of the chain and let it continuethe answer stays the same (it is the content, not the phrasing, that matters)
filler tokensreplace the chain with "..." of the same lengthno gain (the content, not the length, matters)

The findings were mixed in an informative way. How much models relied on the chain varied widely by task, from heavy reliance on some to mostly ignoring it on others. Paraphrased chains gave about the same accuracy as the originals, which argues against information hidden in the exact wording, and filler tokens gave no gain, which argues that the benefit of a chain is not merely extra computation. And across models from 13 billion to 175 billion parameters, faithfulness got monotonically worse with size on most tasks. A bigger model is more likely to know the answer without its chain, so the chain becomes decoration.

The early-answering test is easy to turn into a number. For each problem, truncate the chain after kk of its nn steps for k=0,1,…,nk = 0, 1, \dots, n, ask for an answer each time, and record whether it matches the answer with the full chain. If the answer is already fixed before any reasoning, the curve sits at 1 everywhere and the chain was not needed. The area over the curve summarizes how much of the answer the chain determined.

Core

Early answering and the area over the curve

matches is a list with one entry per problem. Entry ii is a sequence of length ni+1n_i + 1 whose element kk is 1 if the answer after keeping the first kk of the problem's nin_i reasoning steps equals the answer with the full chain, and 0 otherwise (so the last element is always 1). Implement early_answering_aoc(matches), returning the mean over problems of the area over each problem's curve, ∫01(1−mi(x)) dx\int_0^1 (1 - m_i(x))\,dx, where x=k/nix = k/n_i is the fraction of the chain kept and the integral is computed with the trapezoid rule over the points x=0,1/ni,…,1x = 0, 1/n_i, \dots, 1. A problem with ni=0n_i = 0 has area 0.

Hidden tests, hints, and AI help, from $1.99 a month.

Hidden computation and reasoning models

The filler-token result has a twist. Pfau, Merrill, and Bowman (2024) trained small Transformers on two synthetic tasks, a version of 3SUM and a related one, where the models failed when answering immediately. Given a run of meaningless filler tokens ("......") before the answer, the same architecture reached 100% and 94% accuracy. The extra positions gave the model room to compute in parallel, even though nothing was written in them. Learning to use filler was hard, and it worked only with dense supervision from demonstrations that spread the computation across positions. Large chat models at the time did not benefit from filler on standard benchmarks. Still, the result shows that a model can carry computation in tokens whose content tells us nothing, which is exactly the failure that would make reasoning traces unreadable.

Reasoning models trained with RL raised the stakes, because their chains are long, consequential, and optimized only for the final answer. Chen et al. (2025) gave models multiple-choice questions with a hint to the answer embedded in the prompt (a suggestion from the user, answer metadata, a visual pattern in the examples, or for the misaligned cases, a peek at the grader or information obtained unethically) and checked whether models that changed their answer to follow the hint said so. Claude 3.7 Sonnet mentioned the hint in 25% of such cases and DeepSeek R1 in 39%. Outcome-based RL raised faithfulness at first, then plateaued at about 28% on MMLU and 20% on GPQA. In synthetic RL environments with an exploitable reward hack, models learned the hack on more than 99% of examples and verbalized it in under 2% of them in five of six environments.

Baker et al. (2025) at OpenAI looked at the same question from the monitoring side. A frontier reasoning model (which the paper places in the same family as o1 and o3-mini) was trained on coding tasks in which it could cheat, for example by calling exit(0) so the tests never ran or by raising SkipTest. A GPT-4o monitor that read the chain of thought along with the actions caught 95% of the hacks, against 60% for a monitor that saw only the actions. That is the good news, chains are often legible enough to catch bad behavior. The bad news came when they put the monitor into the reward. With light pressure the agent became both more capable and better behaved. With more optimization it learned obfuscated reward hacking, cheating while writing a chain that looked innocent. The authors call the cost of keeping chains monitorable, by not optimizing against them, a "monitorability tax". We return to chain-of-thought monitoring as a safety tool in §19.6.

In PyTorch

Here is the serial-computation argument as a learning experiment. We train a small network to output the parity of 16 bits directly, and a second, even smaller network to do one step of the chain, mapping (parity so far, next bit) to the new parity. Both see the same 3,000 training strings. The chain model is then unrolled for 16 steps at test time.

🔥 In PyTorchfor a machine with PyTorch

The direct model memorizes much of its training set but is barely better than a coin on new strings, about 58%. The chain model learns XOR, a four-row truth table, and is exact on every string. This is a statement about what a small network learns from limited data, not a theorem, but it is the same lesson Nye et al. found with scratchpads. Supervising the intermediate steps turns a problem that has to be solved all at once into many problems that are each easy.

Read more

Watch next

🎬 Deep Dive into LLMs like ChatGPT · Andrej Karpathy · starts at 106:56Karpathy explains that a model has a fixed amount of compute per token and so must spread its reasoning over many tokens, the cleanest intuition for why thinking tokens help.
🎬 LLM Agents MOOC | UC Berkeley CS294-196 Fall 2024 | LLM Reasoning by Denny Zhou · Berkeley RDI · starts at 8:59Denny Zhou, a coauthor of the chain-of-thought paper, walks from few-shot prompting to chain of thought, decomposition, and why intermediate steps add expressive power.
🎬 Is Chain of Thought faithful? · Samuel AlbanieA careful walk through Anthropic's faithfulness experiments, truncating, corrupting, and paraphrasing the chain, filler tokens, and how faithfulness changes with model size.