Quantum computing basics, from qubits to algorithms
Quantum computers process information using the rules of quantum physics: superposition, interference and entanglement. This page builds every basic idea from scratch, with no physics degree required. Each concept comes with a picture, an interactive demo you can play with, and the minimal maths that makes it precise.
1. Why quantum computing?
Classical computers, from your phone to the largest supercomputer, store information as bits that are either 0 or 1, and change them with logic gates. They're extraordinarily good at almost everything. But some problems grow so fast with their size that no classical computer will ever solve them exactly. Simulating molecules is one example: describing 50 interacting electrons exactly needs more numbers than there are atoms in a planet.
A quantum computer stores information in qubits and manipulates it with quantum operations. For certain problems this lets it use an approach no classical machine can efficiently imitate: preparing a large superposition, then using interference so that wrong answers cancel out and right answers reinforce each other.
⚗️ Simulating nature
Chemistry, materials and drug discovery: molecules are quantum systems, so a quantum computer is a natural simulator. This is widely seen as the most likely first big win.
🔐 Cryptography
Shor's algorithm would break RSA and elliptic-curve cryptography on a large, error-corrected machine. That is why "post-quantum" cryptography is being rolled out now.
🔎 Search & optimisation
Grover's algorithm gives a quadratic speed-up for unstructured search. Heuristics for optimisation are being researched, but proven advantages there are limited.
🚫 Not a faster everything
Quantum computers won't speed up spreadsheets, web servers or video games. They are specialised accelerators for specific problem structures.
2. Bits vs qubits
Physicists write quantum states with Dirac (bra-ket) notation. The two basis states of a qubit are written |0⟩ and |1⟩ (read "ket zero" and "ket one"). Under the hood, these are just two-dimensional column vectors:
| Notation | Vector | Meaning |
|---|---|---|
| |0⟩ | 10 | Like a classical 0 |
| |1⟩ | 01 | Like a classical 1 |
| α|0⟩ + β|1⟩ | αβ | A superposition: α and β are complex numbers called amplitudes |
| Classical bit | Qubit | |
|---|---|---|
| State | 0 or 1 | α|0⟩ + β|1⟩, with |α|² + |β|² = 1 |
| Reading it | Gives the stored value; no change | Gives 0 or 1 at random (Born rule) and changes the state |
| Copying | Free | Impossible for unknown states (no-cloning theorem) |
| Operations | Logic gates (AND, OR, NOT), often irreversible | Unitary gates, always reversible (except measurement) |
| n of them describe… | One of 2ⁿ values | 2ⁿ complex amplitudes at once |
3. Superposition and amplitudes
A qubit in superposition isn't "secretly 0 or 1 and we just don't know which". It is in a genuinely different state, described by two amplitudes α and β. Amplitudes are not probabilities: they can be negative or complex. Probabilities only appear when you measure:
Try it: prepare a superposition, then measure it
The state is cos(θ/2)|0⟩ + sin(θ/2)|1⟩. At θ = 90° it's the equal superposition |+⟩.
Measure to collapse the state.
Each measurement uses a fresh, identically prepared qubit. A single result tells you almost nothing; the statistics over many "shots" reveal |α|² and |β|².
4. The Bloch sphere: picturing one qubit
Any single-qubit state can be written using two angles:
|ψ⟩ = cos(θ/2)|0⟩ + e^{iφ} sin(θ/2)|1⟩ θ ∈ [0°, 180°], φ ∈ [0°, 360°)
Those two angles are the latitude and longitude of a point on a unit sphere, the Bloch sphere. The north pole is |0⟩ and the south pole is |1⟩. Points on the equator are equal superpositions that differ only in their relative phase φ. Every single-qubit gate is a rotation of this sphere.
Try it: drive the Bloch vector with angles and gates
Things to try: H on |0⟩ gives |+⟩ (the equator). Then Z flips the phase to |−⟩, and the probabilities don't change at all. Apply H again and you land on |1⟩. Phase is invisible to measurement until interference converts it into probability.
| Point on the sphere | State | Measured in the 0/1 basis |
|---|---|---|
| North pole | |0⟩ | Always 0 |
| South pole | |1⟩ | Always 1 |
| Equator, front (+x) | |+⟩ = (|0⟩ + |1⟩)/√2 | 50 / 50 |
| Equator, back (−x) | |−⟩ = (|0⟩ − |1⟩)/√2 | 50 / 50, but a different state from |+⟩ |
| Equator, ±y | |±i⟩ = (|0⟩ ± i|1⟩)/√2 | 50 / 50 |
5. Measurement
- Measurement is irreversible. It returns a classical bit and leaves the qubit in the matching basis state. The amplitudes are destroyed.
- You can't read amplitudes directly. To estimate them you prepare and measure the same circuit many times. Each run is a shot, and the counts estimate the probabilities.
- Measurement has a basis. "Measuring in the X basis" means rotating with H first and then measuring 0/1. A |+⟩ state gives random results in the Z (0/1) basis but always gives "+" in the X basis.
- Precision costs shots. Statistical error shrinks like 1/√shots, so a 10× more precise estimate needs about 100× more runs.
Mystery qubit
Everyday picture: polarised sunglasses. Vertically polarised light passes a vertical filter every time, but through a diagonal filter it gets through only half the time, at random. Choosing which filter to look through is choosing a measurement basis.
Your mission: a machine prepares the same secret state every time: |0⟩, |1⟩, |+⟩ or |−⟩. Each measurement uses a fresh copy. Name the state using as few measurements as possible.
Make some measurements, then name the state.
6. Phase and interference: the real source of power
Amplitudes add like waves. Two contributions with the same phase add up (constructive interference); with opposite phases they cancel (destructive interference). Quantum algorithms are choreographed so that paths leading to wrong answers cancel.
Try it: H → phase φ → H, and watch the amplitudes add up
P(0) = cos²(φ/2). At φ = 0 the |1⟩ contributions cancel; at φ = 180° (a Z gate) the |0⟩ contributions cancel instead, so H·Z·H = X.
7. Quantum gates
A quantum gate is a unitary matrix U (one with U†U = I) applied to the state vector. Unitary means it preserves total probability and is reversible: every gate can be undone. That is very different from a classical AND gate, which throws information away.
| Gate | Matrix | What it does | On the Bloch sphere |
|---|---|---|---|
| X (NOT) | 0110 | |0⟩ ↔ |1⟩ (bit flip) | 180° about x |
| Y | 0−ii0 | Bit flip + phase flip | 180° about y |
| Z | 100−1 | |1⟩ → −|1⟩ (phase flip) | 180° about z |
| H (Hadamard) | 1/√21/√21/√2−1/√2 | |0⟩ → |+⟩, |1⟩ → |−⟩; creates and undoes superposition | 180° about the x+z diagonal |
| S | 100i | Quarter-turn phase | 90° about z |
| T | 100e^{iπ/4} | Eighth-turn phase | 45° about z |
| Rx(θ), Ry(θ), Rz(θ) | e^{−iθσ/2} | Continuous rotations, the dials of variational algorithms | θ about x, y or z |
| CNOT (2 qubits) | 1000010000010010 | Flips the target if the control is 1 | Creates entanglement (no single-sphere picture) |
The CNOT matrix is written with the control as the first (left) qubit and basis order |00⟩, |01⟩, |10⟩, |11⟩. Qiskit lists bits in the opposite order (qubit 0 rightmost), which swaps how this matrix looks.
- Universality: {H, S, T, CNOT} (the "Clifford + T" set) can approximate any quantum computation to any desired accuracy, just as NAND gates suffice classically.
- Clifford circuits are easy: circuits made only of H, S and CNOT can be simulated efficiently on a classical computer (the Gottesman–Knill theorem). The "magic" that makes quantum computing hard to simulate comes from non-Clifford gates like T.
- Useful identities: H·H = I, X·X = I, HZH = X, HXH = Z, S² = Z, T² = S, T⁸ = I.
Gate maze
Everyday picture: a Rubik's cube. Every gate is a rotation, every rotation can be undone, and there are clever shortcuts. The six dots are the six "poles" of the Bloch sphere from section 4. Reach the target in as few moves as possible.
8. Many qubits: the exponential state space
Two qubits have four basis states, |00⟩, |01⟩, |10⟩, |11⟩, and a general two-qubit state needs four amplitudes. Every added qubit doubles the number of amplitudes: n qubits are described by 2ⁿ complex numbers. Combining independent qubits uses the tensor product, e.g. |0⟩ ⊗ |1⟩ = |01⟩.
| Qubits | Amplitudes (2ⁿ) | Memory to store the state classically (16 bytes each) |
|---|---|---|
| 10 | 1,024 | 16 KiB: trivial |
| 30 | ≈ 1.07 billion | 16 GiB: a laptop |
| 40 | ≈ 1.1 trillion | 16 TiB: a large cluster |
| 50 | ≈ 1.1 × 10¹⁵ | 16 PiB: beyond most supercomputers |
| 300 | ≈ 2 × 10⁹⁰ | More numbers than atoms in the observable universe (~10⁸⁰) |
Rice on the chessboard
Everyday picture: the chessboard legend. Put one grain of rice on the first square and double it on every square after. By square 64 you'd need more rice than the world has ever grown. Each extra qubit is one more square: it doubles the numbers a classical computer must store.
Most people guess in the thousands or millions.
9. Entanglement
Some multi-qubit states can't be written as a product of single-qubit states. These are entangled. The classic example is the Bell state, made with just two gates:
|00⟩ —H on q0→ (|0⟩+|1⟩)/√2 ⊗ |0⟩ —CNOT(q0→q1)→ (|00⟩ + |11⟩)/√2 ← a Bell state
| Bell state | Measurement correlation | Made from |
|---|---|---|
| |Φ⁺⟩ = (|00⟩ + |11⟩)/√2 | Always equal | H, CNOT |
| |Φ⁻⟩ = (|00⟩ − |11⟩)/√2 | Always equal (differs in phase) | H, CNOT, then Z |
| |Ψ⁺⟩ = (|01⟩ + |10⟩)/√2 | Always opposite | H, CNOT, then X |
| |Ψ⁻⟩ = (|01⟩ − |10⟩)/√2 | Always opposite (in every basis) | H, CNOT, then X and Z |
The impossible quiz show
Everyday picture: two contestants in separate soundproof rooms. They can agree on a plan beforehand, but once the game starts they can't communicate. Is there a plan that wins more than 75% of the time? Classically, no. With entangled qubits, yes.
Rules: each round, a host hands Alice and Bob a random card, 0 or 1. Each answers 0 or 1. They win if their answers match, except when both get card 1: then their answers must differ. Set their plan below and play 1,000 rounds.
Try at least two different plans. The entangled option unlocks after that.
10. Circuit lab: build and simulate
A quantum circuit reads left to right: horizontal lines are qubits (all starting in |0⟩), boxes are gates, and the meter symbols at the end are measurements. This lab runs an exact state-vector simulation of 3 qubits in your browser.
Basis states are written |q2 q1 q0⟩, with q0 on the right (the same convention as Qiskit). The amplitude column is what a simulator sees; a real device only ever gives you the shot counts. If the only non-zero amplitude is −1 (as after Grover), that minus sign is a global phase: physically identical to +1.
11. The rules of the game
📵 No-cloning
There's no operation that copies an unknown quantum state. You can't back up a qubit or fan it out like a classical wire. This is why quantum error correction is so different, and why quantum key distribution can detect eavesdroppers.
↩️ Reversibility
Every gate is unitary and can be undone. Only measurement (and noise) is irreversible. Classical logic inside quantum algorithms must also be made reversible, often using extra "ancilla" qubits.
👁️ Observation disturbs
Measuring, or any uncontrolled interaction with the environment, collapses superpositions. Qubits must be extremely well isolated, yet still controllable.
📡 Teleportation
With one shared Bell pair plus two classical bits, a qubit's state can be moved to a distant qubit. The original is destroyed (consistent with no-cloning), and nothing travels faster than light.
12. Noise, decoherence and error correction
Real qubits are fragile. Tiny interactions with the environment, such as heat, stray fields or vibrations, gradually destroy the quantum information. This is decoherence.
| Error source | What happens | Typical metric |
|---|---|---|
| Energy relaxation | |1⟩ decays to |0⟩ | T₁ time |
| Dephasing | Relative phase drifts randomly; superpositions lose coherence | T₂ time (T₂ ≤ 2T₁) |
| Gate errors | Imperfect control pulses rotate slightly too far, or the wrong way | 1- and 2-qubit gate fidelity (e.g. 99.9%) |
| Readout errors | A 0 is reported as 1 or vice versa | Measurement fidelity |
| Crosstalk & leakage | Operating one qubit disturbs neighbours; the state leaves the 0/1 subspace | Device-specific |
Quantum error correction
You can't copy qubits, but you can spread one logical qubit across many physical qubits so that errors can be detected without measuring the encoded data. Helper qubits measure parity checks (syndromes), which reveal where an error happened but not the logical value.
Bit-flip detective
Everyday picture: three friends passing on a phone number. If one mishears a digit, the other two outvote them. The quantum twist: you're not allowed to hear the number, because looking would destroy the quantum state. You may only ask pairs of friends "do you two agree?"
A logical bit is stored as three copies (0 → 000, 1 → 111). Noise may flip one copy. Use the two parity checks to decide which qubit to fix.
| Era | What it means |
|---|---|
| NISQ (Noisy Intermediate-Scale Quantum) | Tens to thousands of physical qubits without full error correction. Circuits must be short; results need error mitigation and many shots. |
| Early fault-tolerant | First logical qubits whose error rates improve as the code grows (experiments since 2023–2024 have shown this "below threshold" behaviour on small codes). |
| Fault-tolerant (FTQC) | Many logical qubits running deep circuits reliably. This is needed for Shor-scale cryptanalysis and most proven speed-ups, and likely requires hundreds to thousands of physical qubits per logical qubit. |
13. Quantum algorithms
| Algorithm | Solves | Speed-up vs best known classical | Status |
|---|---|---|---|
| Deutsch–Jozsa / Bernstein–Vazirani | Toy "oracle" problems | Exponential (or linear-to-one) in oracle queries | Teaching examples of interference |
| Grover's search | Find a marked item among N | Quadratic: ~√N queries instead of ~N (provably optimal) | Needs fault tolerance to beat classical in practice |
| Quantum Fourier Transform (QFT) | Fourier transform of amplitudes | Exponentially fewer gates than a classical FFT on 2ⁿ values | Subroutine, not a standalone speed-up |
| Phase estimation (QPE) | Eigenvalues of a unitary | Core of Shor and of chemistry algorithms | Needs fault tolerance |
| Shor's algorithm | Factoring, discrete logarithms | Superpolynomial: polynomial time vs sub-exponential classical | Breaks RSA/ECC on a large FTQC; far beyond today's machines |
| Hamiltonian simulation | Dynamics of quantum systems (chemistry, materials) | Exponential for many physical systems | The most promising long-term application |
| VQE / QAOA (variational) | Ground states, optimisation | Heuristic; no proven advantage | NISQ-era experiments, hybrid with classical optimisers |
| HHL (linear systems) | Ax = b, in a quantum-encoded form | Exponential only under strong conditions (data loading, readout) | Many caveats; "dequantised" classical rivals exist for some cases |
Grover's algorithm in one picture: start with equal amplitudes on all N items; the oracle flips the sign of the marked item's amplitude; the diffusion step reflects every amplitude about the mean, which boosts the marked one. After ~(π/4)√N rounds, the marked item dominates. With N = 4 a single round is exact, as the "Grover finds |11⟩" preset in the circuit lab shows.
Find the prize
Everyday picture: finding a name in a shuffled phone book. With no order to exploit, you check entries one by one: on average half the book. Grover's algorithm needs only about √N "looks", by repeatedly nudging probability toward the right answer.
Round 1, the classical way: a prize is behind one of 16 cards. Peek at cards one at a time.
Click cards to peek.
Round 2, the quantum way: all 16 cards start in equal superposition. The oracle flips the sign of the prize's amplitude (one "look"). Diffuse reflects every amplitude about the average, which boosts the flipped one. Repeat, then measure at the right moment. Too many rounds and it overshoots.
The bars are the simulator's view of the amplitudes; a real quantum computer can't show them to you. You only get the measurement.
14. Quantum computing and cryptography
| Cryptography | Quantum threat | Response |
|---|---|---|
| RSA, Diffie–Hellman, elliptic-curve (ECDH, ECDSA) | Broken by Shor's algorithm on a large fault-tolerant machine | Migrate to post-quantum algorithms |
| Symmetric ciphers (AES) | Grover roughly halves the effective key length | Use 256-bit keys (AES-256) |
| Hash functions (SHA-2, SHA-3) | Modest weakening | Use adequate output sizes |
- NIST post-quantum standards (August 2024): FIPS 203 ML-KEM (key encapsulation, from CRYSTALS-Kyber), FIPS 204 ML-DSA (signatures, from CRYSTALS-Dilithium) and FIPS 205 SLH-DSA (hash-based signatures, from SPHINCS+). They run on ordinary classical computers.
- "Harvest now, decrypt later": adversaries can record encrypted traffic today and decrypt it once a capable quantum computer exists. Data that must stay secret for many years is already at risk, which is why migration is urgent even though no such machine exists yet.
- Quantum key distribution (QKD) uses quantum physics itself (no-cloning) to detect eavesdropping on key exchange. It is a different, hardware-based approach from post-quantum algorithms.
Catch the spy
Everyday picture: a tamper-evident seal. You can't peel it off and stick it back without leaving a mark. A spy (Eve) can't copy a photon (no-cloning), and if she measures it through the wrong filter she scrambles it. That leaves errors Alice and Bob can spot.
How it works (BB84): Alice sends photons, each carrying a random bit through a random filter, + or ×. Bob measures each with his own random filter. Afterwards they announce only which filters they used, keep the bits where the filters matched, and compare those bits. You're the security officer: was someone listening?
15. Building qubits: the hardware
| Platform | Qubit is… | Strengths | Challenges |
|---|---|---|---|
| Superconducting | A tiny superconducting circuit (e.g. a transmon) cooled to ~10–20 millikelvin in a dilution refrigerator | Very fast gates (tens of ns), mature chip fabrication | Short coherence, wiring and cooling at scale, mostly nearest-neighbour connectivity |
| Trapped ions | Individual charged atoms held by electric fields, controlled by lasers | Very high fidelities, long coherence, all-to-all connectivity within a trap | Slower gates (µs), scaling to many ions per trap |
| Neutral atoms | Atoms held in optical tweezers, entangled via Rydberg states | Large, reconfigurable arrays; atoms are identical | Gate fidelity, atom loss, slower cycle times |
| Photonic | Single photons in waveguides or fibre | Room-temperature components, natural for networking | Photon loss, probabilistic entangling operations |
| Spin qubits | Electron or nuclear spins in silicon quantum dots or defects | Tiny footprint, leverages semiconductor manufacturing | Uniformity and control at scale |
| Topological | Exotic quasiparticles (e.g. Majorana modes) designed to be intrinsically protected | Potentially much lower error rates | Still early-stage research |
DiVincenzo's criteria: what any quantum computer needs
- Scalable, well-characterised qubitsYou know exactly what your two-level systems are, and you can add more.
- InitialisationReliably reset qubits to a known state such as |0⟩.
- Long coherence relative to gate timeMany operations must fit within T₁ and T₂.
- A universal set of gatesSingle-qubit rotations plus at least one entangling gate.
- Qubit-specific measurementRead out individual qubits accurately.
For quantum networks, two more criteria cover converting between stationary and "flying" qubits (usually photons) and transmitting them faithfully.
16. Your first quantum program (Qiskit)
Qiskit is an open-source Python SDK for building circuits and running them on simulators or real hardware. This program was run with Qiskit 2.5 (pip install qiskit):
from qiskit import QuantumCircuit
from qiskit.primitives import StatevectorSampler
from qiskit.quantum_info import Statevector
qc = QuantumCircuit(2)
qc.h(0) # put qubit 0 into an equal superposition
qc.cx(0, 1) # entangle: flip qubit 1 when qubit 0 is 1
print(Statevector.from_instruction(qc)) # amplitudes before measurement
print(qc.draw())
qc.measure_all()
result = StatevectorSampler().run([qc], shots=1000).result()
print(result[0].data.meas.get_counts()) # only '00' and '11', roughly 50/50
$ python bell.py
Statevector([0.70710678+0.j, 0. +0.j, 0. +0.j,
0.70710678+0.j],
dims=(2, 2))
┌───┐
q_0: ┤ H ├──■──
└───┘┌─┴─┐
q_1: ─────┤ X ├
└───┘
{'00': 476, '11': 524}
- BuildDescribe the circuit: qubits, gates and measurements.
- TranspileFor real hardware, the circuit is rewritten into the device's native gates and qubit connectivity, which adds SWAPs and changes depth.
- RunExecute many shots on a simulator or a quantum processor (cloud access via providers such as IBM Quantum, Amazon Braket or Azure Quantum).
- AnalyseTurn counts into probabilities or expectation values; apply error mitigation on real hardware.
17. Myths vs reality
| Myth | Reality |
|---|---|
| "A quantum computer tries every answer in parallel and picks the best." | It evolves amplitudes over all inputs, but measurement returns one random outcome. Only interference that favours the answer makes this useful. |
| "Quantum computers will replace classical computers." | They'll be specialised co-processors working alongside classical systems, which also handle control, decoding and pre- and post-processing. |
| "More qubits means more power." | Quality matters as much as quantity: error rates, coherence, connectivity and the number of logical qubits decide what you can run. |
| "Quantum computers can solve NP-complete problems efficiently." | Not believed to be true. Grover gives only a quadratic speed-up for brute-force search. |
| "Entanglement allows faster-than-light communication." | No. Outcomes are random, and correlations only appear when results are compared over a classical channel. |
| "Encryption is already broken." | Not by any existing machine. But "harvest now, decrypt later" makes migrating to post-quantum cryptography urgent for long-lived secrets. |
Glossary
| Amplitude | Complex number attached to each basis state; |amplitude|² is its measurement probability. |
| Basis state | A classical-looking state such as |0⟩, |1⟩ or |101⟩. |
| Bloch sphere | Geometric picture of a single-qubit state as a point on a sphere. |
| Circuit depth | The number of sequential gate layers; deeper circuits suffer more noise. |
| Coherence time (T₁, T₂) | How long a qubit keeps its energy state (T₁) and its phase (T₂). |
| Entanglement | Correlation between qubits that can't be described qubit by qubit. |
| Fidelity | How close an actual operation or state is to the ideal one (1 = perfect). |
| Logical qubit | An error-corrected qubit encoded across many physical qubits. |
| Oracle | A black-box subroutine that marks solutions (e.g. by flipping a phase). |
| Shot | One execution of a circuit ending in measurement. |
| Superposition | A state that is a weighted combination of basis states. |
| Unitary | A reversible, probability-preserving operation, i.e. a quantum gate. |
Self-check quiz
Score: 0 / 0 answered