Level 2 · Core Principles

Quantum Gates

About 5,486 words · roughly 25 minute read · sources checked December 2, 2026

Quantum gates are the instructions of a quantum computer. A classical program is a sequence of logic operations on bits. A quantum program is a sequence of gates on qubits. Each gate is a reversible, norm-preserving transformation of the joint state, and a circuit is the list of gates in order. Everything that a quantum computer can compute, in the standard model, is a circuit.

This lesson covers the gate set you will meet in every textbook and every software toolkit, and it keeps the arithmetic honest. You will see the matrix of each gate, what it does on the Bloch sphere, how to multiply a circuit out, why a small set of gates is enough to build any operation, and what those gates cost. Along the way we verify standard identities such as H X H = Z, CZ = (I ⊗ H) CNOT (I ⊗ H) and SWAP from three CNOTs, and decompose the Toffoli gate into 6 CNOTs, 2 Hadamards and 7 T-type gates.

You need the Level 0 lessons on linear algebra and tensor products. Superposition and entanglement from the first two lessons of this level give the motivation.

What you will learn

  • Why gates are unitary matrices and what that implies (reversibility, norm preservation).
  • The matrices and geometric meaning of I, X, Y, Z, H, S, T and the rotation gates.
  • Useful identities for rewriting circuits, with verification.
  • CNOT, CZ, SWAP and controlled gates; the Toffoli gate.
  • How to read a circuit diagram and compute its matrix in the right order.
  • What universality means, and the Barenco and Solovay–Kitaev results.
  • Gate counts, T-count and why they matter for fault tolerance.
  • What a native gate set is and why compilers translate.

Helpful first: Multi-Qubit Systems & Tensor Products, Superposition, Entanglement.

What a quantum gate is

A quantum gate on n qubits is a 2ⁿ × 2ⁿ complex matrix U that maps a state vector |ψ⟩ to U|ψ⟩. For the evolution to be physically valid and to keep probabilities summing to 1, U must be unitary, which means U†U = I, where U† is the conjugate transpose. Two consequences follow directly.

  • Reversibility: U⁻¹ = U†, so every gate can be undone by another gate. No information is lost until you measure.
  • Norm preservation: ‖U|ψ⟩‖ = ‖|ψ⟩‖ = 1, so a valid state remains a valid state. Lengths and angles between states are unchanged, which is why gates act as rotations.

Unitarity is much stricter than it looks. A classical gate such as AND is not reversible and has no unitary version without extra bits. Quantum gates are, in that sense, closer to rotations of a high-dimensional space than to logic gates.

Worked example

Checking that a matrix is unitary

  1. Take the Hadamard matrix H = (1/√2)[[1, 1], [1, −1]]. It is real and symmetric, so H† = H.
  2. H² = (1/2)[[1+1, 1−1], [1−1, 1+1]] = [[1, 0], [0, 1]] = I. So H†H = I and H is unitary. It is also its own inverse.
  3. Now take M = [[1, 1], [0, 1]]. M†M = [[1, 0], [1, 1]]·[[1, 1], [0, 1]] = [[1, 1], [1, 2]], which is not I. So M is not a valid gate. It would not preserve the length of a vector, for example it takes (0, 1) to (1, 1) of length √2.

Circuit model in one sentence

A quantum program is: prepare |0…0⟩, apply a sequence of unitary gates, then measure. The whole circuit is itself a single unitary matrix, the product of all its gates.

The single-qubit gates

Single-qubit gates are 2 × 2 unitary matrices and can be pictured as rotations of the Bloch sphere. The table lists the ones used everywhere.

GateMatrixAction on the Bloch sphereEffect on basis states
I[[1, 0], [0, 1]]no change|0⟩ → |0⟩, |1⟩ → |1⟩
X[[0, 1], [1, 0]]180° about x|0⟩ ↔ |1⟩ (quantum NOT)
Y[[0, −i], [i, 0]]180° about y|0⟩ → i|1⟩, |1⟩ → −i|0⟩
Z[[1, 0], [0, −1]]180° about z|1⟩ → −|1⟩ (phase flip)
H(1/√2)[[1, 1], [1, −1]]180° about the (x+z) axis|0⟩ → |+⟩, |1⟩ → |−⟩
S[[1, 0], [0, i]]90° about z|1⟩ → i|1⟩
T[[1, 0], [0, e^(iπ/4)]]45° about z|1⟩ → e^(iπ/4)|1⟩

The standard single-qubit gates. S is called the phase gate and T the π/8 gate.

The Pauli gates X, Y, Z square to the identity, anticommute with each other (XZ = −ZX), and satisfy Y = iXZ. The phase gates are successive square roots of Z: S² = Z and T² = S. So T is a rotation by only 45° about the z axis, which matters later because it is the hard gate for fault-tolerant machines.

Rotation gates

Every single-qubit gate is a rotation about some axis by some angle, up to a global phase. The three basic families rotate about the coordinate axes:

Rz(θ) = [[e^(−iθ/2), 0], [0, e^(iθ/2)]],   Rx(θ) = e^(−iθX/2),   Ry(θ) = e^(−iθY/2)
Rotation gates by angle θ about z, x and y.

Up to a global phase, Rz(π) = Z, Rz(π/2) = S and Rz(π/4) = T. For example T = e^(iπ/8)·Rz(π/4), and the factor e^(iπ/8) has no physical effect. Any single-qubit gate can be written as Rz(α)·Ry(β)·Rz(γ), the Euler decomposition, so three rotation angles suffice.

Worked example

What H does to the sphere

  1. H maps |0⟩ (north pole) to |+⟩ (+x on the equator) and |1⟩ (south) to |−⟩ (−x). It maps +y to −y and leaves the point halfway between +x and +z fixed.
  2. That is a 180° rotation about the axis through (x + z)/√2. Equivalently, H swaps the roles of the x and z axes.
  3. Because H swaps the X and Z axes, it converts a Z-basis measurement into an X-basis one and the other way round.
  4. Applying H twice is a 360° rotation about the same axis, which is the identity: H² = I.

Run this circuit

X gate: the quantum NOT

q0X

Bit order: q0 is the rightmost digit of each result, as in Qiskit. All qubits start in |0⟩ unless marked. This is an ideal simulator with no hardware noise.

Predict first: X swaps |0⟩ and |1⟩. What do you expect to read out?

Press Run to simulate. Results appear here with a short explanation.

Run this circuit

RY(π/3): rotating the Bloch vector

q0RY1.05

Bit order: q0 is the rightmost digit of each result, as in Qiskit. All qubits start in |0⟩ unless marked. This is an ideal simulator with no hardware noise.

Predict first: RY(θ) rotates the Bloch vector by θ about the y axis. For θ = π/3 (60°), P(1) = sin²(θ/2). Estimate it.

Press Run to simulate. Results appear here with a short explanation.

Identities you will use every day

A handful of identities let you simplify circuits and change which gate is native. Each of these was checked by multiplying out the matrices.

IdentityMeaning
H X H = Z and H Z H = XConjugation by H swaps the X and Z axes.
H Y H = −YH flips the y axis.
S² = Z, T² = S, T⁴ = ZThe phase gates are roots of Z.
X² = Y² = Z² = H² = IThese gates are their own inverses.
Y = i X ZY is built from X and Z up to a phase.
H Z H = X so Rx(θ) = H Rz(θ) HAn x-rotation is a z-rotation sandwiched by Hadamards.

Single-qubit identities.

Worked example

Proving H X H = Z by multiplication

  1. H X = (1/√2)[[1, 1], [1, −1]]·[[0, 1], [1, 0]] = (1/√2)[[1, 1], [−1, 1]].
  2. Then (H X) H = (1/2)[[1, 1], [−1, 1]]·[[1, 1], [1, −1]] = (1/2)[[2, 0], [0, −2]] = [[1, 0], [0, −1]] = Z. ✓.
  3. Geometrically: H swaps x and z, so a 180° rotation about x, seen through the swap, becomes a 180° rotation about z.
  4. Practical use: if hardware can only do Z rotations cheaply, as superconducting devices often can by shifting the phase of later pulses, then X rotations cost two extra Hadamards.

These identities are also how compilers shorten circuits. A run of single-qubit gates on one qubit can always be merged into one matrix, then converted into at most three rotations. A circuit with long chains of single-qubit gates is therefore cheaper than it looks on paper, while the two-qubit gates between them cannot be merged away.

Run this circuit

CZ sandwiched by H equals CNOT

q0q1XHH

Bit order: q0 is the rightmost digit of each result, as in Qiskit. All qubits start in |0⟩ unless marked. This is an ideal simulator with no hardware noise.

Predict first: Qubit 0 is set to 1. Wrapping CZ in Hadamards on the target should behave like a CNOT. What is the final string?

Press Run to simulate. Results appear here with a short explanation.

Two-qubit gates: CNOT, CZ and SWAP

Single-qubit gates alone cannot create entanglement. To do that, and to make qubits interact in any useful way, you need gates that act on two qubits at once. The most important is the controlled-NOT, CNOT, also written CX.

CNOT = [[1,0,0,0],[0,1,0,0],[0,0,0,1],[0,0,1,0]]
In the basis order |00⟩, |01⟩, |10⟩, |11⟩ with the first qubit as control.
controltargetinputoutput00→0001→0110→1111→10Target flips only when control = 1. First bit is the control.
The CNOT gate in circuit form, with its truth table. The control (dot) is unchanged; the target (⊕) flips when the control is 1.

CNOT permutes the computational basis states, so on basis inputs it is exactly the classical XOR gate. The quantum behaviour appears on superpositions, as the Bell-state circuit showed: acting on (|0⟩ + |1⟩)|0⟩ it produces an entangled state.

CZ and SWAP

  • CZ applies a Z to the target when the control is 1. Its matrix is diag(1, 1, 1, −1). It is symmetric in the two qubits: it just flips the sign of |11⟩.
  • SWAP exchanges the states of the two qubits: |01⟩ ↔ |10⟩. It is not an entangling gate by itself, yet it is vital for moving information around on chips with limited connectivity.

Worked example

CZ from CNOT, and SWAP from three CNOTs

  1. Conjugating the target of a CNOT by Hadamards gives CZ: (I ⊗ H)·CNOT·(I ⊗ H) = CZ. Reason: H X H = Z, so the controlled flip becomes a controlled phase flip.
  2. SWAP is three CNOTs with alternating control and target: CNOT₁₂ · CNOT₂₁ · CNOT₁₂ = SWAP, where CNOT₂₁ means qubit 2 controls qubit 1. Check on |01⟩: the first CNOT leaves it at |01⟩, the second (qubit 2 controls) gives |11⟩, the third gives |10⟩. ✓
  3. So a SWAP costs three entangling gates, which is expensive. If two qubits that must interact are not directly connected on the chip, each SWAP adds about three CNOTs to the error budget.
  4. I verified both identities numerically with the full 4 × 4 matrices.

Controlled gates in general

Any single-qubit gate U can be made conditional: controlled-U applies U to the target when the control is 1 and does nothing otherwise. Its matrix is block diagonal, with I in the first block and U in the second. CNOT is controlled-X and CZ is controlled-Z. Controlled-U gates with arbitrary U are central to algorithms such as phase estimation. A control may also be placed on two or more qubits, as in the Toffoli gate below.

Phase kickback

When the target of a controlled-U is in an eigenstate of U with eigenvalue e^(iφ), the control qubit picks up the phase e^(iφ) while the target is unchanged. This ‘kickback’ is how phase information is moved from a target register onto a control qubit, and it underlies phase estimation and Shor’s algorithm.

Reading a circuit and multiplying it out

A circuit diagram has one horizontal line per qubit, with time running from left to right. Gates are boxes or symbols placed on the lines. Two rules prevent most mistakes.

  1. Time flows left to right in the diagram, but matrices are applied right to left. A circuit that applies A first, then B, then C has the matrix C·B·A, acting on |ψ⟩ as C(B(A|ψ⟩)).
  2. Gates on different qubits in the same column act in parallel, and combine with the tensor product. Two single-qubit gates A on qubit 1 and B on qubit 2 together are A ⊗ B.

Worked example

The Bell circuit as one matrix

  1. The circuit is H on qubit 1, then CNOT with qubit 1 as the control. Its matrix is CNOT · (H ⊗ I).
  2. (H ⊗ I) acts first. Multiplying out gives the 4 × 4 matrix (1/√2) times [[1, 0, 1, 0], [0, 1, 0, 1], [0, 1, 0, −1], [1, 0, −1, 0]].
  3. Applying it to |00⟩ picks out the first column, (1/√2)(1, 0, 0, 1)ᵀ. That is (|00⟩ + |11⟩)/√2 = Φ⁺.
  4. Applying the same matrix to |01⟩, |10⟩ and |11⟩ gives the other three Bell states up to signs: the circuit turns the computational basis into the Bell basis. In reverse, it can be used to measure in the Bell basis, which is the first step of teleportation.

Worked example

Order matters

  1. Compare H then S with S then H, both applied to |0⟩.
  2. H then S: H|0⟩ = |+⟩ = (|0⟩ + |1⟩)/√2, then S gives (|0⟩ + i|1⟩)/√2 = |+i⟩.
  3. S then H: S|0⟩ = |0⟩ (S does nothing to |0⟩), then H gives |+⟩.
  4. The results differ, |+i⟩ versus |+⟩, so the two gates do not commute. In matrix form HS ≠ SH. Rearranging gates is only allowed when they provably commute, for example gates on different qubits.

Measurement is drawn as a meter symbol. After it, a qubit line may continue as a classical wire (a double line). Classical control, where later gates depend on earlier measurement results, is needed for teleportation and error correction. For the layout conventions used by common software, see the Level 6 lesson on reading circuit diagrams.

Depth and width

The width of a circuit is the number of qubits. The depth is the number of time steps, counting gates that can run in parallel as one step. Depth matters because each time step lets decoherence act. A circuit with 1,000 gates and depth 20 is far friendlier to real hardware than one with 1,000 gates in sequence.

Universality: a few gates are enough

A computer would not be practical if it needed a separate physical operation for every possible unitary. Fortunately a small set of gates is universal, meaning any desired operation can be built from it.

Any unitary on n qubitswhat an algorithm needsSingle-qubit rotations + CNOTexact universality (Barenco et al., 1995)Finite set {H, S, T, CNOT}approximate; Solovay–Kitaev: length polylog(1/ε)Native hardware gatescalibrated pulses; compiler translatesbuilds
From a small physical gate set to arbitrary computations. Exact universality needs single-qubit rotations plus CNOT. A finite gate set gives approximate universality, with efficient compilation.

Barenco and nine co-authors proved the key exact result in their 1995 paper ‘Elementary gates for quantum computation’. Their abstract states that all one-bit gates together with the two-bit exclusive-or gate (CNOT) are universal: any unitary operation on n bits can be written as a composition of these gates. In practice that means arbitrary single-qubit rotations plus one entangling gate.

There is a catch. Arbitrary rotations form a continuous family, and a real device can only implement a finite menu with finite accuracy. The Solovay–Kitaev theorem says that a finite set of gates that generates a dense set of rotations can approximate any single-qubit gate to accuracy ε with a sequence whose length grows only polylogarithmically in 1/ε. In Dawson and Nielsen’s pedagogical review, the output sequence has length O(log^3.97(1/ε)), and the compiling algorithm itself runs in polylogarithmic time. Later work has improved the exponent substantially, though I did not open those papers.

Worked example

What polylogarithmic means in practice

  1. Doubling the number of digits of accuracy does not double the cost. It multiplies it by a modest factor. Take the Dawson–Nielsen scaling as log^k(1/ε) with k ≈ 4 and compare two accuracies, ignoring constants.
  2. For ε = 10⁻³, log₁₀(1/ε) = 3, and 3⁴ = 81.
  3. For ε = 10⁻⁶, log₁₀(1/ε) = 6, and 6⁴ = 1,296. That is 16 times as many gates for 1,000 times better accuracy.
  4. So accuracy is cheap in this sense. The real cost is that each gate in the sequence, if it is a T gate, is expensive under error correction, as the next sections explain.

Exact versus approximate

Exact universality needs a continuum of rotation angles. A finite gate set such as {H, T, CNOT} is approximately universal. For any target and any accuracy, you can find a circuit from the finite set that is within ε of the target, but you generally cannot hit it exactly.

A full decomposition: the Toffoli gate

The Toffoli gate, or controlled-controlled-NOT, flips a target qubit when both of two control qubits are 1. It is the reversible version of AND and is used in arithmetic circuits. It is a three-qubit gate, so it must be compiled into one- and two-qubit gates before it runs on hardware.

A standard decomposition uses 6 CNOT gates, 2 Hadamard gates, and 7 gates of type T or T† (the inverse of T), for 15 gates in total. With controls c₁ and c₂ and target t, the sequence in time order is:

  1. H on t
  2. CNOT (c₂ → t)
  3. T† on t
  4. CNOT (c₁ → t)
  5. T on t
  6. CNOT (c₂ → t)
  7. T† on t
  8. CNOT (c₁ → t)
  9. T on c₂, and T on t
  10. H on t
  11. CNOT (c₁ → c₂)
  12. T on c₁, and T† on c₂
  13. CNOT (c₁ → c₂)

Worked example

Gate count

  1. CNOT gates: steps 2, 4, 6, 8, 11, 13, which is 6.
  2. Hadamards: steps 1 and 10, which is 2.
  3. T-type gates: T† (step 3), T (step 5), T† (step 7), T (step 9, on c₂), T (step 9, on t), T (step 12, on c₁) and T† (step 12, on c₂), which is 7.
  4. The T-count is 7 and the CNOT-count is 6. I verified that this sequence multiplies out to the exact 8 × 8 Toffoli permutation matrix, including all phases.
  5. The two-qubit cost matters because CNOT error rates are higher than single-qubit error rates, and the T-count matters under error correction, as explained next.

The same gate with a different counting convention gives different totals, for example by merging single-qubit gates. When someone quotes a gate count, ask which gates were counted and in what gate set.

Run this circuit

Toffoli (CCX) with both controls set

q0q1q2XX

Bit order: q0 is the rightmost digit of each result, as in Qiskit. All qubits start in |0⟩ unless marked. This is an ideal simulator with no hardware noise.

Predict first: X on qubits 0 and 1 sets both controls to 1. What does the Toffoli do to qubit 2?

Press Run to simulate. Results appear here with a short explanation.

Clifford gates, T gates and why T is expensive

The Clifford group is generated by H, S and CNOT. Clifford circuits map Pauli operators to Pauli operators, which makes them easy to analyse. They can create any of the stabiliser states, including Bell and GHZ states. The Gottesman–Knill theorem says that Clifford circuits, even with many qubits, can be simulated efficiently on a classical computer. So Clifford gates alone are not enough for a quantum advantage.

Adding the T gate to the Clifford set gives {H, S, CNOT, T}, called Clifford+T, which is universal (approximately). T is the gate that supplies the extra, hard-to-simulate power.

Gate familyExamplesClassical simulationFault-tolerant cost
PauliX, Y, ZTrivialCheap, can be tracked in software
CliffordH, S, CNOT, CZEfficient (Gottesman–Knill)Relatively cheap: ‘transversal’ in many codes
Non-CliffordT, Toffoli, arbitrary rotationsCost grows with the number of such gatesExpensive: needs magic-state distillation or equivalent

Why T gates dominate the cost of fault-tolerant algorithms.

In many error-correcting codes, Clifford gates can be applied in a fault-tolerant way fairly directly, but the T gate cannot. The usual remedy prepares special ancilla states called magic states, purifies them with a process called distillation that consumes many noisy copies to make a few good ones, and then uses them to apply a T gate by teleportation. The consequence is that resource estimates for fault-tolerant algorithms are often quoted in T-count, because that count dominates the number of physical qubits and the running time.

Worked example

Why T-count dominates

  1. Suppose a fault-tolerant machine performs a logical Clifford gate in time t_C and each T gate takes about 10 t_C, including distillation overhead. (These factors are illustrative, since real values depend on the architecture.)
  2. An algorithm with 10⁶ Clifford gates and 10⁶ T gates then takes about 10⁶ t_C for Cliffords and 10⁷ t_C for T gates. The T gates account for over 90% of the running time.
  3. Reducing the T-count of a subroutine by half therefore cuts the total time by about 45%, while halving the Clifford count cuts it by only about 4.5%.
  4. That is why quantum compilers and algorithm designers spend so much effort minimising T-count and T-depth.

A controlled gate at work: phase kickback with numbers

Controlled gates have an effect that has no classical counterpart. When the target is in an eigenstate of the gate being applied, the target does not change, but the control picks up a phase. This is phase kickback, and it is worth working through once with explicit numbers because it is the basis of phase estimation, of Shor’s algorithm, and of the Deutsch oracle in the previous lesson.

Worked example

Controlled-S on |+⟩|1⟩

  1. The S gate has eigenstate |1⟩ with eigenvalue i, since S|1⟩ = i|1⟩. Take a control qubit in |+⟩ and a target in |1⟩.
  2. Controlled-S does nothing when the control is 0 and applies S to the target when the control is 1. So (|0⟩|1⟩ + |1⟩|1⟩)/√2 becomes (|0⟩|1⟩ + i|1⟩|1⟩)/√2.
  3. Factor out the target: ((|0⟩ + i|1⟩)/√2) ⊗ |1⟩ = |+i⟩ ⊗ |1⟩. The target is untouched, and the control has moved from |+⟩ to |+i⟩, a 90° turn about the z axis of its Bloch sphere. I confirmed this with the 4 × 4 matrix diag(1, 1, 1, i).
  4. With a T gate instead of S the phase would be e^(iπ/4), a 45° turn. In general a controlled gate whose target eigenvalue is e^(iφ) turns the control by φ about z.
  5. So the phase of the operation has been moved from the ‘gate’ to the ‘control’, where Hadamards and measurement can read it.

The idea scales. Controlled gates with eigenphases e^(iφ), controlled-U², controlled-U⁴, and so on, each kick back a different multiple of φ onto a different control qubit. The control register then holds the binary digits of φ, which an inverse Fourier transform reads out. That is phase estimation, and it is the core subroutine of Shor’s algorithm and of many chemistry algorithms.

Run this circuit

Phase kickback

q0q1XHHHH

Bit order: q0 is the rightmost digit of each result, as in Qiskit. All qubits start in |0⟩ unless marked. This is an ideal simulator with no hardware noise.

Predict first: Qubit 1 is prepared in |−⟩ and used as the target of a CNOT. The target is untouched by a CNOT on |−⟩ (it only gets a sign). Which qubit changes?

Press Run to simulate. Results appear here with a short explanation.

How a gate becomes a pulse

A gate in a diagram is a rotation. In hardware, a rotation is produced by a control pulse whose amplitude, duration, frequency and phase are chosen to implement the required unitary. The mapping from gate to pulse is the job of the lowest layer of the software stack.

  • A single-qubit rotation about an axis in the x–y plane is a resonant pulse. The pulse phase selects the axis, and the area under the pulse envelope (amplitude times duration) selects the angle.
  • A rotation about z can often be done in software. Instead of a pulse, the controller shifts the reference phase for all later pulses on that qubit, which costs no time and adds essentially no error. For this reason Z-type gates, including S and T on many superconducting platforms, are very cheap at the hardware level.
  • A two-qubit gate needs a controlled interaction between two qubits, for example by tuning two superconducting qubits briefly into resonance, by driving a shared mode of motion in an ion chain, or by exciting neighbouring neutral atoms into highly excited Rydberg states. These are the slowest and noisiest operations, and a large part of hardware research goes into improving them.

Worked example

Gate time and error together

  1. Suppose a single-qubit gate lasts 25 ns and a two-qubit gate lasts 100 ns on some device, and the qubit has T1 = 100 µs. (All three numbers are illustrative.)
  2. While the two-qubit gate runs, energy decay alone costs about 100 ns / 100 µs = 0.1% of the excited-state population, since 100 ns ÷ 100,000 ns = 0.001. So even a perfect pulse has a floor of about 0.1% (decay on the qubit that is in |1⟩).
  3. If the other qubit also decays, the loss is roughly twice that. This is one of several contributions to the two-qubit error rate, along with control errors and leakage.
  4. Halving the gate time would halve this particular contribution. That is why faster gates are attractive, and why it matters that very fast pulses risk leakage into other levels, as in the transmon example of the previous level.

The practical point for a programmer is that the quality of a gate is a property of the calibration, not just the hardware. The same chip can have noticeably different error rates from one day to the next, so providers calibrate regularly and publish error data for each device. When you run a circuit on cloud hardware, check these calibration numbers for the particular qubits your circuit was mapped to.

Parameterised gates and variational circuits

Not all circuits are fixed in advance. Many near-term algorithms use gates with adjustable angles, such as Ry(θ) and Rz(φ), arranged in a fixed pattern with entangling gates between layers. A classical optimiser runs the circuit, measures an expectation value, updates the angles, and repeats. These are called variational or hybrid quantum–classical algorithms, and the circuit is called an ansatz.

The reason rotation gates are the natural building block is that they are smooth in their angle. The expectation value of any observable after a rotation by θ is a trigonometric function of θ, namely a combination of cos θ and sin θ, so the optimiser sees a well-behaved landscape. For example, measuring Z after Ry(θ)|0⟩ gives ⟨Z⟩ = cos θ.

Worked example

A one-parameter circuit

  1. Prepare |0⟩, apply Ry(θ), measure Z. The state is cos(θ/2)|0⟩ + sin(θ/2)|1⟩, so ⟨Z⟩ = cos²(θ/2) − sin²(θ/2) = cos θ.
  2. If the target is to make ⟨Z⟩ as small as possible, the minimum is −1 at θ = π, where the state is |1⟩.
  3. The optimiser can also estimate the slope exactly by running the circuit twice, at θ + π/2 and θ − π/2. The slope of cos θ is −sin θ = (cos(θ + π/2) − cos(θ − π/2))/2, which equals (−sin θ − sin θ)/2 = −sin θ. ✓ This is the parameter-shift rule for such gates.
  4. On hardware each evaluation is a statistical estimate, so the optimiser needs many shots per point. Noise and the ‘flat landscape’ problem on larger circuits remain open difficulties.

Native gates and compilation

The gates in a textbook, such as H, CNOT and T, are an abstraction. A physical device implements a specific native gate set, which are the operations the hardware can do directly with calibrated pulses. Everything else is compiled into the native gates. Native sets differ by platform and often by vendor. As typical examples, superconducting devices commonly offer single-qubit rotations (with Z rotations done virtually by changing the phase of later pulses) and one native two-qubit gate of the CZ or CNOT family, while trapped-ion devices commonly offer single-qubit rotations and an entangling gate from the Mølmer–Sørensen family. Check the documentation of the specific device, because these details change.

A compiler, also called a transpiler, performs several jobs.

  • Decompose: rewrite each gate in terms of native gates, such as a Toffoli into CNOTs and single-qubit rotations.
  • Map: assign logical circuit qubits to physical qubits so that two-qubit gates fall on connected pairs.
  • Route: insert SWAPs, each about three CNOTs, when a needed pair is not directly connected.
  • Optimise: merge single-qubit gates, cancel adjacent gates that undo each other, and reduce depth.

Worked example

The cost of poor connectivity

  1. Suppose a 5-qubit device has qubits in a line 0–1–2–3–4 and your circuit needs a CNOT between qubit 0 and qubit 3.
  2. Move qubit 0’s state next to qubit 3 with SWAPs: 0↔1, then 1↔2. That is 2 SWAPs, or about 6 CNOTs, before the CNOT you wanted. You may need further SWAPs afterwards to restore the layout.
  3. If each CNOT has an error of 0.5%, 7 CNOTs have a combined survival probability of about (0.995)⁷ ≈ 0.966, a loss of about 3.4% for this one logical gate.
  4. On a device with all-to-all connectivity, such as many trapped-ion machines, no SWAPs are needed. This is a real architectural advantage, which is traded against slower gates.

Because of this, the same circuit may have very different depth and error on different devices. Software toolkits report the circuit after compilation, and benchmarks that compare devices must count compiled gates, not circuit-diagram gates.

Gate counts and the error budget

Every gate has some error, and the errors add up. A first estimate of the success probability of a circuit with n₁ single-qubit gates at error ε₁, n₂ two-qubit gates at error ε₂, and m measurements at error ε_m is

P_success ≈ (1 − ε₁)^n₁ · (1 − ε₂)^n₂ · (1 − ε_m)^m ≈ exp(−(n₁ε₁ + n₂ε₂ + mε_m))
A crude estimate that treats errors as independent and ignores idle errors.

Worked example

Will the Bell circuit survive? What about a bigger one?

  1. A Bell-pair circuit has 1 Hadamard, 1 CNOT and 2 measurements. Take ε₁ = 0.0003, ε₂ = 0.005 and ε_m = 0.01 (round illustrative values).
  2. Exponent: 1 × 0.0003 + 1 × 0.005 + 2 × 0.01 = 0.0253. So P_success ≈ e^(−0.0253) ≈ 0.975.
  3. Now take a circuit with 500 single-qubit gates, 300 CNOTs and 20 measurements. Exponent: 500 × 0.0003 + 300 × 0.005 + 20 × 0.01 = 0.15 + 1.5 + 0.2 = 1.85, so P_success ≈ e^(−1.85) ≈ 0.157.
  4. The CNOTs contribute 1.5 out of 1.85, about 81% of the total. Reducing CNOT error from 0.5% to 0.1% would lower their term to 0.3, giving a total of 0.65 and P_success ≈ 0.52.
  5. This is why two-qubit gate quality is the figure to watch.

The estimate is optimistic. It ignores idle errors while qubits wait, crosstalk, leakage and correlated errors. It also does not say whether the errors matter for the specific output. Real benchmarks measure circuit performance directly. The calculation still gives an immediate feel for what a circuit of a given size demands of the hardware, and for why error correction is the long-term answer.

Common misunderstandings

MisunderstandingCorrection
Quantum gates are like logic gates with extra statesThey are unitary matrices. They must be reversible, which excludes AND, OR and any many-to-one map.
The Hadamard gate ‘creates superposition’ and nothing elseIt also changes basis. Applied to a superposition it can undo it. H² = I.
CNOT copies a qubitOn basis states it looks like a copy. On a superposition it creates entanglement. No-cloning forbids copying.
Circuits are read like matrices, left to rightThey are drawn left to right but multiplied right to left.
All gates cost the sameTwo-qubit gates have much higher error. Under error correction, T gates dominate cost.
The textbook gate set is what hardware runsHardware runs native gates, and a compiler translates. Compiled gate counts differ from the textbook diagram.
Universal means every gate is available exactlyA finite universal set only approximates arbitrary gates, with cost polylogarithmic in 1/ε.

Practice problems

Check yourself

Show that Z H applied to |0⟩ gives |−⟩ and H Z applied to |0⟩ gives |+⟩. What does that say about the order of gates?

H|0⟩ = |+⟩ and Z|+⟩ = |−⟩, so Z·H|0⟩ = |−⟩. Z|0⟩ = |0⟩ and H|0⟩ = |+⟩, so H·Z|0⟩ = |+⟩. The results differ, so H and Z do not commute and order matters.

Compute H S H applied to |0⟩ and describe the result on the Bloch sphere.

H|0⟩ = |+⟩, S|+⟩ = |+i⟩, H|+i⟩ = ((1+i)/2)|0⟩ + ((1−i)/2)|1⟩. This is the point −y on the equator, a state that is |−i⟩ up to a global phase.

Verify that T⁴ = Z and T² = S.

T = diag(1, e^(iπ/4)). T² = diag(1, e^(iπ/2)) = diag(1, i) = S. T⁴ = diag(1, e^(iπ)) = diag(1, −1) = Z.

What does CZ do to |11⟩, and why is CZ symmetric between its two qubits?

It multiplies |11⟩ by −1 and leaves other basis states alone. The condition ‘both qubits are 1’ does not distinguish control from target.

Write SWAP as three CNOTs and test it on |10⟩.

CNOT₁₂, CNOT₂₁, CNOT₁₂. |10⟩ → |11⟩ (first, q1 controls) → |01⟩ (second, q2 controls q1) → |01⟩ (third, q1 is 0). The result |01⟩ is the swapped state.

A circuit applies A, then B, then C to a state. Write its matrix.

C·B·A. The first gate applied is the right-most matrix.

A device has CNOT error 0.2% and you run 250 CNOTs. Estimate the survival probability from CNOT errors alone.

exp(−250 × 0.002) = e^(−0.5) ≈ 0.61, about 61%.

Why does the Toffoli decomposition above have a T-count of 7, and why does that number matter?

The sequence contains seven T or T† gates. Under fault-tolerant error correction T gates cost far more than Cliffords, so T-count dominates resource estimates.

What does the Gottesman–Knill theorem imply about circuits made only of H, S and CNOT?

They can be simulated efficiently on a classical computer, so they cannot give a quantum speed-up on their own, even though they create large entanglement.

References and further reading

The explanations are written for this site, and every identity and decomposition on this page was verified numerically with matrices. I opened the arXiv abstracts of Barenco et al. (1995) and Dawson and Nielsen (Solovay–Kitaev) to confirm what they state. Statements about native gate sets differ by vendor and change often; they are given as typical, not exact. Later optimal-synthesis results on T-count were not opened.

  1. Elementary gates for quantum computation (arXiv quant-ph/9503016; Phys. Rev. A 52, 3457 (1995), A. Barenco, C. H. Bennett, R. Cleve, D. P. DiVincenzo, N. Margolus, P. Shor, T. Sleator, J. Smolin, H. Weinfurter) Opened. Abstract: one-bit gates plus the two-bit XOR gate are universal.
  2. The Solovay-Kitaev algorithm (arXiv quant-ph/0505030, C. M. Dawson and M. A. Nielsen) Opened. Polylogarithmic compilation; output length O(log^3.97(1/ε)).
  3. The Nobel Prize in Physics 2022: Press release (The Royal Swedish Academy of Sciences, 2022) Context on why entangling operations are central to quantum information.
  4. Physics 219 Quantum Computation: lecture notes (John Preskill, Caltech) Free notes on circuits, universality and the Clifford group.
  5. A Quantum Engineer’s Guide to Superconducting Qubits (arXiv:1904.06560, Krantz et al.) How gates are realised with microwave pulses on transmons.
  6. IBM Sets the Course to Build World’s First Large-Scale, Fault-Tolerant Quantum Computer (IBM Newsroom, June 10, 2025) Illustrates that fault-tolerant targets are expressed in logical qubits and operation counts.