Interference: why H, Z, H flips a bit

Two Hadamards with a phase flip between them turn |0⟩ into |1⟩. Probabilities cannot explain this, but amplitudes can.

Beginner · 1 qubit · 3 gates · 0 two-qubit · depth 3 · reviewed November 2026

Open in the Circuit Builder

What is happening

The first Hadamard splits |0⟩ into two equal paths. The Z gate flips the sign of the |1⟩ path, which changes no probabilities. The second Hadamard recombines the paths, and because of the sign change the |0⟩ contributions cancel while the |1⟩ contributions add.

Quantum algorithms are built from exactly this idea: arrange the phases so that wrong answers cancel and the right answer reinforces.

Step by step

  1. 1. H

    State becomes (|0⟩ + |1⟩)/√2.

  2. 2. Z

    State becomes (|0⟩ − |1⟩)/√2. Probabilities are still 50/50, but the relative phase is now −1.

  3. 3. H

    The two paths to |0⟩ have opposite signs and cancel. The paths to |1⟩ add up. The result is |1⟩ with probability 100%.

Expected result

Final state |1⟩ with 100% probability. Remove the Z and the result is |0⟩ with certainty instead.

Qubit 0 is the leftmost bit. In Qiskit, bitstrings are printed in the reverse order.

Qiskit code

from qiskit import QuantumCircuit
from math import pi

qc = QuantumCircuit(1, 1)
qc.h(0)
qc.barrier()
qc.z(0)
qc.barrier()
qc.h(0)
qc.barrier()
qc.measure(0, 0)

# Qiskit prints bit strings with qubit 0 on the RIGHT; this site writes qubit 0 on the LEFT.

Try this

  • Delete the Z gate and compare.
  • Swap Z for S then S again. Is the result the same as Z?
  • Use the step slider to watch the phase appear in the state vector table.

Gates used

Related reading

Questions

Why does a gate that changes no probabilities matter?

Because later gates can convert phase differences into probability differences. Phase is where much of a quantum algorithm’s power comes from.