Why the order of gates matters: non-commuting rotations

Rotations about different axes do not commute. A table of examples, the one tricky exception, and what it means for circuits.

6 min read · reviewed December 2026

The effect

Hold a book and turn it a quarter-turn about a vertical axis, then a quarter-turn about a horizontal one. Now start again and do the two in the opposite order. The book ends up facing differently. Rotations in three dimensions do not generally commute, and the Bloch sphere makes this visible, since each gate is a rotation.

Examples from |0⟩

Two gates applied to |0⟩ in both orders. “A then B” means A acts first.
A, BA then BB then ASame?
H, T0.71, 0.71, 0.001.00, 0.00, 0.00no
H, S0.00, 1.00, 0.001.00, 0.00, 0.00no
S, T0.00, 0.00, 1.000.00, 0.00, 1.00yes
X, Z0.00, 0.00, -1.000.00, 0.00, -1.00yes
Rx(π/2), Rz(π/2)1.00, 0.00, 0.000.00, -1.00, 0.00no
H, X1.00, 0.00, 0.00-1.00, 0.00, 0.00no

Same axis always commutes

Rotations about the same axis commute: Rz(α) then Rz(β) is Rz(α + β) in either order. That is why S and T can be combined freely with Z. The trouble starts when the axes differ.

A subtle exception: the same point, different matrices

X and Z anticommute as matrices: XZ = −ZX. The two products differ by a factor of −1, which is a global phase. On the Bloch sphere, which ignores global phase, X then Z and Z then X give the same point. So “the vectors agree” does not mean “the matrices agree”. The difference matters when the gate is controlled by another qubit, because a controlled operation turns a global phase into a relative phase.

Useful identities

You can test any of these in the lab: apply the sequence, then compare with the single gate.

  • H·Z·H = X and H·X·H = Z: a Hadamard on each side swaps the roles of x and z.
  • H·S·H is a quarter-turn about x, since the sandwich moves the z axis onto x.
  • S·S = Z and T·T = S.

What it means for circuit design

Compilers reorder gates only when they commute, and cancel gates only when they undo each other. When you read a circuit diagram, remember that it runs left to right and that swapping two neighbouring gates is not safe unless their rotations commute.

Try it

Questions

Do all quantum gates fail to commute?

No. Gates on different qubits commute, and gates that rotate about the same axis commute. It is gates sharing a qubit with different axes that do not.

Is the order shown left to right in circuits?

Yes, the first gate in time is on the left, but in the matrix product the first gate appears on the right. Be careful when you convert between the two.

Read next

Sources and further reading

  • F. Bloch, “Nuclear induction” (1946)
  • M. Nielsen and I. Chuang, Quantum Computation and Quantum Information, section 1.2 and chapter 4
  • C. Dawson and M. Nielsen, “The Solovay–Kitaev algorithm” (2005)
  • Dictionary: Bloch sphere

Check the original sources for exact citations.