| HowItWorksLab ¡ Systems
English

How a CPU Pipeline Instruction Flow Works

A processor does not finish one instruction before starting the next. Follow the stream as instructions overlap through five stages, one advancing on every tick of the clock.

CPU · PIPELINE INSTRUCTION FLOW each clock cycle pushes every instruction one stage further — so several run at once Instruction stream I1 · I2 · I3 · I4 — in program order one new instruction enters each cycle Fetch get the instruction Decode work out what it does Execute do the operation Memory load or store data Write-back save the result Register file operands in · results out fast on-chip storage the stages read and write Clock one tick advances every stage by one instruction fetch → decode → execute → memory → write-back stage advance register operands / results
The stages, in order Fetch → Decode → Execute → Memory → Write-back
Display mode

Detailed Explanation

What is a CPU pipeline?

A processor has to run a long list of instructions. Doing them strictly one after another wastes most of the chip most of the time, because each step of an instruction uses only a small part of the hardware.

A pipeline solves this by splitting instruction handling into stages and letting different instructions occupy different stages at once. It works like an assembly line: while one instruction is being executed, the next is being decoded and the one after that is being fetched.

Why overlap the stages?

Because each stage then only has to do one small job, so it can be made short and fast. Once all stages are full, a finished instruction rolls off the end on every clock cycle instead of once every five cycles — the same units, simply kept busy on different instructions.

The gain is not free: keeping stages in step needs careful handling, because instructions sometimes depend on each other. Those moments are where stalls and hazards come from.

Components & their role

1. Instructions arrive in program order

A stream of instructions waits to be run. Normally they would be handled one at a time, each finishing fully before the next begins. The pipeline changes that.

2. Fetch gets the next instruction

The fetch stage reads the next instruction from memory. As soon as it hands it on, fetch immediately turns to the one after it.

3. Decode works out what it means

Decode looks at the instruction and determines what operation it is, which registers it needs and where its result should go. Meanwhile fetch is already loading the next one.

4. Execute performs the operation

The execute stage does the arithmetic or logic the instruction calls for, using operands read from the register file. This is the stage that actually produces a value.

5. Memory loads or stores data

If the instruction needs to touch memory, this stage reads or writes it. Instructions that only work on registers simply pass through.

6. Write-back saves the result

Finally the result is written back into the register file, completing the instruction. Because the stages overlap, by now several later instructions are already partway through the pipeline.

What is a CPU pipeline?

It is a way of splitting instruction work into stages so that different instructions occupy different stages at the same time. Instead of finishing one instruction before starting the next, the CPU overlaps them.

What are the classic pipeline stages?

A common set is fetch, decode, execute, memory and write-back. Fetch gets the instruction, decode works out what it means, execute performs the operation, memory loads or stores data, and write-back saves the result.

Why is a pipeline faster?

Each stage does one small job, so it can be short and quick. Once all stages are full, an instruction finishes every clock cycle instead of every five — the same parts, simply kept busy on different instructions.

What is a pipeline stall?

A stall is a pause in the flow. It happens when the next instruction cannot proceed — for example because it needs a result that is not ready yet or must wait on memory. Stalls reduce the ideal overlap.

What is a hazard?

A hazard is a situation where overlapping instructions interfere, such as one instruction needing data another is still computing. Processors handle hazards by stalling, forwarding results early, or reordering instructions.

Does more stages always mean faster?

No. More stages can raise the clock rate, but each one adds overhead, and mispredicted branches cost more to unwind. Real designs balance depth against these penalties.

Common Misconceptions

The CPU finishes one instruction first. The pipeline is imagined running instructions strictly one at a time.
Several instructions overlap. Different instructions sit in different stages, all at the same moment.
The pipeline makes each instruction faster. People assume a single instruction finishes sooner.
It raises the throughput, not the latency. One instruction still takes several cycles; the machine just retires one per cycle.
Stages always run in perfect lockstep. The pipeline is expected to never pause.
Stalls and hazards interrupt it. Dependencies and memory waits can leave bubbles that stall the flow.
Disclaimer: Diagrams are heavily simplified for educational demonstration only. Real-world systems contain far more variables and complexity. Not for engineering production use. Not financial, political or professional advice.