TechniqueGuideintermediate14 min read

Chain-of-Thought Prompting: A Step-by-Step Guide

Get dramatically better AI reasoning by teaching models to show their work before answering

The Reasoning Gap

Ask an AI model “What is 247 times 38?” and it will often get it wrong. Ask it “What is 247 times 38? Work through this step by step” and it gets it right. Same model. Same knowledge. The only difference: you told it to show its work.

This is the reasoning gap. AI models have the ability to solve complex problems, but they default to pattern-matching their way to an answer in a single leap. When the answer requires multiple logical steps, that leap often lands in the wrong place.

Chain-of-thought prompting closes this gap. It is the single most impactful technique you can learn after basic prompt structure. Not because it is fancy, but because it works on the hardest class of problems: the ones that require thinking.

Insight

Chain-of-thought prompting was formally described by Google researchers Wei et al. in 2022, but the core idea is older than AI: breaking hard problems into steps is how humans solve them too. CoT just teaches models to do what good thinkers do naturally.

What is Chain-of-Thought Prompting?

Chain-of-thought prompting is a technique where you instruct the AI to reason through intermediate steps before producing a final answer. Instead of jumping straight to a conclusion, the model lays out its thinking process, which significantly improves accuracy on tasks that involve logic, math, multi-step analysis, or complex decision-making.

Think of it as the difference between asking someone “what’s the answer?” versus “walk me through how you’d figure this out.” The second version forces deliberate reasoning instead of gut instinct.

Here is the simplest possible example:

Before
A store has 15 apples. They sell 8 and receive a shipment of 23. How many do they have?
After
A store has 15 apples. They sell 8 and receive a shipment of 23. How many do they have?

Think through this step by step before giving your final answer.

The second prompt produces reasoning like: “Starting with 15 apples. After selling 8: 15 - 8 = 7 apples. After receiving 23: 7 + 23 = 30 apples.” This step-by-step process makes errors visible and self-correctable, and it sharply increases the chance of a correct final answer.

Pro Tip

CoT is not about getting longer responses. It is about getting more accurate responses. The reasoning steps are a means to an end. If you only want the final answer, you can ask the model to think step by step and then provide just the conclusion.

Why CoT Works (The Cognitive Science)

Large language models generate text one token at a time, left to right. Each token is influenced by all the tokens before it. When a model jumps straight to an answer, it has to compress all the reasoning into a single prediction step. That works for simple recall (“What is the capital of France?”) but fails for problems that require multiple dependent inferences.

Chain-of-thought prompting works because it turns internal, implicit reasoning into external, explicit text. Each intermediate step becomes part of the context that informs the next step. The model literally has more information to work with by the time it reaches the final answer, because its own reasoning is now part of the input.

There are three mechanisms at play:

1. Decomposition

Complex problems become sequences of simpler sub-problems. Each sub-problem is within the model’s reliable capability range, even when the composite problem is not.

2. Working Memory Extension

By writing intermediate results into the output, the model creates an external scratchpad. It no longer has to hold all intermediate values in its hidden state simultaneously.

3. Error Propagation Control

When reasoning is explicit, mistakes in early steps are visible and can be caught. Without CoT, an error in implicit reasoning silently corrupts the final answer with no way to diagnose what went wrong.

Insight

This is why CoT works better on harder problems. Easy problems do not benefit much because the model can solve them in one step anyway. The harder the problem, the bigger the improvement from step-by-step reasoning. If your task is trivial, skip CoT. If it requires real thought, always use it.

Three Types of Chain-of-Thought Prompting

Not all CoT is the same. The three variants differ in how much effort you invest and how much control you get over the reasoning process.

1

Zero-Shot CoT

Add "think step by step" or similar reasoning triggers to your prompt. No examples needed. Works surprisingly well for most tasks.
2

Manual CoT (Few-Shot)

Provide one or two worked examples showing the reasoning process you want. The model mirrors your demonstrated thinking pattern.
3

Auto-CoT

Ask the model to generate its own reasoning examples first, then use those to solve the real problem. Best for complex, multi-domain tasks.

Zero-Shot CoT: The Five-Word Upgrade

Zero-shot CoT is the easiest technique in all of prompt engineering. You add a reasoning trigger phrase to your prompt and the model does the rest. No examples, no elaborate setup. Just an instruction to think before answering.

The most well-known trigger is “Let’s think step by step” but there are several variants that work well for different situations:

Trigger PhraseBest For
“Think step by step”General reasoning, math, logic
“Work through this methodically”Analysis, evaluation, comparison
“Break this down into parts”Complex decomposition, planning
“Consider each factor, then conclude”Decision-making, risk assessment
“First analyze, then recommend”Advisory tasks, consulting-style output
Zero-Shot CoT: Build vs. Buy Decision
I need to decide whether to build a feature in-house or buy a third-party solution. Here are the details:

Feature: User authentication with SSO
Team size: 3 backend engineers
Timeline: 6 weeks
Budget: $15,000/year for tooling
Current stack: Node.js, PostgreSQL, AWS

Consider each factor systematically - cost, time, maintenance burden, security implications, and team expertise - then provide your recommendation with reasoning.

Pro Tip

Position the reasoning trigger after the problem description, not before it. The model needs to see the full problem before it starts reasoning. “Think step by step about the following...” works less well than presenting the problem first, then asking for step-by-step reasoning.

Manual CoT (Few-Shot): Show the Reasoning Pattern

Manual CoT gives you the most control. You provide one or two worked examples that demonstrate exactly how you want the model to reason. The model then applies that same reasoning pattern to your actual problem.

This is more effort than zero-shot, but it pays off when you need a specific reasoning structure, when zero-shot reasoning tends to skip important considerations, or when you are running the same type of analysis repeatedly.

Manual CoT: Security Code Review
I need you to evaluate code changes for potential security issues. Here is how I want you to reason through each change:

**Example:**
Code change: Added user input directly into SQL query string
Step 1 - Identify the data flow: User input from request.body.name flows into a raw SQL string concatenation
Step 2 - Check for sanitization: No parameterized queries, no input validation, no escaping
Step 3 - Assess attack surface: This endpoint is publicly accessible, no authentication required
Step 4 - Rate severity: CRITICAL - direct SQL injection vulnerability in a public endpoint
Step 5 - Recommend fix: Use parameterized queries via the ORM. Add input validation for expected format.
Verdict: Block this change. SQL injection is exploitable immediately.

**Now evaluate this change:**
Code change: New API endpoint reads a filename from the query parameter and serves the file using fs.readFile(req.query.filename)
  • Make your example realistic but clear: Use a case that is similar in complexity to the real task, not a trivially simple one
  • Label your reasoning steps: Explicit labels like “Step 1” or named phases help the model replicate the exact structure
  • Show the connective tissue: Do not just list steps. Show how each step’s conclusion feeds into the next step
  • Include the final synthesis: Always end your example with how the steps lead to a conclusion
  • One example is usually enough: Two examples help if the pattern is complex. Three is almost never necessary and wastes context window

Warning

Your example sets the ceiling. If your worked example has shallow reasoning, the model will produce shallow reasoning. If your example considers edge cases and tradeoffs, the model will too. Spend the time making your example genuinely good.

Auto-CoT: Let the Model Bootstrap Its Own Reasoning

Auto-CoT is a two-step technique. First, you ask the model to generate reasoning examples for problems similar to yours. Then, you feed those generated examples back as few-shot context for the real problem. This gives you the benefits of manual CoT without having to write the examples yourself.

This works best when you are tackling a domain where you cannot easily write expert-level worked examples, or when you want the reasoning to be adapted to the specific nuances of a new problem category.

Auto-CoT Step 1: Generate Reasoning Example
Step 1: I need to analyze customer churn patterns. Before tackling my specific dataset, generate a worked example of churn analysis reasoning.

Show me how you would analyze this hypothetical scenario:
- SaaS product, 5000 users
- Monthly churn spiked from 3% to 7% over 2 months
- No pricing changes
- New competitor entered the market
- Support ticket volume increased 40%

Walk through your complete analytical reasoning: what you would examine, in what order, what each finding might indicate, and how you would synthesize the findings into actionable recommendations.
Auto-CoT Step 2: Apply to Real Problem
[Paste the generated reasoning example from Step 1 above]

Now apply that same analytical framework to my actual situation:
- E-commerce subscription box, 12,000 subscribers
- Monthly churn went from 5% to 11% over the last quarter
- We raised prices 15% two months ago
- Fulfillment delays averaging 4 days beyond promised delivery
- NPS score dropped from 42 to 28
- Social media complaints up 3x, mostly about product quality

Use the same systematic reasoning approach. Examine each factor, assess interactions between factors, and give me prioritized recommendations.

Insight

Auto-CoT is particularly useful when you are working across domains. If you are a marketing person who needs to reason about technical architecture, or an engineer who needs to reason about financial modeling, auto-CoT lets the model generate domain-appropriate reasoning patterns you might not know how to write yourself.

CoT Before & After: Real Examples

The best way to understand CoT’s impact is to see side-by-side comparisons across different domains. In each case, the “after” version produces substantially more accurate and useful output.

Debugging a Performance Issue

Before
My React app is slow. The page takes 4 seconds to load. How do I fix it?
After
My React app takes 4 seconds to load the dashboard page. The dashboard fetches data from 3 API endpoints and renders 6 chart components.

Tech stack: React 18, Next.js, recharts for charts, SWR for data fetching, Vercel hosting.

I need you to diagnose the likely causes and recommend fixes. Work through this systematically:
1. First, identify the most probable bottlenecks given this architecture
2. For each bottleneck, explain why it causes slowness and how to confirm it
3. Then prioritize fixes by impact-to-effort ratio
4. For each recommended fix, give me the specific implementation approach

Writing a Project Proposal

Before
Write a proposal for migrating our database to PostgreSQL.
After
I need to write a proposal for migrating our primary database from MySQL 5.7 to PostgreSQL 16. This proposal goes to our VP of Engineering for budget approval.

Context:
- Current MySQL instance handles 50M rows, 2000 queries/second peak
- Pain points: lack of JSONB support, poor full-text search, licensing concerns
- Team: 4 backend engineers, 1 DBA, moderate PostgreSQL experience
- Current monthly cost: $1,800/month on RDS

Before writing the proposal, reason through:
1. What are the strongest arguments FOR migration that a VP Engineering cares about?
2. What are the realistic risks and how do we mitigate each one?
3. What is a credible timeline given the team size and data volume?
4. What will the VP want to see in terms of cost comparison?

Then write the proposal incorporating your analysis. Use a format with Executive Summary, Current State, Proposed Solution, Risk Mitigation, Timeline, and Cost Analysis sections.

Analyzing a Business Decision

Before
Should we expand to the European market?
After
We are a B2B SaaS company ($4M ARR, 200 customers, project management space) considering European market expansion.

Current state:
- 95% of revenue from US/Canada
- 12 inbound leads from EU companies last quarter (up from 3 the prior quarter)
- Product is English-only
- No GDPR-specific data handling in place
- Competitor Basecamp recently launched EU-specific pricing

Analyze this decision step by step:
1. Evaluate the demand signal - are 12 leads enough to justify expansion?
2. Assess the investment required: GDPR compliance, localization, support coverage, legal entity
3. Estimate timeline and cost for minimum viable EU presence
4. Consider the competitive implications of waiting vs. acting now
5. Identify the biggest risk and how to test the market before full commitment

End with a clear recommendation: go, no-go, or test-first, with specific next steps.

Success

Notice the pattern in every “after” example: provide context, state the problem clearly, then explicitly list the reasoning steps you want. You are not hoping the model thinks carefully. You are structuring the thinking process.

When to Use CoT (and When Not To)

CoT is powerful, but it is not universally the right choice. Using it inappropriately wastes tokens, slows down response time, and can actually introduce errors on simple tasks where the model overthinks.

Use CoT When:

  • Math or calculations with multiple steps
  • Logic puzzles or constraint satisfaction
  • Multi-criteria decision making
  • Code debugging that requires tracing execution
  • Analyzing cause and effect in complex systems
  • Comparing multiple options with tradeoffs
  • Planning tasks with dependencies
  • Legal, medical, or financial reasoning where accuracy matters
  • Any task where you would use scratch paper if doing it yourself

Skip CoT When:

  • Simple factual recall (“What is the capital of France?”)
  • Creative writing where you want flow, not analysis
  • Translation or language tasks
  • Summarization of text (model just needs to compress, not reason)
  • Simple reformatting or conversion tasks
  • Brainstorming or ideation (reasoning can constrain creativity)
  • When speed matters more than depth
  • Tasks with a single obvious answer

Warning

A common trap: using CoT for creative writing. When you tell a model to “think step by step” before writing a poem or story, the output often feels mechanical and over-analyzed. Creative tasks benefit from less deliberation, not more. Save CoT for tasks that actually require reasoning.

Common Mistakes with Chain-of-Thought Prompting

After using CoT extensively, these are the patterns that consistently trip people up. Avoid these and your CoT prompts will be substantially more effective.

Mistake 1: Vague reasoning instructions

“Think carefully” is not CoT. Neither is “be thorough.” These are vibes, not instructions. The model needs structural direction: what steps to take, what factors to consider, what order to reason in. Compare “think carefully about this decision” with “evaluate cost, timeline, risk, and team capacity separately, then weigh them against each other.”

Mistake 2: Putting the reasoning trigger before the problem

“Think step by step about the following problem: [problem]” works worse than “[problem]. Think step by step.” The model processes text sequentially. When the reasoning instruction comes first, it has to start reasoning before it knows what the problem is. Always present the full problem first, then ask for step-by-step reasoning.

Mistake 3: Not providing enough context for the reasoning to work with

CoT amplifies what the model knows. If you ask it to reason step by step about a decision but do not provide the relevant data points, constraints, and goals, the model will produce confident-sounding reasoning based on assumptions. Step-by-step garbage is still garbage. Combine CoT with rich context (this is where the COSTAR framework pairs well with CoT).

Mistake 4: Using CoT when you need creativity

Reasoning and creativity use different cognitive modes. When you ask a model to think step by step about writing a tagline, you get analytical output that reads like a committee wrote it. For creative tasks, give context and constraints but let the model generate freely. Use CoT to evaluate the creative output afterward, not to generate it.

Mistake 5: Trusting the reasoning chain without verification

CoT makes reasoning visible, but visible reasoning is not necessarily correct reasoning. Models can produce plausible-sounding logical chains that contain subtle errors, especially with numeric calculations or domain-specific knowledge. Read the steps, not just the conclusion. The value of CoT is that it lets you spot where reasoning went wrong - but only if you actually check.

Mistake 6: Over-specifying the number of steps

“Solve this in exactly 5 steps” forces the model to either pad simple problems or compress complex ones. Some problems need 3 steps. Others need 8. Specify what aspects to reason about, not how many steps to use. Let the problem’s complexity determine the reasoning depth.

Quick Reference Cheatsheet

Use this reference when deciding how to apply CoT to your next prompt.

CoT TypeEffortBest ForKey Phrase
Zero-ShotLow (add one line)Quick tasks, math, general reasoning“Think step by step”
Manual (Few-Shot)Medium (write examples)Repeated tasks, specific reasoning structure“Follow this example...”
Auto-CoTMedium (two prompts)Unfamiliar domains, complex analysis“First, show me how you’d approach...”

CoT Prompt Template

CoT Master Template
CoT Prompt Template - Copy and Customize:

[Describe your problem or question with full context]

Before answering, reason through this step by step:
1. [First aspect to analyze - e.g., "Identify the key constraints"]
2. [Second aspect - e.g., "Evaluate each option against those constraints"]
3. [Third aspect - e.g., "Consider second-order effects and risks"]
4. [Synthesis step - e.g., "Weigh the tradeoffs and recommend a path forward"]

Show your reasoning for each step, then provide your final answer.

Domain-Specific Quick Triggers

DomainEffective CoT Trigger
Code debugging“Trace the execution flow, identify where the actual behavior diverges from expected behavior, then suggest fixes”
Data analysis“Examine each variable independently, then analyze correlations, then draw conclusions supported by the data”
Business strategy“Assess the market factors, internal capabilities, competitive landscape, and financial implications separately before synthesizing a recommendation”
Legal/compliance“Identify the applicable rules, analyze how each applies to this situation, note any ambiguities, then state your assessment”
Architecture decisions“Evaluate the requirements, consider each architectural option against scalability/maintainability/cost, then recommend with tradeoff analysis”

Next Steps

Chain-of-thought prompting is the single most useful technique after learning to write clear, specific prompts. Start with zero-shot CoT on your next complex task. If the reasoning is not structured enough, try manual CoT with a worked example. Once it clicks, you will stop hoping the model figures it out on its own.

To go further, combine CoT with the COSTAR framework for context-rich reasoning prompts, or with prompt chaining to break complex workflows into reasoned steps.

Build reasoning prompts automatically

AskSmarter’s prompt builder asks targeted questions about your task, then constructs prompts with built-in chain-of-thought reasoning. You describe what you need; we structure the thinking process. No prompt engineering knowledge required.

Start building free