Phase Gates: S and T

Imagine a single clock hand pinned to the state |1\rangle. A phase gate does one deceptively simple thing: it grabs that hand and turns it — a quarter-turn, an eighth-turn — while leaving |0\rangle completely alone. Nothing about how often you'd measure a 0 or a 1 changes at all. And yet these tiny, invisible turns are the hinge on which the entire power of quantum computing swings — one of them, the T gate, is the single ingredient that separates a machine a laptop could fake from one it never could.

This lesson is about the two most important phase gates — S (a quarter-turn) and T (an eighth-turn) — and the general phase gate they belong to. They build directly on single-qubit gates and on the difference between global and relative phase.

The general phase gate P(φ)

A phase gate is diagonal: in the computational basis it multiplies |0\rangle by 1 and |1\rangle by a phase factor e^{i\varphi}.

P(\varphi) = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\varphi} \end{pmatrix},\qquad P(\varphi)|0\rangle = |0\rangle,\qquad P(\varphi)|1\rangle = e^{i\varphi}|1\rangle.

On a general qubit |\psi\rangle = \alpha|0\rangle + \beta|1\rangle it acts term by term:

P(\varphi)\big(\alpha|0\rangle + \beta|1\rangle\big) = \alpha|0\rangle + e^{i\varphi}\beta|1\rangle.

The factor e^{i\varphi} sits on only one amplitude, so it is a relative phase — real and physical, not the invisible global kind. It is also unitary: since |e^{i\varphi}| = 1, lengths are preserved (P^\dagger P = I).

S is a quarter-turn; T is an eighth-turn

The two named phase gates are just P(\varphi) at two special angles. The S gate turns |1\rangle by a quarter-turn, \varphi = \tfrac{\pi}{2} (and e^{i\pi/2} = i):

S = P\!\left(\tfrac{\pi}{2}\right) = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix},\qquad S|0\rangle = |0\rangle,\qquad S|1\rangle = i\,|1\rangle.

The T gate turns it by an eighth-turn, \varphi = \tfrac{\pi}{4} — half of what S does:

T = P\!\left(\tfrac{\pi}{4}\right) = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix},\qquad T|1\rangle = e^{i\pi/4}|1\rangle = \tfrac{1}{\sqrt2}(1 + i)\,|1\rangle.

(The last step is just e^{i\pi/4} = \cos\tfrac{\pi}{4} + i\sin\tfrac{\pi}{4} = \tfrac{1+i}{\sqrt2}.) Both are named "phase" gates because that is all they touch — the relative phase of |1\rangle.

Worked example: S turns |+⟩ into |+i⟩

Take the equal superposition |{+}\rangle = \tfrac{1}{\sqrt2}\big(|0\rangle + |1\rangle\big) and apply S. It fixes the |0\rangle term and multiplies the |1\rangle term by i:

S|{+}\rangle = \tfrac{1}{\sqrt2}\big(S|0\rangle + S|1\rangle\big) = \tfrac{1}{\sqrt2}\big(|0\rangle + i\,|1\rangle\big) = |{+i}\rangle.

This is a brand-new state, |{+i}\rangle, sitting a quarter-turn around the Bloch sphere's equator from |{+}\rangle. Notice the measurement probabilities are unchanged — still \Pr(0) = \Pr(1) = \tfrac12, because |i|^2 = 1 — yet the state genuinely moved. That is the signature of a phase gate.

Worked example: Z = S² and S = T²

Because phase gates are diagonal, composing them just adds the angles (multiplies the phase factors). Apply S twice:

S^2 = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix}\begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & i^2 \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & -1 \end{pmatrix} = Z.

Two quarter-turns make a half-turn: \tfrac{\pi}{2} + \tfrac{\pi}{2} = \pi, and e^{i\pi} = -1. So Z = S^2 — the Pauli phase-flip Z is exactly two S's. The same logic one level down gives

T^2 = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/4} \end{pmatrix}^{\!2} = \begin{pmatrix} 1 & 0 \\ 0 & e^{i\pi/2} \end{pmatrix} = \begin{pmatrix} 1 & 0 \\ 0 & i \end{pmatrix} = S,

so S = T^2 and, chaining both facts, T^4 = S^2 = Z: four eighth-turns of |1\rangle add up to a phase flip. The whole family is one tower — T, then S = T^2, then Z = T^4 — each doubling the turn.

On the Bloch sphere: a turn about the z-axis

Looking straight down the z-axis at the equator, a phase gate is a pure rotation about z. S spins the state 90^\circ; T spins it 45^\circ. The point |0\rangle (the north pole) sits on the axis, so it never moves — exactly matching S|0\rangle = |0\rangle.

Diagonal and unitary — but not Hermitian

A phase gate is unitary, so it is a legal quantum gate. But it is not Hermitian: its conjugate transpose does not equal itself. Conjugating S = \mathrm{diag}(1, i) flips the sign of the imaginary entry,

S^\dagger = \begin{pmatrix} 1 & 0 \\ 0 & -i \end{pmatrix} \ne S,\qquad T^\dagger = \begin{pmatrix} 1 & 0 \\ 0 & e^{-i\pi/4} \end{pmatrix} \ne T.

So S and T are operations, not observables — you cannot "measure the S of a qubit." (Their inverses S^\dagger and T^\dagger, which turn the phase back the other way, are useful gates in their own right and often appear as S^\dagger, T^\dagger on circuit diagrams.)

In a circuit

On a circuit diagram, time runs left to right along a wire and each gate is a labelled box. A phase gate is drawn as a plain S or T box on a single wire:

Why T is the "magic" gate

Here is the payoff. The gates H (Hadamard), S, and \mathrm{CNOT} form the Clifford group. A circuit built only from Clifford gates, however large, can be efficiently simulated on an ordinary computer — this is the Gottesman–Knill theorem. Clifford gates alone give no quantum speed-up.

Add the T gate and everything changes. T is non-Clifford — it cannot be built from Cliffords — and \{H, S, \mathrm{CNOT}, T\} becomes a universal gate set: it can approximate any quantum operation to any precision, and its circuits are believed to be classically intractable. Because it is the scarce, hard-to-implement resource that lifts a machine out of the classically-simulable regime, T is nicknamed the magic gate, and fault-tolerant hardware spends enormous effort on "magic-state distillation" just to supply clean T's.

S and T change only the relative phase of |1\rangle, and a computational-basis measurement is blind to relative phase — it reports the same probabilities before and after. It is tempting to conclude the gate "did nothing." It did not do nothing. That hidden phase steers what a later Hadamard or interference step produces: measure |{+}\rangle and |{+i}\rangle = S|{+}\rangle directly and they look identical, but run each through a change of basis first and they diverge completely. Two related traps: don't imagine S touches |0\rangle (it fixes it), and don't treat S or T as an observable — they are not Hermitian, so there is nothing to "measure the value of."