Part I · Chapter 3

Qubits & Gate Introduction

Read ~25 min Prerequisites Ch. 1–2 Tools Bloch sphere, code cell Live

A qubit is a unit vector in a two-dimensional complex space. That's the whole mathematical story — but the geometry of where that vector points is what makes qubits feel different from classical bits, and that geometry has a name: the Bloch sphere.

From a bit to a qubit

A classical bit is 0 or 1 — a single binary choice. A qubit's state is a superposition:

Fig. 3.1 — interactivedrag the sliders

Click and drag directly on the sphere to rotate the vector, or use the sliders for precise angles.

The Bloch sphere (left) and the great-circle slice at the current φ (below) — the 2D cross-section that makes the θ angle easy to read at a glance. Click a gate button to watch it act as a real rotation of the vector.

Every point on the sphere's surface is a valid single-qubit state. The north pole is |0⟩, the south pole is |1⟩, and everywhere else is a superposition with a specific phase and amplitude balance — not "0 and 1 at once" in any vague sense, but one specific point on a specific sphere.

What superposition actually means

Written out fully, a qubit's state is

|ψ⟩ = α|0⟩ + β|1⟩

where α and β are complex numbers called probability amplitudes — not probabilities themselves. The actual probability of measuring 0 is |α|², and of measuring 1 is |β|². Because some outcome must happen, these have to sum to exactly 1:

|α|² + |β|² = 1

That single constraint is why a qubit's state space is a sphere at all — it's the same reason the set of points (x, y, z) with x² + y² + z² = 1 traces out a sphere. The θ/φ parametrization in Fig. 3.1 is just a convenient way to walk along that constraint surface without ever leaving it: change θ or φ all you like, and |α|² + |β|² = 1 stays true automatically. The readout under the sphere confirms this directly — try dragging to an extreme angle and check that the line still sums to 1.

A few named states

Most of what you'll read elsewhere refers back to these six points by name:

StateθφMeaning
|0⟩North pole, the "classical 0"
|1⟩180°South pole, the "classical 1"
|+⟩90°Equal superposition, no relative phase
|−⟩90°180°Equal superposition, opposite relative phase
|+i⟩90°90°Equal superposition, phase rotated a quarter-turn
|−i⟩90°270°Equal superposition, phase rotated three-quarter-turn

Try dragging Fig. 3.1's vector to each of these six points and reading the live equation above the sphere — it's the fastest way to make the table above stop feeling like a list of symbols.

Global phase doesn't move the point

Multiply the whole state by e^{iα} for any real α, and the Bloch vector doesn't move at all — global phase is invisible to the sphere, and (as you'll confirm in Ch. 7) invisible to any measurement too. Only the relative phase between the |0⟩ and |1⟩ components — the φ slider above — actually changes where the point sits.

Gate reference

A single-qubit gate is a 2×2 matrix that takes one valid state to another valid state — geometrically, that means every gate has to be a rotation of the Bloch sphere, since that's the only kind of map that keeps every point on the surface. Click any button in Fig. 3.1 and compare what happens to the sphere against the matrix and rotation below — same fact, three ways of seeing it.

X — bit flip

$$X=\begin{bmatrix}0&1\\1&0\end{bmatrix}$$
θ → π−θ, φ → −φ

180° rotation about the x-axis. Swaps |0⟩ and |1⟩ outright — the quantum analog of a classical NOT.

Y — bit + phase flip

$$Y=\begin{bmatrix}0&-i\\i&0\end{bmatrix}$$
θ → π−θ, φ → π−φ

180° rotation about the y-axis. Also swaps the poles, but picks up a different phase relationship than X — watch where |+⟩ ends up vs. where X sends it.

Z — phase flip

$$Z=\begin{bmatrix}1&0\\0&-1\end{bmatrix}$$
θ unchanged, φ → φ+π

180° rotation about the z-axis (the |0⟩/|1⟩ axis itself). Leaves the poles fixed entirely — it only does something visible to states already off the poles.

H — Hadamard

$$H=\tfrac{1}{\sqrt2}\begin{bmatrix}1&1\\1&-1\end{bmatrix}$$
|0⟩ ↔ |+⟩, |1⟩ ↔ |−⟩

180° rotation about the diagonal axis halfway between x and z. The gate that actually creates superposition from a classical-looking start — the one you'll use constantly.

S — phase gate

$$S=\begin{bmatrix}1&0\\0&i\end{bmatrix}$$
θ unchanged, φ → φ+90°

A quarter-turn rotation about the z-axis — half of a Z gate. Notice it does nothing at all to |0⟩ or |1⟩, only to states on the equator and in between.

T — π/8 gate

$$T=\begin{bmatrix}1&0\\0&e^{i\pi/4}\end{bmatrix}$$
θ unchanged, φ → φ+45°

Half of an S gate. Small, precise phase nudges like this are exactly what later algorithms (Ch. 29–31) chain together to build up large effects.

  • Video3Blue1Brown — visualizing qubitsBest visual intuition for why the sphere has the shape it does.
  • TextbookNielsen & Chuang, §1.2The canonical derivation of the θ/φ parametrization.
  • ToolQuirkDrag gates onto a circuit and watch the Bloch sphere update live — good for building intuition beyond a single qubit.

The Hadamard gate, as matrix arithmetic

You just clicked H above and watched the vector move. Here's the exact same operation as the raw linear algebra underneath it — edit the matrix and re-run to try a different gate as code instead of a button.

Fig. 3.2 — code, runs in your browser
Applying a Hadamard gate to |0⟩ — edit the matrix and re-run. First run downloads a small Python runtime into the tab; after that it's instant.

Build a sequence

One gate at a time only goes so far. Drag gates from the palette into the slots below (or just click a gate to drop it in the next open slot) to build a real sequence — every step recomputes the actual state, the actual probabilities, and the actual Python that produced them. Everything here starts fresh from |0⟩.

Fig. 3.3 — drag, drop, and merge gatesstarts from |0⟩
I
X
Y
Z
H
S
T
Click "Run on Bloch sphere" to watch Fig. 3.1 animate through your exact sequence, gate by gate. Drag a placed gate onto another slot to reorder it.
Fig. 3.4 — the code behind your sequence
This is generated directly from the slots above — every drag, drop, or click rewrites it. Hit Run to execute the actual numpy version of your circuit.

Two qubits, and the gate that connects them

Everything so far has been a one-qubit gate — a 2×2 matrix touching a single wire. The moment you have two qubits, a new kind of gate becomes possible: one that acts on both wires at once, and can create exactly the kind of correlation that makes two qubits behave as something more than two separate qubits. That gate is CNOT — controlled-X.

CNOT — controlled-X

$$\text{CNOT}_{0\to1}=\begin{bmatrix}1&0&0&0\\0&0&0&1\\0&0&1&0\\0&1&0&0\end{bmatrix}$$
if control=1: flip target

A 4×4 matrix on the joint 2-qubit space — not a tensor product of two 2×2 gates, because what happens to the target depends on the control's value. That dependency is exactly what produces entanglement: after H on q0 then CNOT, the two qubits can no longer be described independently of each other (Ch. 17's GHZ/W states are this same idea pushed to more qubits).

Build it yourself: drag H onto q0's first column, then drag the CNOT tile onto q0 in the next column (this makes q0 the control, q1 the target automatically). Run it — you should land on 50% 00, 50% 11, and exactly 0% on 01 or 10. That's the Bell state, the smallest possible example of entanglement.

Fig. 3.5 — two-qubit circuit, drag gates onto either wirestarts from |00⟩
I
X
Y
Z
H
S
T
CNOT

Drag a gate onto a wire, or click a wire's slot to select it (it highlights), then click a gate tile to drop it in. Click a placed gate to remove it. For CNOT: drop it on whichever wire should be the control.

00
0
01
0
10
0
11
0
The step list shows the exact 4-amplitude state after every gate — including how CNOT changes the math differently from any single-qubit gate. "Run on simulator" samples 1024 simulated measurement shots from the exact probabilities, the same ideal-vs-sampled distinction real hardware dashboards show.
Want the full toolkit — 4 qubits, CNOT/CZ/SWAP, OpenQASM, a Q-sphere, and a gate-matrix inspector? Open the Quantum Composer →
Fig. 3.6 — the code behind your two-qubit circuit
Each gate's matrix is expanded to the full 4×4 that acts on both qubits — for single-qubit gates this is a tensor product with identity on the other qubit (Ch. 5 covers exactly why that works); for CNOT it's the controlled structure shown in the card above.
Check your understanding

If you multiply a qubit's state by a global phase e^{iα}, where does its point move to on the Bloch sphere?

Nowhere — global phase is invisible on the Bloch sphere and invisible to measurement. Only relative phase between the |0⟩ and |1⟩ amplitudes changes the point's position.

Check your understanding

What θ and φ put a qubit exactly on the equator of the Bloch sphere?

θ = 90° (π/2), with φ free to range from 0° to 360° — the equator is the whole set of equal-superposition states, distinguished from each other only by relative phase.

Check your understanding

What state does the Hadamard gate produce from |0⟩, and where does it sit on the sphere?

(|0⟩ + |1⟩)/√2 — on the equator, at φ = 0°. Equal probability of measuring 0 or 1, with no relative phase between the two terms.

Review queue

This proof-of-concept wires up the SM-2 scheduler and storage. A full "serve me the next due card from anywhere in the book" queue view is the next build step — for now, scroll back to a chapter's quiz cards to review them once they're due.