# Chain of thought

> Letting an AI model write out its reasoning step by step before it answers.

- Level: Intermediate
- Topics: AI
- URL: https://tidbit.legios.com.ar/chain-of-thought/
- In Spanish: [Cadena de pensamiento](https://tidbit.legios.com.ar/es/chain-of-thought/)

**Chain of thought** is the intermediate reasoning a language model writes before giving its final answer. Instead of jumping from "a store had 23 apples, used 20 and bought 6 more, how many now?" straight to a number, the model writes "23 minus 20 is 3, plus 6 is 9" and only then answers 9.

It works because a model produces text one token at a time, and each new token can build on everything written before. Writing the steps gives the model room to work: partial results end up on the page instead of having to be held "in its head". A 2022 Google paper showed that just including worked examples like this in the prompt made large models much better at math and logic puzzles; soon after, people found that adding "let's think step by step" helped too.

Today this is often built in. **Reasoning models** are trained to produce a long chain of thought before answering, and many apps let you see it, or a summary of it. Two cautions: thinking costs time and tokens, so it is not worth it for simple questions; and the written chain is not guaranteed to be the real reason behind the answer. It is useful for checking work, but it is not a perfect window into the model.

## An analogy

A teacher who says "show your work" on a math test. Writing each step helps you catch your own mistakes, and lets someone else see where you went wrong.

## Keep in mind

- The model writes intermediate steps before the final answer.
- It helps most on math, logic and multi-step problems.
- Reasoning models are trained to do it on their own.
- The written steps may not fully reflect how the answer was really reached.

## Go deeper

- [Let Claude think: chain-of-thought prompting (Claude docs)](https://platform.claude.com/docs/en/build-with-claude/prompt-engineering/chain-of-thought)
- [Chain-of-Thought Prompting Elicits Reasoning in Large Language Models (Wei et al., 2022)](https://arxiv.org/abs/2201.11903)
- [Chain-of-thought prompting on Wikipedia](https://en.wikipedia.org/wiki/Chain-of-thought_prompting)

## Related terms

- [LLM](https://tidbit.legios.com.ar/llm/): A neural network trained on huge amounts of text to predict the next word.
- [Token](https://tidbit.legios.com.ar/token/): The small chunk of text a language model actually reads.
- [Google](https://tidbit.legios.com.ar/google/): The search company that gives most products away and makes its money on ads.
- [Prompt](https://tidbit.legios.com.ar/prompt/): Everything you send to an AI model: the question, the instructions, the context.
- [Reasoning model](https://tidbit.legios.com.ar/reasoning-model/): An AI model that works through a problem step by step before it answers.
