AI State of the Art
Fundamentals/LLM: Understanding Large Language Models/24 min
Section 60

Chain-of-Thought Prompting

Listen as a podcast →

Making an LLM Reason

LLMs are trained to predict the next token. This mechanism works remarkably well for generating fluent text, but it has an Achilles' heel: reasoning. Without a special technique, the model has to produce its answer directly, in a single mental "jump," with no intermediate thinking step. It's like asking someone to solve 347×28347 \times 28 in their head, without scratch paper, even a smart person will get it wrong.

Chain-of-thought (CoT) prompting solves this problem elegantly by giving the model "scratch paper": you ask it (or show it by example) to spell out its reasoning step by step before giving its final answer. It's one of the most powerful and best-studied prompt engineering techniques.

Chain-of-Thought Prompting Elicits Reasoning in Large Language Models (Wei et al., 2022)

The Foundational Paper

In January 2022, Wei et al. published a paper whose idea is strikingly simple and whose implications are profound. Their discovery: adding a few examples of step-by-step reasoning to the prompt makes LLM (Large Language Model) results on reasoning tasks jump dramatically, more than threefold in the best-documented case, quantified below.

The Classic Example

Without chain-of-thought:

Q: Roger has 5 tennis balls. He buys 2 cans of 3 balls each. How many balls does he have now? A: The answer is 11.

With chain-of-thought:

Q: Roger has 5 tennis balls. He buys 2 cans of 3 balls each. How many balls does he have now? A: Roger starts with 5 balls. 2 cans of 3 balls make 2×3=62 \times 3 = 6 balls. 5+6=115 + 6 = 11. The answer is 11.

By providing examples with detailed reasoning, the model learns to produce its own chains of reasoning for new questions.

Comparison between standard prompting and chain-of-thought prompting. On the left, the example given to the model shows only the final answer and the model gets the new question wrong (27 instead of 9). On the right, the example contains the detailed reasoning highlighted in blue, and the model produces its own reasoning chain highlighted in green before giving the correct answer.
The foundational figure from Wei et al. On the left, standard prompting: the example shows only the final answer, and the model gets it wrong. On the right, the same example with the reasoning spelled out (highlighted in blue), the model imitates that format, writes out its own steps (in green) and reaches the correct answer. This is exactly the difference between the two Roger-and-his-tennis-balls dialogues above.Source : Wei et al., 2022 paper (figure 1), via Prompt Engineering Guide
Wei et al.'s Results

The reference benchmark is GSM8K (Grade School Math 8K: 8,500 primary-school maths problems stated in ordinary language). On PaLM at 540 billion parameters, switching from ordinary prompting to chain-of-thought takes the accuracy from 17.9% to 56.9%.

That is a tripling, obtained without touching the model: same weights, same question, only the form of the supplied examples changes. The effect is strongest where the task needs several steps.

Why It Works

CoT's effectiveness is explained by three complementary mechanisms:

More Compute at Inference

This is the most fundamental explanation, and it is purely arithmetic. Every generated token requires a full traversal of all the Transformer's layers. Producing 50 tokens of reasoning before the answer therefore means doing 50 times more computation than answering directly in one token.

Chain-of-thought thus converts computation time into reasoning quality. It is an explicit trade: you pay in latency and billed tokens, you gain in accuracy. Nothing magical, you are simply giving the model more room to think, in the literal sense of more operations performed.

Decomposition into Sub-problems

Intermediate steps break a complex problem into simpler sub-problems. To solve "Marie has 3 times as many marbles as Pierre, and Pierre has 5 more than Luc who has 8," the model doesn't need to calculate everything at once. It can proceed step by step: "Luc has 8 marbles, Pierre has 8+5=13, Marie has 13x3=39." Each step requires only elementary reasoning that the model handles perfectly.

Externalizing Working Memory

Without a reasoning chain, the model has to do everything "in its head," in a single forward pass. The intermediate results then live only in the activations (values computed on the fly, not learned parameters) where they can degrade or interfere with one another. With CoT they are written into the text: the model produces "Luc has 8 marbles," and when it computes Pierre's share it can re-read that number in its context. This is the difference between scratch paper and mental arithmetic.

The Transformer's Working Memory

A Transformer has a narrow working memory: at every position, all the information must fit into a vector of a few thousand numbers (4,096 to 8,192 on current models) and be propagated layer by layer. That is a bottleneck for multi-stage reasoning.

CoT gets around it by using the generated text as external memory. That memory is bounded only by the context window, hundreds of thousands of tokens rather than a few thousand numbers.

Zero-shot Chain-of-Thought

Shortly after Wei et al.'s paper, Kojima et al. (2022) made a surprising discovery: simply appending the phrase "Let's think step by step" to the prompt triggers chained reasoning, with no examples at all.

Large Language Models are Zero-Shot Reasoners (Kojima et al., 2022)

Q: A store sells apples at $2 each and oranges at $3. Marie buys 4 apples and 3 oranges. How much does she spend? Let's think step by step.

The model then spontaneously generates detailed reasoning. This zero-shot CoT approach is remarkable because it requires no examples, a simple instruction is enough.

Two-stage diagram of zero-shot chain-of-thought. First prompt, called reasoning extraction: the question is followed by the sentence Let's think step by step, and the model produces the full reasoning. Second prompt, called answer extraction: question and reasoning are fed back in, followed by Therefore the answer is, and the model outputs the final result, 375.
The full zero-shot CoT pipeline as described by Kojima et al. A first call to the model, with just the magic sentence appended to the question, elicits the reasoning chain. A second call feeds that reasoning back in and asks for the answer in the right format. No examples are provided: the sentence alone is enough to trigger the intermediate steps.Source : Kojima et al., 2022 paper (figure 2), via cnblogs
Variations of the Magic Phrase

Several phrasings work: "Let's think step by step," "Let's reason methodically," "Let's detail the reasoning," "Before answering, let's analyze the problem." The key is to signal to the model that it should spell out its thinking. Effectiveness varies across models and languages.

Self-consistency: The Wisdom of Crowds

Self-consistency (Wang et al., 2022) improves CoT further by exploiting the diversity of reasoning paths. The principle:

  1. Generate NN different reasoning chains for the same problem, sampling tokens at random with a temperature above 0 so each attempt takes a distinct route
  2. Extract the final answer from each chain
  3. Keep the majority answer
Self-Consistency Improves Chain of Thought Reasoning in Language Models (Wang et al., 2022)

The intuition is the jury's: if eight paths out of ten land on "39" and the other two give "42" and "37," then "39" is probably right. The mechanism rests on an asymmetry: there is only one correct answer, but an unlimited supply of wrong ones. Errors, being random, scatter, while successes pile up on a single value.

Diagram comparing standard chain-of-thought and self-consistency. At the top, greedy decoding produces a single reasoning chain leading to a wrong answer of 14 dollars. At the bottom, several different reasoning chains are sampled, yielding 18, 26 and 18 dollars; the majority vote keeps 18 dollars.
At the top, plain CoT: a single chain produced by greedy decoding, if it contains a mistake, the answer is wrong. At the bottom, self-consistency: several different chains are sampled for the same question, the final answer is extracted from each, and the majority answer wins, here 18 dollars, reached by two chains out of three.Source : Self-Consistency paper, Wang et al., 2022 (figure 1), via SciSpace

Here are the gains the authors report, benchmark by benchmark, rather than an approximate range:

BenchmarkGain from self-consistency
GSM8K (grade-school maths)+17.9 points
AQuA (algebraic problems)+12.2 points
SVAMP (arithmetic word problems)+11.0 points
StrategyQA (implicit reasoning)+6.4 points
ARC-challenge (science questions)+3.9 points

The price is mechanical: inference cost is multiplied by NN, the number of sampled chains, which the authors take as far as 40. This is again a compute-for-quality trade, like CoT itself, just at a different scale.

The Limits of Chain-of-Thought

Model Size

CoT only works above a certain size, and the threshold Wei et al. report is high: about 100 billion parameters, or 102310^{23} training operations. Below that, the chains produced are often incoherent, and asking the model to reason makes it slightly worse than asking for the answer directly.

This is one of the best-established examples of an emergent capability: the technique is useless, then harmful, then decisive, with nothing changing but model size. (Recent models cross that threshold far earlier, since their training explicitly prepares them to reason, but the paper's figure is the 2022 one.)

Reasoning Errors

CoT improves reasoning but doesn't eliminate errors. Models can:

  • Make calculation mistakes in the middle of the chain
  • Follow logically valid reasoning but based on false premises
  • Get "lost" in long reasoning chains
  • Produce reasoning that appears correct but is subtly wrong (reasoning hallucinations)
Plausible but Wrong Reasoning

One of CoT's risks is that it makes errors more convincing. Step-by-step reasoning that leads to a wrong answer can seem very plausible to a human reader. The presence of detailed reasoning does not guarantee the correctness of the conclusion.

Non-decomposable Tasks

Some tasks don't naturally lend themselves to sequential reasoning. Intuition, complex pattern recognition, or aesthetic judgments don't necessarily benefit from CoT.

Recent Developments

Tree-of-Thought and Graph-of-Thought

Tree-of-Thought (Yao et al., 2023) generalizes CoT by exploring several reasoning branches at once, with the ability to backtrack when a branch leads nowhere. Graph-of-Thought goes further still by allowing links between branches.

Tree of Thoughts: Deliberate Problem Solving with Large Language Models (Yao et al., 2023)

Test-time Compute: CoT Built into the Model

Recent reasoning models (OpenAI's o-series, Claude's thinking modes) are the endpoint of CoT: the reasoning chain is no longer a prompting technique but part of how the model operates, and it decides for itself how many tokens to spend according to difficulty.

An important correction, because this page long got it wrong: these models are not produced by RLHF (Reinforcement Learning from Human Feedback), which optimizes human preferences. They are trained by reinforcement learning on the reasoning chains themselves, with rewards based on whether the result is correct, the subject of the RLVR (Reinforcement Learning with Verifiable Rewards) page. That is a different objective: not "please an annotator" but "reach the right answer."

This is what is meant by test-time compute, computation spent when answering rather than when training.

Process Reward Models: Evaluating Each Step

Instead of judging only the final answer (the outcome reward), PRMs (Process Reward Models) score each step of the reasoning separately.

The appeal is easy to see: if step 3 of a 7-step chain contains an error, a PRM flags it immediately, instead of waiting for the end to find the answer wrong without knowing where. Combined with a beam search (keeping only the best-scoring continuations at each step and dropping the rest), this lets you fix the error where it happens.

CoT in Everyday Practice

For a practitioner, chain-of-thought is probably the most universally useful prompt engineering tool: solving numerical problems, logical analysis, debugging, structured decisions, drafting plans, analyzing complex documents, any task that breaks into steps.

The recommendation is simple: for any reasoning task, ask the model to show its steps. A plain "think step by step before answering" is usually enough. The extra token cost is generally repaid many times over in reliability.

One closing caveat, following from the section on errors: displayed reasoning makes an answer easier to check, but also more persuasive. Read the steps; do not settle for the fact that they are there.

Check your understanding0 / 5

1. What is the most fundamental explanation for chain-of-thought's effectiveness?

2. What happens if you apply CoT to a model well below the roughly 100-billion-parameter threshold reported by Wei et al.?

3. Why does self-consistency's majority vote work?

4. How are recent reasoning models (OpenAI's o series, thinking modes) trained?

5. Does a detailed step-by-step reasoning guarantee the conclusion is correct?