Quantum Gates
Quantum gates are the instructions that manipulate qubits. Like classical logic gates (AND, OR, NOT), quantum gates are the alphabet of quantum programs. But quantum gates have a special property: they're all reversible, which is fundamentally different from classical gates.
What is a Quantum Gate?
A quantum gate is a mathematical operation that transforms the state of one or more qubits. Visually, in a circuit diagram, gates are boxes or symbols that qubits "pass through."
Mathematically, a single-qubit gate is a 2×2 unitary matrix. "Unitary" means:
- It preserves the total probability (still sums to 1)
- It's reversible — you can always "undo" a quantum gate
- It rotates the qubit's state on the Bloch sphere
Single-Qubit Gates
X Gate (Pauli-X / Quantum NOT)
The simplest gate. Flips |0⟩ to |1⟩ and |1⟩ to |0⟩ — exactly like a classical NOT gate.
Hadamard Gate (H)
The most important gate in quantum computing. Creates an equal superposition from a definite state. It's the "coin flip" of quantum computing.
|1⟩ → (|0⟩−|1⟩)/√2
Z Gate (Pauli-Z)
Flips the phase of |1⟩ while leaving |0⟩ unchanged. Phase differences are invisible to measurement but matter for interference patterns in algorithms.
Y Gate (Pauli-Y)
Combines the effects of X and Z. Flips the qubit AND changes its phase. Less commonly used alone, but essential in building rotations.
S Gate (Phase Gate)
Rotates the qubit's phase by 90° (π/2 radians). It's the "quarter turn" gate. Applying S twice gives you the Z gate.
T Gate (π/8 Gate)
Rotates the phase by 45° (π/4 radians). The T gate is critical for building universal quantum computation — it's one of the two gates needed to do anything.
Two-Qubit Gates
Two-qubit gates operate on two qubits simultaneously and are essential for creating entanglement.
CNOT Gate (Controlled-NOT)
The CNOT gate has two qubits: a control and a target. It flips the target qubit if and only if the control qubit is |1⟩. This is how quantum computers create entanglement.
| Control | Target (in) | Target (out) |
|---|---|---|
| |0⟩ | |0⟩ | |0⟩ (no change) |
| |0⟩ | |1⟩ | |1⟩ (no change) |
| |1⟩ | |0⟩ | |1⟩ (flipped!) |
| |1⟩ | |1⟩ | |0⟩ (flipped!) |
Toffoli Gate (CCNOT)
A three-qubit gate: two controls and one target. Flips the target only if BOTH controls are |1⟩. The Toffoli gate is universal — you can simulate any classical circuit with it, and it's key to many quantum error correction schemes.
SWAP Gate
Exchanges the states of two qubits. Useful when qubit connectivity on hardware is limited — you can route information around by swapping.
Universal Quantum Gate Sets
Just as any classical computation can be built from NAND gates alone, any quantum computation can be built from a universal quantum gate set. The most commonly used universal set is:
With just these three gates, you can implement any quantum algorithm. This is analogous to how H, T, and CNOT are the complete "instruction set" of a quantum processor.
Frequently Asked Questions
Why must quantum gates be reversible?
Because quantum mechanics requires that all physical processes be reversible (unitary). Information cannot be destroyed in quantum mechanics — only transformed. Classical gates like AND lose information (two inputs, one output), which is why classical computers generate heat. Quantum gates are reversible and theoretically can compute without generating heat.
How many gates are in a real quantum circuit?
It varies enormously. Simple demonstrations might use 5–10 gates. Shor's algorithm for factoring a 2048-bit number would require millions of gates. That's why quantum error correction is critical — errors accumulate with each gate.
Can I apply any gate in any order?
Not freely. Quantum gates don't commute in general — applying H then Z is different from Z then H. Gate ordering is part of algorithm design and must be carefully planned.
Frequently Asked Questions
What will I learn here?
This page covers the core concepts and techniques you need to understand the topic and progress confidently to the next lesson.
How should I use this page?
Start with the overview, then follow the section links to deepen your understanding. Use the table of contents on the right to jump to specific sections.
What should I read next?
Use the navigation below to continue to the next lesson or explore related topics.