Chain-of-Thought — Step-by-Step AI Reasoning
Think step by step
The Problem: AI often jumps straight to answers, making mistakes on complex problems that require step-by-step reasoning. How can we make it think more carefully?
The Solution: Think Out Loud
Chain of Thought (CoT) prompting asks the AI to show its reasoning step by step before giving the final answer. Just like how a math teacher asks students to "show their work," this technique dramatically improves accuracy on complex problems. Unlike zero-shot prompting, CoT produces intermediate reasoning steps. It can be further enhanced with Self-Consistency — generating multiple reasoning paths and selecting the most common answer.
Think of it like solving a math problem out loud:
- 1. Read the problem: "I need to find how much money is left..."
- 2. Break it down: "First, let me calculate the total spent..."
- 3. Work through steps: "$20 + $15 + $8 = $43"
- 4. Reach conclusion: "$100 - $43 = $57 remaining"
Where Is This Used?
- Math Problems: Multi-step calculations, word problems
- Logical Reasoning: Puzzles, deduction tasks
- Complex Questions: Questions requiring multiple facts to combine
- Debugging Code: Walking through code execution step by step
Fun Fact: The phrase "Let's think step by step" is so powerful that it alone can boost accuracy by 10-40% on reasoning tasks! This was discovered by Google researchers in 2022 and is called "zero-shot CoT."
Try It Yourself!
Use the interactive example below to compare regular prompts vs Chain of Thought prompts. Watch how asking for step-by-step reasoning changes the quality of answers.
🔗 Chain of Thought (CoT) — a technique where the model "thinks out loud" step by step. This helps solve complex problems more accurately!
Mary had 5 apples. She gave 2 to Pete, then bought 3 more. How many apples does Mary have?
6 apples
How to write CoT prompts:
1. Zero-shot CoT (simplest way)
Just add the magic phrase at the end of your prompt, and the model will start reasoning step by step
Solve this problem: Mary had 5 apples. She gave 2 to Pete, then bought 3 more. How many apples does Mary have? Let's think step by step.
2. Explicit CoT (with structure)
Provide explicit reasoning structure with numbered steps
Task: A train travels at 60 km/h. How long will it take to travel 180 km if it stops for 15 minutes every 60 km? Think step by step: 1. First determine pure travel time 2. Then calculate number of stops 3. Calculate total stop time 4. Add travel time and stop time Give the final answer.
3. CoT with output format
Specify format to separate reasoning from final answer
Task: A class has 30 students. 40% are boys. How many boys are present if 3 are absent? Reason like this: <thinking> [your step-by-step reasoning here] </thinking> <answer> [final brief answer here] </answer>
CoT works because it forces the model to "show its work" — intermediate steps help avoid errors in complex reasoning. Especially useful for math, logic, and multi-step problems.
Try it yourself
Interactive demo of this technique
Mary had 5 apples. She gave 2 to Pete, then bought 3 more. How many apples does Mary have?
6 apples.
Let's solve this step by step:
- Starting amount: Mary had 5 apples
- First action: She gave 2 to Pete → 5 - 2 = 3 apples
- Second action: Bought 3 more → 3 + 3 = 6 apples
Answer: Mary has 6 apples.
Even for simple problems, CoT shows the reasoning process, which helps verify correctness and understand the logic.
Create a free account to solve challenges
4 AI-verified challenges for this lesson
This lesson is part of a structured LLM course.
My Learning Path