How Grover’s algorithm works, step by step

The whole algorithm in plain words: superposition, an oracle that marks the answer, a reflection that boosts it, and a measurement.

9 min read · reviewed December 2026

The problem Grover solves

Suppose you have N possible answers and a checker that can say yes or no to any one of them. You have no clue which answer is correct and no structure to exploit, such as a sorted list. A classical computer has to try candidates one by one. On average it needs about N/2 checks to find a single correct answer, and in the worst case it needs close to N.

Grover’s algorithm, published by Lov Grover in 1996, finds a correct answer with about (π/4)·√N checks. For a million candidates that is roughly 800 checks instead of 500,000. It is a quadratic speedup: the number of steps is the square root of the classical number.

The algorithm never looks inside a list. It only needs a checker that it can run on a superposition of candidates. That checker is called the oracle.

The ingredients

  • n qubits, which give N = 2ⁿ basis states. Each basis state is one candidate answer.
  • An oracle that flips the sign of the amplitude of every correct answer and leaves the others alone.
  • A diffusion step, also called inversion about the mean, that reflects every amplitude about the average amplitude.
  • A measurement at the end that reads the n qubits and returns one candidate.

Step 1: start with every candidate equally likely

All qubits start in |0…0⟩. A Hadamard gate on every qubit turns that into an equal superposition. Every one of the N basis states now has amplitude 1/√N, so each would be measured with probability 1/N.

Nothing has been learned yet. If you measured now you would get a random candidate, exactly like guessing.

Step 2: the oracle marks the answer with a minus sign

The oracle multiplies the amplitude of each correct answer by −1. Look at the Amplitudes view in the lab above after the oracle step: the marked bar drops below zero while all the others stay put.

This is important to understand. A minus sign does not change a probability, because probabilities are squares of amplitudes. If you measured right after the oracle, you would still get every candidate with probability 1/N. The information is stored in the phase, and the next step turns it into a probability.

Step 3: diffusion turns the minus sign into extra probability

Diffusion replaces every amplitude a by 2·mean − a, where mean is the average of all the amplitudes. The marked item’s amplitude is negative, so it sits far below the mean. Reflecting it about the mean sends it far above the mean. Every other amplitude was just a little above the mean, so reflection sends each of them slightly below the mean.

The result is that one amplitude grows and the others shrink. The lab’s mean line shows the reflection directly. In terms of gates, diffusion is H on all qubits, X on all qubits, a multi-controlled Z, X on all qubits, and H on all qubits.

a → 2·mean − a

mean = (sum of all amplitudes) / N

Step 4: repeat the pair about √N times

One oracle plus one diffusion is called a Grover iteration. Each iteration raises the marked amplitude by a roughly fixed amount, so after about (π/4)·√N iterations the marked state holds almost all the probability.

When N is 4 and one item is marked, a single iteration gives exactly probability 1. For larger N the success probability climbs close to 1 but is rarely exactly 1. The lab shows the exact number.

Step 5: measure

Measure all n qubits. With high probability you read the marked item. Because the check is cheap, you can run the checker once classically on the result. If it fails, run the algorithm again.

Do not iterate longer than the recommended number. Grover’s algorithm overshoots: past the best point the success probability falls again. The guide on iteration counts shows this with real numbers.

A worked example with 8 items

Take n = 3, so N = 8, and mark the item 101. The starting amplitude of every item is 1/√8, about 0.354. The oracle makes the marked one −0.354. The mean of all eight amplitudes is (7 × 0.354 − 0.354)/8, about 0.265.

Diffusion sends each amplitude a to 2 × 0.265 − a. The marked item goes to about 0.884 and each of the seven others to about 0.177. The marked probability is 0.884², about 78 percent, after one iteration. A second iteration lifts it to about 94.5 percent, which is the best possible for N = 8. Check both numbers in the success table and in the lab.

Try it

Questions

Does Grover’s algorithm check all items at once?

No. It prepares a superposition of all candidates, but a measurement returns only one. The speedup comes from interference that makes the right answer more likely, not from reading all the results.

Why is the oracle phase flip enough?

Because diffusion compares every amplitude with the average. A negative amplitude lies far from the average, so reflecting it moves it far in the positive direction.

Read next

Sources and further reading