Quantum
Module 4 · Multi-qubit systems · Lesson 3

CNOT, CZ, and SWAP

Three two-qubit gates. One of them creates entanglement out of nothing. The other two are more subtle, but still essential.

12 min read · Lesson 15 of 32

You now know what entangled states are but you haven’t seen how to make one. This lesson fixes that. There are three two-qubit gates you’ll see in almost every quantum circuit: CNOT, CZ, and SWAP. We’ll look at each in turn, starting with the most important one.

CNOT: the entanglement-maker

The CNOT gate — short for “controlled-NOT” — takes two qubits as input: a control and a target. Its rule is:

If the control is in state 1|1\rangle, flip the target. Otherwise, leave it alone.

In table form:

InputOutput
00\|00\rangle00\|00\rangle
01\|01\rangle01\|01\rangle
10\|10\rangle11\|11\rangle
11\|11\rangle10\|10\rangle

Here I’m using qubit 0 as control and qubit 1 as target, so 10|10\rangle means “qubit 1 is 0 and qubit 0 is 1” — and since qubit 0 (the control) is 1, we flip qubit 1, giving 11|11\rangle. (Yes, this is confusing the first time you read it. Sit with it for a moment.)

Written as a matrix in the basis (00,01,10,11)(|00\rangle, |01\rangle, |10\rangle, |11\rangle) with qubit 0 as the control:

CNOT01=(1000010000010010)CNOT_{0 \to 1} = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \end{pmatrix}

The top-left 2×22 \times 2 block is the identity (because when the control is 0|0\rangle, nothing happens) and the bottom-right 2×22 \times 2 block is the Pauli XX (because when the control is 1|1\rangle, the target gets flipped).

CNOT is classical-looking on definite inputs — but its real superpower is what it does to superpositions.

The entanglement recipe

Here’s the most famous circuit in quantum computing:

  1. Start with both qubits in 0|0\rangle, so the joint state is 00|00\rangle.
  2. Apply HH to qubit 0. The joint state becomes 12(00+01)\frac{1}{\sqrt{2}}(|00\rangle + |01\rangle) — still a product state, since it equals 0+|0\rangle \otimes |+\rangle.
  3. Apply CNOT01CNOT_{0 \to 1}. Let’s work through it term by term:
    • CNOT00=00CNOT|00\rangle = |00\rangle (control is 0, do nothing)
    • CNOT01=11CNOT|01\rangle = |11\rangle (control is 1, flip target: qubit 1 goes from 0 to 1)

So the final state is:

12(00+11)=Φ+\frac{1}{\sqrt{2}}(|00\rangle + |11\rangle) = |\Phi^+\rangle

This is the Bell state. We made an entangled state out of two completely independent qubits using only HH and one CNOT. The concurrence is 1. This is exactly the recipe the “entanglement maker” follows in the widget — try it below.

Reset, then: H0H_0, CNOT01CNOT_{0 \to 1}. Watch the concurrence jump from 00 to 11.

CZ: the symmetric one

The CZ gate (controlled-Z) is simpler and more symmetric. It applies a ZZ gate (a phase flip) to the target when the control is 1|1\rangle:

CZ=(1000010000100001)CZ = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & -1 \end{pmatrix}

Notice the only off-diagonal is zero: CZ is a diagonal matrix. All it does is multiply the 11|11\rangle amplitude by 1-1. That’s it.

Here’s the cute part: CZ is symmetric between the two qubits. In CNOTCNOT, there’s a clear “control” and “target” — swap their roles and you get a different gate. But CZCZ doesn’t care which qubit you call “control” and which you call “target”; the action is the same. That makes CZCZ particularly natural for hardware where both qubits are on equal footing (like many superconducting architectures).

There’s also a magic identity:

CNOT01=(IH)CZ(IH)CNOT_{0 \to 1} = (I \otimes H) \cdot CZ \cdot (I \otimes H)

In words: CNOT is a CZ “sandwich” with Hadamards on the target. This is a direct consequence of the HXH=ZHXH = Z identity you saw in the Pauli lesson, and it means you can always convert between CNOT and CZ using single-qubit gates.

SWAP: the exchange

The third two-qubit gate is SWAP. It does what the name suggests — exchanges the states of the two qubits:

SWAP00=00SWAP01=10SWAP10=01SWAP11=11SWAP|00\rangle = |00\rangle \quad SWAP|01\rangle = |10\rangle \quad SWAP|10\rangle = |01\rangle \quad SWAP|11\rangle = |11\rangle

After a SWAP, whatever was in qubit 0 is now in qubit 1 and vice versa. This is useful in real hardware where not every pair of qubits can be directly coupled — you have to “walk” a state around the chip by swapping it through intermediate qubits.

Unlike CNOT and CZ, SWAP alone cannot create entanglement. It just moves existing states around. If the input was a product state, the output is still a product state (just with the qubits swapped). You can verify this in the widget: start from any product state, apply SWAP, and the concurrence stays at 0.

SWAP can be built from three CNOTs:

SWAP=CNOT01CNOT10CNOT01SWAP = CNOT_{0 \to 1} \cdot CNOT_{1 \to 0} \cdot CNOT_{0 \to 1}

This is a neat exercise to work through. Try it in the widget: apply those three CNOTs to various input states and verify that it’s the same as SWAP.

Why CNOT is special

Here is a fact that will take the rest of the course to fully appreciate:

The set {H,T,CNOT}\{H, T, CNOT\} is universal for quantum computation.

With just those three gates — Hadamard, T, and CNOT — you can approximate any quantum computation to arbitrary precision. No other gates are needed. The Hadamard creates superposition, the T contributes the missing bit of “non-Clifford” magic, and CNOT connects qubits so they can entangle.

CNOT plays the role in quantum computing that NAND plays in classical computing: it’s the universal gate that (together with a couple of friends) can express everything. On many real quantum processors, CNOT is the only native two-qubit gate the hardware implements — every multi-qubit operation in your algorithm gets compiled down into a sequence of CNOTs and single-qubit rotations.

Quick check
What does CNOT(0 → 1) do to the state |11⟩?
Quick check
Starting from |00⟩, what single quantum circuit produces the Bell state (|00⟩+|11⟩)/√2?
Quick check
Can SWAP create entanglement from a product input state?

What’s next

You now have all the ingredients: qubits, single-qubit gates, and two-qubit gates including one (CNOT) that creates entanglement. In the final lesson of Module 4, we put the pieces together properly and meet the four Bell states — the simplest maximally entangled systems in quantum mechanics — and see what makes their measurement correlations genuinely strange.