Skip to main content
Be Bitwise

Quantum Gates & Circuits

Quantum Computing Fundamentals · Frontiers track

6 min read

In this module

From Classical Gates to Quantum Gates

Back in Logic Gates, we saw classical computers build complex operations out of dirt-simple logic gates: AND, OR, NOT, NAND. Quantum computers play the same game. Complex quantum algorithms are built from simple quantum gates that nudge qubits around.

The catch is that quantum gates carry one constraint classical gates don't: they have to be reversible. Every quantum gate must be possible to "undo." Classical AND already breaks this rule. See an output of 0 and you have no way to recover whether the inputs were (0,0), (0,1), or (1,0). Quantum mechanics flatly forbids destroying information (the principle is called unitarity), so every quantum operation has to keep enough breadcrumbs to reconstruct the input from the output.

Mathematically, quantum gates show up as unitary matrices acting on the state vector of one or more qubits.

Single-Qubit Gates

The Pauli-X Gate (Quantum NOT)

The simplest quantum gate is the X gate, which is the quantum equivalent of the classical NOT gate. It flips |0⟩ to |1⟩ and |1⟩ to |0⟩:

text
X|0⟩ = |1⟩
X|1⟩ = |0⟩

As a matrix:

text
X = | 0 1 |
| 1 0 |

If the qubit is in superposition, X swaps the amplitudes: X(α|0⟩ + β|1⟩) = β|0⟩ + α|1⟩.

The Hadamard Gate

The Hadamard gate (H) is arguably the most important single-qubit gate. It creates superposition from a definite state:

text
H|0⟩ = (|0⟩ + |1⟩) / √2
H|1⟩ = (|0⟩ - |1⟩) / √2

As a matrix:

text
H = (1/√2) | 1 1 |
| 1 -1 |

Apply H twice and the qubit lands back where it started: HH|0⟩ = |0⟩. That falls straight out of unitarity. Every quantum gate has an inverse, and H is its own.

The Hadamard Gate Creates Superposition

The Hadamard gate is the workhorse of quantum computing. It is typically the first gate applied in a quantum algorithm because it puts qubits into superposition, which is where quantum advantage begins. Applying H to N qubits in the |0⟩ state creates an equal superposition of all 2^N possible states - the starting point for many quantum algorithms.

The Pauli-Z Gate

The Z gate leaves |0⟩ unchanged but flips the sign of |1⟩:

text
Z|0⟩ = |0⟩
Z|1⟩ = -|1⟩

This "phase flip" doesn't shift measurement probabilities (since |-1|² = 1), but it does shift the relative phase between |0⟩ and |1⟩. Phase is invisible when you measure a single qubit on its own. The moment qubits start interacting through multi-qubit gates, though, phase becomes the thing that actually matters. A huge chunk of quantum algorithm design is, at heart, phase wrangling.

The S and T Gates

The S gate (phase gate) adds a 90-degree phase to |1⟩, and the T gate a 45-degree one. These finer phase rotations are what let you build arbitrary quantum operations rather than only the obvious ones. Stick H and CNOT alongside them and you get {H, S, T, CNOT}: a universal gate set that can approximate any quantum operation to whatever precision you care to throw gates at.

Multi-Qubit Gates

The CNOT Gate (Controlled-NOT)

The CNOT gate is the most important two-qubit gate. It takes a control qubit and a target qubit. If the control is |1⟩, the target is flipped. If the control is |0⟩, the target is unchanged:

text
CNOT|00⟩ = |00⟩
CNOT|01⟩ = |01⟩
CNOT|10⟩ = |11⟩
CNOT|11⟩ = |10⟩

The CNOT gate is the primary mechanism for creating entanglement. Starting with two qubits in the |00⟩ state:

text
Step 1: Apply H to qubit 1 → (|0⟩ + |1⟩)/√2 ⊗ |0⟩ = (|00⟩ + |10⟩)/√2
Step 2: Apply CNOT → (|00⟩ + |11⟩)/√2

What you've got is a Bell state. The qubits are entangled. Neither has a definite state on its own, but measure one and the other's outcome is locked in.

The Toffoli Gate (CCNOT)

The Toffoli gate takes two control qubits and one target. The target flips only when both controls are |1⟩. It's the quantum equivalent of the classical AND gate, with one massive caveat: it's reversible. The Toffoli gate is universal for classical computation, meaning you can build any classical logic circuit out of Toffoli gates alone.

The SWAP Gate

The SWAP gate exchanges the states of two qubits. It can be decomposed into three CNOT gates. SWAP is often needed in practical quantum computers where qubits can only interact with their physical neighbours.

Quantum Circuits

Quantum algorithms are written as quantum circuits: diagrams where qubits are horizontal lines and gates are symbols dropped onto them. Time runs left to right. Here's a circuit that builds a Bell state:

text
q0: ──H──●──
|
q1: ─────X──

The H gate puts q0 into superposition, and the CNOT (shown as a vertical line from the control dot ● to the target X) entangles the two qubits.

Circuits finish with measurement, drawn as a meter symbol. Measurement collapses the quantum state down to a single classical result. Since the whole game is probabilistic, you typically run the same circuit many times (called shots) and read off a distribution of outcomes rather than a single answer.

Universal Gate Sets

Just as any classical logic circuit can be built from NAND gates alone, any quantum computation can be approximated using a small set of quantum gates. The set {H, T, CNOT} is universal for quantum computing - meaning any unitary operation on any number of qubits can be decomposed into a sequence of these three gates. This is a deep and beautiful result analogous to the universality of NAND in classical computing.

Quantum vs. Classical Gate Differences

A few properties set quantum gates apart from their classical cousins:

  • Reversibility — every quantum gate is reversible; classical gates (AND, OR) usually aren't.
  • No cloning — no quantum gate can copy an arbitrary qubit state. This is the no-cloning theorem, and it has serious knock-on effects for quantum error correction and quantum cryptography.
  • Linearity — quantum gates act linearly on superpositions. Know what a gate does to |0⟩ and |1⟩, and you know what it does to every superposition built from them.
  • Unitarity — quantum gates preserve total probability. Sum the outcome probabilities and you get exactly 1, every time.

Building Intuition

Think of a quantum circuit as a carefully choreographed dance of amplitudes. Each gate nudges the amplitudes of different states around, amplifying some and cancelling others. A well-designed quantum algorithm arranges those nudges so that the answer you actually want ends up with a fat amplitude (high probability when measured) while the wrong answers cancel each other out into background noise.

That play of constructive and destructive interference is the engine behind every quantum speedup, and it's what the next lesson digs into through specific quantum algorithms.