The qubit: two amplitudes, one probability rule
A classical bit is 0 or 1. A qubit is a normalised superposition of both basis states with complex amplitudes: |ψ⟩ = α|0⟩ + β|1⟩, where |α|²+|β|² = 1. Physically it can be an electron's spin, a photon's polarisation, two energy levels of a trapped ion, or the ground/excited state of a superconducting transmon — the mathematics is identical regardless of the hardware.
The Bloch sphere
Any single-qubit state, up to an irrelevant global phase, maps to exactly one point on the unit sphere:
|ψ⟩ = cos(θ/2)|0⟩ + e^(iφ)·sin(θ/2)|1⟩ θ ∈ [0,π] — polar angle: θ=0 is |0⟩ (north pole), θ=π is |1⟩ (south pole) φ ∈ [0,2π) — azimuthal angle: equator holds all equal-weight superpositions
Every single-qubit gate is a rotation of this sphere — X is a 180° rotation around the x-axis, Z is a 180° rotation around the z-axis — which is what makes gate composition geometrically intuitive rather than purely algebraic.
Single-qubit gates
Quantum gates are unitary matrices (U†U = I) applied to the amplitude vector. The essential set:
X = [0 1; 1 0] // NOT gate: flips |0⟩↔|1⟩, 180° rotation about x Z = [1 0; 0 -1] // phase flip: Z|1⟩ = −|1⟩ H = (1/√2)·[1 1; 1 -1] // Hadamard: H|0⟩ = (|0⟩+|1⟩)/√2 — the "quantum coin flip" S = [1 0; 0 i] // quarter-turn phase gate, S² = Z T = [1 0; 0 e^(iπ/4)] // eighth-turn phase gate, T⁴ = Z — key for fault tolerance
Measurement and the Born rule
Measuring |ψ⟩ = α|0⟩ + β|1⟩ in the computational basis collapses it irreversibly: outcome 0 with probability |α|², outcome 1 with probability |β|², and the superposition is destroyed the instant a result is recorded. This asymmetry between unitary, reversible evolution and stochastic, irreversible measurement is fundamental — and the no-cloning theorem guarantees an unknown quantum state can never be perfectly copied, the basis for quantum-key-distribution protocols like BB84.
Two qubits, CNOT and entanglement
Two qubits live in a 4-dimensional tensor-product space, α₀₀|00⟩+α₀₁|01⟩+α₁₀|10⟩+α₁₁|11⟩. The CNOT gate flips the target qubit exactly when the control qubit is |1⟩, and together with single-qubit gates it forms a universal gate set — any quantum circuit whatsoever can be built from just these two ingredients. A state is entangled if it cannot be factored into a product of individual qubit states; the four maximally entangled Bell states are built from a Hadamard followed by a CNOT:
|Φ+⟩ = (|00⟩ + |11⟩)/√2 // circuit: H(qubit 0) → CNOT(control=0, target=1), starting from |00⟩
Simulating a circuit: the statevector approach
A statevector simulator represents the full n-qubit state as 2ⁿ complex amplitudes and applies each gate as a matrix operation touching only the pairs of amplitudes that differ in the target qubit's bit:
class QuantumCircuit {
constructor(n) {
this.n = n;
const dim = 1 << n;
this.re = new Float64Array(dim);
this.im = new Float64Array(dim);
this.re[0] = 1; // start in |00…0⟩
}
H(q) { // apply Hadamard to qubit q
const bit = 1 << q, s = 1/Math.sqrt(2);
for (let i = 0; i < this.re.length; i++) {
if (i & bit) continue;
const j = i | bit;
const r0=this.re[i], r1=this.re[j];
this.re[i] = s*(r0+r1); this.re[j] = s*(r0-r1);
}
}
CNOT(ctrl, tgt) { // flip target iff control bit is 1
const cb = 1<
From gates to real algorithms
Grover's search finds a marked item among N in O(√N) queries, a quadratic speedup over classical search. Shor's algorithm factors integers in polynomial time using the quantum Fourier transform, which is the theoretical basis of the long-term threat to RSA encryption. Google's Sycamore processor performed a specific sampling task in 200 seconds that was estimated to take a classical supercomputer roughly 10,000 years — real hardware, but still fundamentally limited by decoherence and requiring roughly 1,000 physical qubits per error-corrected logical qubit.
Frequently asked questions
What is the Bloch sphere actually showing?
Any single-qubit state, up to an overall irrelevant global phase, maps to exactly one point on the unit sphere: the north pole is |0⟩, the south pole is |1⟩, and every point on the equator is an equal superposition of the two with a different relative phase. Every single-qubit gate is then simply a rotation of that sphere, which makes gate composition geometrically intuitive.
Why is CNOT so important if it only flips a bit conditionally?
Because CNOT, combined with arbitrary single-qubit gates, forms a universal gate set — any quantum computation whatsoever can be decomposed into single-qubit rotations plus CNOTs. It's also the simplest gate that creates entanglement between two previously independent qubits, which is why circuits for Bell states and GHZ states always start with a Hadamard followed by one or more CNOTs.
Does entangled measurement let you send information faster than light?
No. Measuring one half of an entangled pair does instantly determine the probability distribution for the other, and this does violate Bell inequalities — ruling out local hidden-variable explanations, confirmed experimentally by Alain Aspect and colleagues (Nobel Prize 2022). But the outcome on each side is still random, and comparing the two results to notice the correlation requires an ordinary classical communication channel, so no faster-than-light signal is ever transmitted.
Try it live
Drag gates onto a circuit and watch the resulting statevector and measurement probabilities update live in Quantum Circuit Simulator.
▶ Open Quantum Circuit Simulator