Write the code, see the circuit

Quantum Gates Explained

Every quantum gate: what it does, why it matters, the 2x2 matrix, and the Qiskit code to use it. Interactive Bloch sphere demos included.

What are quantum gates?

Quantum gates are the building blocks of quantum circuits, the quantum equivalent of logic gates (AND, OR, NOT) in classical computing. Every quantum gate is represented as a unitary matrix that transforms qubit states.

Unlike classical gates, quantum gates are always reversible (unitary), can act on superposition states, and can create entanglement between qubits. A sequence of gates forms a quantum circuit.

Gate Reference

H

Hadamard (H)

|0⟩ → |+⟩, |1⟩ → |−⟩

Creates superposition. The most important gate in quantum computing. Puts a qubit into an equal mix of |0⟩ and |1⟩.

Matrix

1/√2 [[1, 1], [1, -1]]

Qiskit

qc.h(0)
X

Pauli-X (NOT)

|0⟩ → |1⟩, |1⟩ → |0⟩

The quantum NOT gate. Flips a qubit from |0⟩ to |1⟩ and vice versa. Equivalent to a 180° rotation around the X-axis.

Matrix

[[0, 1], [1, 0]]

Qiskit

qc.x(0)
Y

Pauli-Y

|0⟩ → i|1⟩, |1⟩ → -i|0⟩

180° rotation around the Y-axis. Combines a bit flip with a phase flip. Introduces complex phases.

Matrix

[[0, -i], [i, 0]]

Qiskit

qc.y(0)
Z

Pauli-Z

|0⟩ → |0⟩, |1⟩ → -|1⟩

Phase flip gate. Leaves |0⟩ unchanged but flips the sign of |1⟩. Equivalent to a 180° rotation around the Z-axis.

Matrix

[[1, 0], [0, -1]]

Qiskit

qc.z(0)
S

S Gate (Phase)

|0⟩ → |0⟩, |1⟩ → i|1⟩

90° phase rotation. Applies a phase of i (= e^{iπ/2}) to |1⟩. The square root of the Z gate.

Matrix

[[1, 0], [0, i]]

Qiskit

qc.s(0)
T

T Gate (π/8)

|0⟩ → |0⟩, |1⟩ → e^{iπ/4}|1⟩

45° phase rotation. The square root of S. Essential for universal quantum gate sets.

Matrix

[[1, 0], [0, e^{iπ/4}]]

Qiskit

qc.t(0)
CX

CNOT (CX)

|00⟩→|00⟩, |01⟩→|01⟩, |10⟩→|11⟩, |11⟩→|10⟩

Controlled-NOT. The primary 2-qubit gate. Flips the target qubit only if the control qubit is |1⟩. Used to create entanglement.

Matrix

[[1,0,0,0],[0,1,0,0],[0,0,0,1],[0,0,1,0]]

Qiskit

qc.cx(0, 1) # control=0, target=1
CCX

Toffoli (CCX)

Flips target only if both controls are |1⟩

3-qubit controlled-controlled-NOT. Universal for classical reversible computation. Used in arithmetic circuits and error correction.

Matrix

8×8 unitary (classical AND gate + quantum)

Qiskit

qc.ccx(0, 1, 2) # controls=0,1 target=2

Gates in action: Bell state

Two gates is all it takes to create maximum quantum entanglement. H puts qubit 0 into superposition, then CNOT entangles it with qubit 1.

bell_state.py (run in Playground)
from qiskit import QuantumCircuit
from qiskit_aer import AerSimulator

qc = QuantumCircuit(2, 2)
qc.h(0)       # Hadamard: |0⟩ → (|0⟩+|1⟩)/√2
qc.cx(0, 1)  # CNOT: creates entanglement
qc.measure([0, 1], [0, 1])

sim = AerSimulator()
counts = sim.run(qc, shots=1024).result().get_counts()
print(counts)
# → {'00': ~512, '11': ~512}
# Never '01' or '10'. The qubits are entangled.

Learn gates interactively

The Gate Explorer widget lets you select any gate and see the matrix, Bloch sphere effect, and probability changes in real time. Built into every lesson.