Technology & Computing · Computers & hardware

How processors execute instructions

Follow a tiny calculation through the instructions, memory addresses and circuits that make a computer work.

4 short lessons · about 22 minutes · 4 sources · updated November 2026

What you will learn

  • Distinguish fetching, decoding and executing an instruction.
  • Explain why a processor needs an encoded instruction as well as data.
  • Explain what a processor must keep track of for a sequence of instructions to run at all.
  • Distinguish the address of a memory location from the value stored there.
  • Explain why a program must interpret the bytes it reads.
  • Predict what happens when a program reads bytes under the wrong interpretation.

Lesson 1 of 4 · 6 min

What a processor does with 7 + 5

Before you readA tiny program subtracts 1 from a counter and then jumps back to repeat if the counter isn't zero. Those instructions are stored once and the counter starts at 3. How many times does the processor run the subtract instruction?

Correct.Not quite. The answer is Three times.

It runs three times, though the instruction is stored only once. This lesson shows how a processor keeps track of where it is in a program.

You type 7 + 5 into a calculator and 12 appears. It looks like one act. Inside, the processor did several smaller things in a fixed order, and it does those same few things for every task it's given.

A central processing unit, or CPU, is circuitry that carries out encoded instructions one after another. The processor described here is deliberately simple. Real chips overlap and reorder their work, but they have to produce the same results as the simple version.

Each instruction goes through three stages. Fetch gets the next instruction from memory. Decode works out which operation the instruction asks for and where its inputs are. Execute performs that operation, such as adding two values.

Then the cycle starts again with the next instruction. These are stages of one instruction cycle. They aren't three separate parts of the computer taking turns.

Take the sum. Say one instruction means "add these two values." Fetch brings that instruction in from memory. Decode recognizes it as an addition. Execute produces 12. A further instruction then stores the result where later work can find it.

Two parts of the chip share the work. The arithmetic and logic unit does the calculations and comparisons, and control circuitry coordinates the rest. Neither knows why you wanted the answer.

Check yourselfA processor already has an instruction and is working out which operation it asks for. Which stage of the instruction cycle is that?

Correct.Not quite. The answer is Decoding the instruction.

Decoding works out what the instruction means. Fetching is the earlier step that got the instruction from memory, and executing is the later step that performs the operation.

Inside the machine, an instruction and a piece of data look alike. Both are stored as bits, the ones and zeros a computer keeps. Which role a pattern plays depends on how the system uses it.

So the number 7 sitting in memory doesn't ask for anything. The processor also needs an operation and a way to find the values involved. Data supplies the ingredients, and an instruction says what to do with them.

Try to recallA memory location holds the value 12. Why isn't that enough to tell the CPU what to do?

The value is data. The CPU also needs an instruction that specifies an operation, such as add or compare, and says how to find its inputs or where the result goes.

Look again at the first stage. Fetch gets the next instruction, and the word "next" hides a requirement. The processor has to know where that instruction is.

It keeps the address in a small store called the instruction pointer. After each fetch, the pointer moves on to the following instruction. Without it, the machine would fetch the same instruction forever.

That one stored address is where a program's shape comes from. Normally the pointer steps forward, so instructions run in the order they're stored. But an instruction can also write a new address into the pointer.

Set the pointer back to an earlier address, and a section of the program repeats. Set it to one of two addresses, depending on a comparison, and the program takes one of two paths. The cycle never changes. It's still fetch, decode, execute.

Say a tiny program sits at three addresses. At address 10, subtract 1 from a counter. At address 11, if the counter isn't zero, set the pointer back to 10. At address 12, stop.

Start the counter at 3. The processor runs address 10 three times, though that instruction is stored only once. Each time, the instruction at 11 sends the pointer back. When the counter reaches zero, the pointer moves on to 12.

Real chips work on several instructions at once, so read "next" as the order of effects. It doesn't describe what each circuit is doing at a given instant.

Check yourselfIn a simple fetch, decode and execute model of a processor, how can a program run the same section of instructions more than once?

Correct.Not quite. The answer is By setting the address of the next fetch back to an earlier instruction.

An instruction can write a new address into the instruction pointer, and the next fetch goes wherever it points. Point it back at an earlier address and that section runs again. So a loop is stored only once, with no extra copies and no second processor.

Lessons in this topic

  1. What a processor does with 7 + 5

    Follow one small sum through fetch, decode and execute, then see how a single stored address lets a program repeat itself or choose a path.

    Essentials · 6 min

  2. Why a memory address isn't the value stored there

    Tell a value from the address where it's kept, then see why the same stored numbers can be read as text, as a color or as nonsense.

    Essentials · 5 min

  3. Four small steps behind one running total

    Follow a running total through read, add and store, see where the recipe comparison fails and learn to read a wrong result as a clue to the step that went wrong.

    Deeper · 6 min

  4. From typed text to machine code

    Follow a program from human-readable source through the compiler's four stages to the bit patterns a processor executes.

    Deeper · 5 min

Three quick stories from this topic

HI! is different from HI!

In C, typing HI! twice and comparing the two with == reports that they're different

The == test compares where each piece of text is stored, and the two copies sit at different addresses. Harvard's CS50 course uses the example to show that a memory address and the value kept there are separate things.

Think of numbered lockers

The number on the door identifies the locker, and the object inside is its contents. Two lockers can hold identical objects and still be different lockers.

Comparing the contents

To compare the letters themselves, a C programmer calls a function named strcmp, which looks at the characters stored at each address.

HI! or a shade of yellow

The three numbers that spell HI! in a text message are also a shade of yellow

A computer stores the characters H, I and ! as the numbers 72, 73 and 33. Hand the same three numbers to image software and it reads them as amounts of red, green and blue. Stored numbers don't say what they mean. The program reading them decides.

Bytes carry no label

A place in memory holds numbers and nothing else. Nothing stored there says whether they're text, part of a picture or an instruction.

Why software needs shared rules

Programs agree on standard codes, such as the one that maps 72 to the letter H. Read with the wrong rules, perfectly good bytes turn into nonsense.

One address set back

A processor repeats part of a program by setting one stored address back

The processor keeps the address of its next instruction in an instruction pointer, which normally steps forward. An instruction can write a new address there. Send the pointer back and a section runs again, so a loop is stored only once however many times it runs.

Fetch needs an address

In the simplified cycle, fetching gets the next instruction from memory, and the pointer supplies its location. Once the current instruction has been carried out, the next one moves into the instruction register, and the pointer indicates the one after that.

An address doesn't say what the instruction does

Knowing where the next instruction is says nothing about what it does. It still has to be decoded and executed. In IBM's simplified model of the cycle, a clock keeps time, and its pulses coordinate the circuitry at a rate called the clock speed, measured in hertz.

Sources

This topic is part of What happens behind the screen, a guided path through related topics.

  • Why adding cores stops helping

    A fixed job has a part that won't split, and that part sets a ceiling no number of processors can lift.

    4 lessons · 24 min

  • Binary, bits and bytes

    Everything a computer holds is a pattern of on and off. Learn to count in binary, see what bits and bytes are, and find out why one pattern can be a number, a letter or a shade.

    4 lessons · 16 min

  • The parts of a computer

    Open up a laptop or a phone and name what you find. See what the processor, memory, storage and the input and output parts each do, and how they work together when you open a file.

    4 lessons · 16 min

  • Searching a million items

    See why a sorted list of a million items takes about 20 checks to search, when sorting first is worth the effort, and how a hash table skips the search altogether.

    4 lessons · 17 min

  • How the internet works

    The internet is tens of thousands of separate networks that agree to carry each other's traffic. See how data is cut into packets, how routers pass them along, and how they're put back together.

    4 lessons · 16 min

  • How a database keeps records consistent

    See how transactions, built-in rules and isolation levels keep records right when a server crashes, two buyers want one seat or two updates collide.

    4 lessons · 17 min

All technology & computing topics · Take the quiz