Quantum gates are the basic operations used to build quantum circuits. This practical reference explains what common gates do, how to recognize their matrices and circuit symbols, when to use them, and how to express them in Qiskit so you can move from an algorithm sketch to a testable circuit with fewer surprises.
Overview
A quantum gate transforms the state of one or more qubits. Like a classical logic gate, it is an operation in a circuit, but quantum gates must preserve the total probability of all possible outcomes. Mathematically, this means their matrices are unitary: the inverse operation exists and can undo the gate.
For a single qubit, the state is commonly written as a two-element vector using the computational basis states |0⟩ and |1⟩. A gate acts on that vector by matrix multiplication. You do not need to calculate every matrix by hand to write useful circuits, but understanding the basic effects helps when debugging measurement results or translating an algorithm into code.
The most frequently used gates include the Pauli gates, Hadamard, phase gates, rotation gates, and controlled operations. The following reference uses the basis order |0⟩, |1⟩.
| Gate | Matrix | Intuitive effect | Typical use |
|---|---|---|---|
| X | [[0, 1], [1, 0]] | Flips |0⟩ and |1⟩ | Bit flip, state preparation |
| Y | [[0, -i], [i, 0]] | Flips the basis state and adds a phase | Rotations and basis transformations |
| Z | [[1, 0], [0, -1]] | Leaves |0⟩ unchanged and changes the phase of |1⟩ | Phase marking and error-sensitive circuits |
| H | 1/√2 [[1, 1], [1, -1]] | Maps a basis state to an equal superposition, with a relative phase in one branch | Creating superposition and changing measurement basis |
| S | [[1, 0], [0, i]] | Adds a quarter-turn phase to |1⟩ | Phase-sensitive algorithms |
| T | [[1, 0], [0, eiπ/4]] | Adds an eighth-turn phase to |1⟩ | Fine-grained phase control |
The X gate is often compared with a classical NOT operation, but the comparison is limited: X also acts on superpositions. The H gate is especially important because it creates superposition from a computational-basis state. Superposition does not mean that a measurement displays several classical values at once; measurement produces one outcome according to the resulting probabilities.
Template structure
A useful quantum gate reference should answer four questions for every operation: What does the gate do? Which qubits does it act on? Is it reversible? Why would an algorithm need it? A compact gate entry can follow this structure:
- Name and symbol: Identify the operation used in circuit diagrams and code.
- Matrix or parameter rule: Show the mathematical definition, including any angle or phase parameter.
- State-level interpretation: Explain the effect on
|0⟩,|1⟩, and a general superposition where relevant. - Use case: Connect the operation to state preparation, interference, phase estimation, entanglement, or measurement-basis changes.
- Implementation note: Provide the framework call and mention any control, target, ordering, or hardware consideration that may affect results.
For two-qubit circuits, add the control and target roles explicitly. The CNOT, or controlled-X, applies X to the target only when the control qubit is in the |1⟩ state. In the computational basis, it maps |00⟩ to |00⟩, |01⟩ to |01⟩, |10⟩ to |11⟩, and |11⟩ to |10⟩, assuming the first position identifies the control. It is a central building block for creating entanglement and for conditional logic.
Other controlled gates follow the same pattern. A controlled-Z applies a Z operation conditionally, while controlled rotation gates apply a parameterized rotation when the control condition is met. Multi-qubit gates can be convenient at the algorithm level, but a compiler may decompose them into operations supported by a selected backend.
How to customize
When designing a circuit, start with the mathematical intent rather than a list of familiar gate names. Ask whether you need to prepare a state, create interference, encode a phase, correlate qubits, or rotate into a measurement basis. Then choose the smallest understandable sequence that performs that task.
For example, use X to prepare a known |1⟩ state from |0⟩. Use H when a later operation should act on both computational branches. Use CNOT when the operation on one qubit should depend on another. Use RZ, RX, or RY rotations when the algorithm requires a continuously adjustable angle rather than a fixed quarter- or half-turn. Rotation conventions and parameter signs matter, so confirm the framework definition before comparing circuits across tools.
A minimal Qiskit example looks like this:
from qiskit import QuantumCircuit
qc = QuantumCircuit(2, 2)
qc.h(0) # Create superposition on qubit 0
qc.cx(0, 1) # Use qubit 0 as control and qubit 1 as target
qc.measure([0, 1], [0, 1])
This pattern is commonly used to illustrate entanglement: H creates a superposition on the control, and CNOT correlates the target with it. The measurement output should be interpreted through repeated shots, not from a single run. For a beginner-friendly circuit workflow, see Qiskit Tutorial for Beginners: Build and Run Your First Quantum Circuit.
Keep three implementation details visible in your notes. First, record qubit and classical-bit ordering because displayed bit strings can use an ordering convention that differs from the way you read the circuit. Second, distinguish a relative phase from a global phase: a global phase cannot affect measurement probabilities, while a relative phase can change later interference. Third, test small subcircuits before combining them. A circuit that prepares a state correctly in isolation may behave differently after additional gates or transpilation.
Examples
Example 1: Bit flip and phase flip
Applying X to |0⟩ produces |1⟩. Applying Z to |1⟩ produces -|1⟩. If you measure immediately in the computational basis, that minus sign does not change the result. If you apply H afterward, however, the relative phase can affect interference. This is why a Z gate may appear to do nothing in a simple measurement test while still being important inside a larger algorithm.
Example 2: Preparing and undoing superposition
H is its own inverse, so applying H twice returns a qubit to its original state: H H = I. This gives you a simple debugging test. Prepare a basis state, apply H twice, and verify that measurement returns the original state with the expected distribution. If it does not, inspect qubit ordering, measurement mapping, and any extra operations.
Example 3: CNOT and entanglement
Starting with two qubits in |00⟩, apply H to the first qubit and CNOT with the first as control. The resulting state is a correlated superposition of |00⟩ and |11⟩. Measuring one qubit gives information about the other, but this correlation should not be confused with classical copying of an unknown quantum state. The circuit is useful as a compact test of controlled operations and two-qubit measurement handling.
Example 4: Basis changes
To measure a qubit in the X basis using computational-basis measurement, apply H immediately before measurement. For a Y-basis measurement, a basis-changing sequence involving phase and Hadamard operations is used. The exact sequence should be checked against the framework's convention, but the general method is stable: rotate the desired basis into the basis that the hardware or simulator measures directly.
When to update
Revisit this reference when the quantum SDK changes gate names, parameter conventions, circuit-drawing behavior, or backend compilation rules. Framework syntax is an implementation detail, so a code example should be tested after a dependency upgrade rather than assumed to remain unchanged. Also update examples when a platform changes which native operations, connectivity patterns, or measurement features it exposes.
For your own projects, update the circuit notes whenever you change the qubit layout, add a controlled operation, replace an abstract gate with a decomposed sequence, or move from a simulator to hardware. Record the SDK version, backend or simulator, transpilation settings, number of shots, and measurement mapping. The Quantum Experiment Reproducibility Checklist provides a useful companion for that record-keeping step, while the Quantum Backend Selection Checklist can help when choosing where to run a circuit.
As a practical next step, choose one small circuit and document it using the template: name each gate, write its purpose, identify control and target qubits, and note the expected measurement behavior. Run the circuit first without noise or hardware-specific transformations, then inspect the compiled version and compare results. This habit turns a gate table from a memorization aid into a reusable tool for quantum programming, circuit debugging, and algorithm study.