TL;DR
Chain-of-thought (CoT) prompting shows a language model a few worked examples in which the answer comes after a short written derivation, and then the model writes its own derivation before answering. On arithmetic, logic and word problems this often lifts accuracy a long way, with no change to the model's weights. The trade is more generated text, and so more time and cost per question.
Where you'll see it: the "show your work" mode of chat assistants, the step-by-step solutions that coding and math tools produce, and the reasoning traces that large models generate before they commit to an answer.
Intuition
Doing the sums on paper
Ask someone to multiply 23 by 47 in their head and reply at once. Most people will guess, and the guess will often be wrong. Give them a pencil and the same person gets it right, because the paper holds the partial results: , , then . Nothing about the person changed. What changed is that the intermediate steps now exist somewhere they can be read back.
A language model is in a similar position. It produces one token at a time, and each token must be chosen using only what came before it. If the answer is the very first thing it writes, it has to compress the whole problem into a single guess. If it first writes out the steps, every later token can look at those steps, so the answer is conditioned on a worked derivation rather than on the bare question.
That is the core idea of chain-of-thought prompting. The model is not taught any new skill. It is shown that the useful form of an answer includes the reasoning, and it then imitates that form.
Why it helps
There is a mechanical reason as well. A Transformer spends the same fixed amount of computation on each token it produces. A question that needs twelve arithmetic steps gets no more processing if the answer is squeezed into one token. Each reasoning token it writes is another pass through the network, with the earlier steps available to attend to. More tokens means more sequential computation spent on the problem.
- each step right 90% of the time
- each step right 99% of the time
The plot above is a toy model, but it shows the pressure that chain-of-thought relieves. A single hard leap with a 30% chance of success is worse than ten small steps, each close to certain.
The math
Let be a question, the final answer, and a reasoning trace, which is the sequence of tokens written between the question and the answer. A language model defines a distribution over whole continuations, and for any sequence the chain rule of probability gives
Here is the probability that the model writes trace after question , and is the probability of answer once the trace is in place. Read in words: first the model writes its reasoning, then it writes an answer that is conditioned on that reasoning.
Standard prompting asks for the answer directly, so it effectively uses , a single step with no trace in between. Chain-of-thought prompting puts examples of the form in the prompt and then asks for for the new question. The examples are the few-shot part of In-Context Learning; the reasoning inside them is what changes the behaviour.
Marginalising over reasoning
Many different traces can lead to the same correct answer. To score an answer, sum over all traces that produce it:
The sum is over every possible trace, which is far too many to compute. In practice we sample a few traces and use them as an estimate. This is the idea behind self-consistency, covered below.
Greedy decoding and temperature
When the model writes a trace, it draws each token from a softmax over its vocabulary. Softmax Temperature divides the logits (the raw scores the network outputs for each possible token) by a temperature before that softmax. At temperature zero the model always picks the most likely token (greedy decoding). At higher temperature it samples more freely. Greedy decoding gives one deterministic trace; higher temperature gives diverse traces, which is what self-consistency needs.
Self-consistency
Sample traces at a nonzero temperature, extract an answer from each, and take the most common answer:
Here is 1 when its condition is true and 0 otherwise. This is a majority vote. It works because wrong traces tend to scatter across many different wrong answers, while correct traces tend to agree.
Worked examples
A cafe sells muffins at 3 dollars each. Ana buys 4 muffins and pays with a 20 dollar note. How much change does she get?
Asked directly, a model might write: "8 dollars". That is correct here, but a model that answers this way often fails on problems with the same structure and more numbers. There is no visible derivation to check, so when an answer is wrong you cannot tell whether it came from a bad multiplication or a bad subtraction.
The prompt contains one worked example first, with its derivation written out. The model then answers the new question in the same form:
- Cost of the muffins: dollars.
- Amount paid: 20 dollars.
- Change: dollars.
Answer: 8 dollars.
Each line depends on the previous one. If the model had written "", the error would be visible at line 1 and the rest would follow from it. Interpretation: the reasoning is not a decoration. It is the computation, and it can be checked line by line.
The GSM8K benchmark of grade-school word problems (Cobbe et al., 2021) requires two to eight arithmetic steps per problem. Wei et al. (2022) reported that a 540-billion-parameter model, prompted with a handful of worked examples, roughly tripled its accuracy when the examples included reasoning, going from under 20% with plain answers to about 57%.
Their result also showed the gain depended on scale. Smaller models produced chains of text that looked like reasoning but often contained arithmetic or logic errors, so prompting with chains did little or nothing for them. The technique needs a model large enough to carry a coherent derivation.
Kojima et al. (2022) found a variant with no examples at all: appending "Let's think step by step" to the question was enough to elicit a trace on many tasks. This is zero-shot chain of thought.
Tradeoffs and failure modes
Chain-of-thought is not free, and the costs fall in predictable places.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Simple factual lookup or classification | Extra tokens add latency and cost, and reasoning can talk the model out of a correct first answer | Answer directly |
| Multi-step arithmetic, logic or planning | Direct answers are often wrong, and errors are invisible | Chain of thought, with a checkable final answer |
| High-stakes answer where one sample is risky | A single trace can be confidently wrong | Self-consistency: sample several traces and vote |
| Small model | Fluent but invalid steps; accuracy may not improve | Use a larger model, or fine-tune on reasoning data |
| Reasoning is needed for a decision that must be audited | The written trace may not be the real cause of the answer | Verify the answer with a separate check, do not rely on the trace alone |
Three failure modes are worth knowing.
Plausible wrong steps. A trace can read well and still contain a false step. Because the answer is conditioned on the trace, one bad step often carries through to a confidently wrong result.
Unfaithful explanations. Turpin et al. (2023) showed that a model's stated reasoning can be shaped by a hint in the prompt that the model then does not mention, so the written trace is not always an account of what drove the answer. Treat the trace as a useful scratchpad, not as a proof.
Cost and latency. A chain can be many times longer than the answer. This matters for interactive products and for large batch jobs. Self-consistency multiplies the cost again by the number of samples.
History
Wei, Wang, Schuurmans and colleagues at Google published the chain-of-thought paper in 2022, during the period when researchers were finding that very large language models could do tasks they were not trained on, given only a prompt. Their question was narrow: why do large models fail at multi-step reasoning, and can the prompt change that? Their answer, that writing the steps out is enough for sufficiently large models, was simple and easy to test, which helped it spread quickly.
Kojima and colleagues showed later in 2022 that a short instruction could replace the worked examples. Wang and colleagues introduced self-consistency in the same year as a way to get more reliable answers from the same sampling machinery. These three papers together made chain-of-thought a standard prompting method, and later models were often trained to produce reasoning traces by default.
Check yourself
QuestionRecall: in one sentence, what does chain-of-thought prompting ask the model to do before it gives its answer?Show answer
It asks the model to write out intermediate reasoning steps first, so that the final answer is generated after, and conditioned on, a visible derivation.
QuestionComputation: a model answers a question correctly with probability 0.9 per reasoning step, and a problem needs 10 independent steps. What is the chance every step is right, using the toy model from the plot? Give your answer to three decimal places.Show answer
Each step is right with probability , and the steps are treated as independent, so the chance all 10 are right is . Computing , so the answer is 0.349 to three decimal places. The point of the calculation is that even a high per-step accuracy compounds into a low chance of a fully correct chain.
QuestionWhy: why does writing reasoning steps help a transformer, given that it spends the same computation on every token?Show answer
A transformer does a fixed amount of work per token, so a question that needs several sequential steps cannot be solved within one token's computation. Each reasoning token is another pass through the network, and later tokens can attend to the earlier steps. Writing the steps therefore gives the model more sequential computation and a record it can use, rather than forcing the whole answer into one guess.
QuestionApplied: you are building a support assistant that answers 'What are your opening hours?' from a fixed FAQ, and another that calculates refunds from a multi-line order. Which should use chain-of-thought, and why?Show answer
The refund calculator should use it, because it has several dependent arithmetic steps where an intermediate error would be invisible in a bare answer, and the derivation can be checked. The opening-hours lookup is a single retrieval with no computation; chain-of-thought would add latency and cost and could introduce errors into a simple answer. Use a direct answer there.
QuestionWhy, applied: a team samples 5 traces at temperature 0.8 and takes the majority answer. A colleague says this is no better than sampling once. Who is right, and what would change the answer?Show answer
The colleague is right only if the traces are not diverse. If every sample is the same trace, the vote adds nothing. When wrong traces scatter across different wrong answers and correct traces agree, the majority is more reliable than any single sample. The gain depends on temperature producing real variety and on the correct answer being the most common one across samples. Checking the agreement rate on a labelled set would show whether the vote helps.
Sources
- Wei et al., Chain-of-Thought Prompting Elicits Reasoning in Large Language Models (2022): https://arxiv.org/abs/2201.11903
- Kojima et al., Large Language Models are Zero-Shot Reasoners (2022): https://arxiv.org/abs/2205.11916
- Wang et al., Self-Consistency Improves Chain of Thought Reasoning in Language Models (2022): https://arxiv.org/abs/2203.11171
- Turpin et al., Language Models Don't Always Say What They Think (2023): https://arxiv.org/abs/2305.04388
- Chain-of-thought prompting (Wikipedia): https://en.wikipedia.org/wiki/Chain-of-thought_prompting