Quantum circuits are sequences of gates applied to qubits, analogous to logic circuits in classical computing. A small set of gates (Hadamard, phase, and CNOT) is sufficient to approximate any quantum operation, making them a universal programming language for quantum computers.
Building with Quantum: Gates and Circuits
The quantum circuit model is quantum computing's programming language. Learn universal gate sets, single-qubit and two-qubit gates, circuit composition, and the gap between circuits and hardware.
Building with Quantum: Gates and Circuits
Every discipline has a notation that separates the people who can participate from those who can only watch. In music, it is sheet notation. In chemistry, it is structural formulas. In quantum computing, it is the circuit diagram.
A quantum circuit is a picture of a computation. Horizontal lines represent qubits. Boxes on the lines represent gates (operations). Time flows left to right. A measurement symbol at the end indicates where you extract a result. The entire description of a quantum algorithm, from initialization to final readout, fits in this format.
The circuit model is not the only way to think about quantum computation. There are alternatives (measurement-based computation, adiabatic computation, topological approaches), and we will mention them briefly. But the circuit model is the standard language. When researchers publish a quantum algorithm, they draw a circuit. When hardware companies benchmark a processor, they run circuits. When you read a quantum computing paper, the circuit diagram is what you need to read.
This chapter will teach you enough about that language to follow the conversation.
The classical analogy and where it holds
Classical digital circuits also have a visual language. Wires carry bits. Logic gates (AND, OR, NOT, NAND) transform them. Circuits combine gates into larger operations. A processor is, at bottom, a very large circuit.
The quantum version follows the same structure, with three differences that change everything.
First, quantum gates are reversible. Every quantum gate has an inverse that undoes it. Classical gates like AND are not reversible: knowing the output (1) does not tell you the inputs (could be 1,1 or 1,0 or 0,1 for OR). Quantum mechanics requires reversibility for all operations except measurement. This means quantum circuits preserve information at every step until the final measurement.
Second, quantum gates operate on continuous amplitudes rather than discrete bit values. A classical NOT gate flips 0 to 1. A quantum gate rotates a qubit’s state by a precise angle on the Bloch sphere. The precision of that angle matters, and different angles produce different computations.
Third, quantum circuits have a gate that has no classical equivalent: the entangling gate. This is what connects individual qubits into the correlated states described in Chapter 3. Without entangling gates, each qubit would operate independently, and the computation would be no more powerful than running separate classical probabilistic bits.
Gates are irreversible (AND output does not reveal inputs). Operates on discrete bit values. No entangling operations. All gates have classical equivalents.
All gates are reversible (every gate has an inverse). Operates on continuous amplitudes. Entangling gates create correlations with no classical equivalent. Measurement is the only irreversible operation.
Single-qubit gates: the vocabulary
You met single-qubit gates in Chapter 2. Here they are as members of the circuit vocabulary.
The Hadamard gate (H). Placed on a qubit in state 0, it produces an equal superposition. Placed on a qubit already in superposition, it can return it to a definite state. The Hadamard is its own inverse: apply it twice and you get back to the starting state. It appears at the beginning of nearly every quantum algorithm (to create superposition) and often at the end (to convert phase information back into measurable amplitude information).
Phase gates (S and T). These change the relative phase between the 0 and 1 components of a qubit without altering the measurement probabilities. The S gate adds a 90-degree phase. The T gate adds a 45-degree phase. If the Hadamard creates the superposition, phase gates steer the interference. They are the precision instruments of quantum computation, adjusting the angles at which amplitudes will later combine.
Rotation gates (Rx, Ry, Rz). These rotate the qubit around a specified axis of the Bloch sphere by a specified angle. They give continuous control and are especially important for algorithms that need to tune angles as parameters, such as variational algorithms used in chemistry simulations.
The Pauli gates (X, Y, Z). The X gate is the quantum NOT: it swaps the amplitudes of 0 and 1. On the Bloch sphere, it is a 180-degree rotation around the x-axis. The Z gate flips the phase of the 1 component (180-degree rotation around the z-axis). The Y gate combines both effects. These gates are used frequently in error correction and in constructing more complex operations.
Any single-qubit gate can be decomposed into a sequence of rotations. Three rotations around two different axes are sufficient to reach any point on the Bloch sphere from any starting point. This means the single-qubit gates already give you complete control over individual qubits.
But complete control over individual qubits, by itself, does not give you quantum computation. For that, you need gates that act on pairs of qubits.
The Role of Phase Gates
Phase gates leave measurement probabilities unchanged but rotate the qubit’s phase. Since phases determine interference effects, changing the phase can completely alter what happens later in a computation. Phase gates are how quantum algorithms steer interference.
The CNOT gate: where the power lives
The controlled-NOT gate, abbreviated CNOT or CX, is the workhorse of quantum circuits. It acts on two qubits. One is designated the control qubit, the other the target. The gate flips the target qubit if and only if the control qubit is in state 1. If the control qubit is in state 0, the target is left alone.
In classical computing, CNOT is not particularly interesting. It is just a conditional flip. In quantum computing, CNOT is transformative, because the control qubit can be in superposition. If the control is in superposition, the CNOT gate creates entanglement between the two qubits. After the gate, the control and target are correlated in a way that cannot be described by independent qubit states.
The standard recipe for creating a Bell state (the maximally entangled state from Chapter 3) is exactly two gates: a Hadamard on the first qubit, followed by a CNOT with the first qubit as control and the second as target. Two gates. That is all it takes to create the resource that Einstein called spooky.
CNOT is also the key ingredient in almost every multi-qubit quantum operation. Need to copy classical information? CNOT (with the source in a definite state). Need to create entanglement? CNOT (with the source in superposition). Need to implement error correction? Multiple CNOTs arranged in specific patterns. The gate appears so frequently that when hardware companies report the error rate of their two-qubit gate, they are almost always talking about CNOT or its equivalent.
Other two-qubit gates
CNOT is not the only two-qubit gate, though it is the most common.
The CZ gate (controlled-Z) applies a phase flip to the target qubit when the control is in state 1. Unlike CNOT, the CZ gate is symmetric: it does not matter which qubit you call the control and which you call the target. Some hardware platforms implement CZ natively instead of CNOT, since it can be more natural for certain physical systems. Any circuit written with CNOT can be rewritten with CZ (by adding Hadamard gates before and after), so the choice is one of convenience, not capability.
The SWAP gate exchanges the states of two qubits. It can be built from three CNOT gates. SWAP is important in practice because quantum hardware typically allows two-qubit gates only between physically adjacent qubits. If you need to entangle qubits that are not neighbors, you must SWAP qubits along a path until the two you need are adjacent.
Controlled-U gates generalize the controlled-NOT concept: apply any single-qubit gate U to the target, controlled by the state of the control qubit. These can always be decomposed into a sequence of single-qubit gates and CNOTs.
2
Gates to Make a Bell State
Hadamard + CNOT
3
Gates in Universal Set
H, T, and CNOT
3
CNOTs to Build a SWAP
Exchanges two qubit states
Universal gate sets: the sufficiency theorem
Here is one of the most important results in quantum computing theory: a small, finite set of gates is sufficient to approximate any quantum operation to arbitrary precision. This is the universality theorem, and it means you do not need infinitely many types of gates. You need just a few.
One standard universal gate set is: Hadamard, T gate, and CNOT. With these three gates alone, you can build a circuit that approximates any quantum computation on any number of qubits, to any desired accuracy.
The classical analogy is the NAND gate. In classical logic, NAND is universal: any Boolean function can be built from NAND gates alone. The Solovay-Kitaev theorem plays a similar role in quantum computing, showing that any target gate can be approximated by a sequence of gates from the universal set, and the sequence length grows only modestly (polylogarithmically) with the desired precision.
This matters practically because hardware does not need to implement every conceivable quantum gate. It needs to implement a universal set well. If the Hadamard, T, and CNOT gates work with high fidelity on a given processor, that processor can, in principle, run any quantum algorithm.
How circuits compose: depth and width
A quantum circuit has two spatial dimensions that determine its resource requirements.
Width is the number of qubits. This determines the size of the quantum state space. Every additional qubit doubles the number of amplitudes in the quantum state. Ten qubits have roughly a thousand amplitudes. Twenty qubits have roughly a million. Fifty qubits have roughly a quadrillion. Width determines how much quantum information the circuit can process.
Depth is the number of sequential time steps. Within each time step, multiple gates can execute in parallel (on different qubits), but some gates must wait for others to finish. Depth determines how long the computation takes in physical time.
Depth is almost always the binding constraint. Qubits are fragile. They lose their quantum properties through decoherence, and decoherence accumulates over time. A circuit with depth 10 is vastly easier to run than a circuit with depth 10,000, even if they have the same width. The race in quantum computing is between circuit depth (how many sequential operations the algorithm needs) and coherence time (how long the qubits maintain their quantum states).
This creates a design tension. Many algorithms can be made shallower by using more qubits (trade width for depth), or narrower by using more sequential operations (trade depth for width). Finding the right balance for a specific hardware platform is a core challenge in quantum circuit design.
Metric Trap
Raw qubit count is an incomplete metric. A 100-qubit processor with poor connectivity and high error rates may run useful circuits less effectively than a 50-qubit processor with rich connectivity and low error rates. The metric that matters is the size of circuit the processor can execute reliably.
Gates within the same time step, acting on different qubits, execute in parallel. This is a genuine form of parallelism, though it is different from the popular misconception of quantum parallelism. The qubits are doing different things simultaneously, the same way cores in a classical processor execute different instructions simultaneously. The quantum advantage comes from entanglement and interference, not from this gate-level parallelism.
From abstract circuit to physical hardware
There is a gap between the circuit you draw on paper and the circuit that runs on hardware. Bridging that gap is the job of compilation (sometimes called transpilation).
The abstract circuit might use any gates and assume any qubit can interact with any other qubit. Physical hardware has constraints.
Connectivity. Most quantum processors arrange qubits on a chip with limited connections. A superconducting processor might arrange qubits in a grid where each qubit connects to four neighbors. An ion-trap processor might have all-to-all connectivity but with overhead for distant pairs. If your circuit requires a CNOT between qubits 1 and 7 and they are not connected, the compiler must insert SWAP gates to move the information to adjacent qubits. Each SWAP adds three CNOT gates and additional error.
Native gate set. Different hardware implements different native gates. IBM processors natively implement the CNOT and a specific set of single-qubit rotations. Google processors natively implement the “Sycamore gate,” a different two-qubit interaction. The compiler must decompose your abstract gates into the hardware’s native gates.
Error rates. Not all gates on a processor are equally reliable. Some qubit pairs have higher two-qubit gate error rates than others. Smart compilers route operations through the most reliable qubits and connections, even if it means a longer path.
Timing. Gates take physical time to execute, and that time varies across gates and across qubit pairs. The compiler must schedule gates to minimize total execution time while respecting dependency constraints.
The result is that the circuit actually executed on hardware may look quite different from the circuit you designed. It may have more gates (from SWAP insertions and gate decompositions), use different gate types, and execute in a different order. The logical computation is equivalent, but the physical implementation is adapted to the machine.
For technical leaders evaluating quantum platforms, this means that raw qubit count is an incomplete metric. A 100-qubit processor with poor connectivity and high error rates may run useful circuits less effectively than a 50-qubit processor with rich connectivity and low error rates. The metric that matters is the size of circuit the processor can execute reliably, which depends on qubit count, connectivity, gate fidelity, and coherence time together.
Beyond the circuit model
The circuit model is the dominant framework, but two alternatives are worth knowing about.
Measurement-based quantum computation (also called one-way quantum computation) takes a completely different approach. You start by preparing a large, highly entangled state (a cluster state or graph state). Then you perform the computation entirely through single-qubit measurements. The choice of which measurements to make and in what order determines the computation. No multi-qubit gates are needed after the initial state preparation.
This might sound impractical, but it has advantages. The initial entangled state can be prepared offline. The computation itself requires only single-qubit measurements, which are relatively easy to perform. Photonic quantum computing platforms have explored this model extensively.
Adiabatic quantum computation encodes the problem as an energy landscape. You start the system in the ground state (lowest energy state) of a simple energy landscape, then slowly deform the landscape into one whose ground state encodes the answer to your problem. If you deform slowly enough, the system stays in the ground state throughout and arrives at the answer.
Both alternatives are mathematically equivalent to the circuit model in computational power. They can solve the same problems. The differences are in physical implementation and in which problems map naturally to each model.
For most purposes, the circuit model is the language to learn. When you encounter the alternatives, knowing circuits gives you the vocabulary to understand the translation.
Key Takeaways
- Quantum circuits are sequences of reversible gates applied to qubits, read left to right
- Three gates (Hadamard, T, CNOT) form a universal set sufficient to approximate any quantum operation
- Circuit depth (sequential steps) is the binding constraint because qubits lose coherence over time
- Compilation translates abstract circuits into hardware-specific ones, adding SWAP gates and decomposing unsupported operations
- The circuit model is the standard language, though measurement-based and adiabatic alternatives exist with equivalent computational power
The next chapter addresses a question that arises naturally once you understand gates and circuits: what operations are forbidden? The constraints on quantum information turn out to be as important as the capabilities.