Pricing…Open Lab
Gates & entanglement · after Single-qubit gates · ~8 min

Two-qubit gates

A two-qubit gate makes what happens to one qubit depend on another qubit. CX flips the target qubit exactly when the control qubit is 1. Because control and target play different roles, CX on [0,1] and CX on [1,0] are different gates. CZ is the exception: it only flips the sign of the "both qubits are 1" amplitude, so it works the same either way round.

What does "controlled" actually mean?

CX stands for controlled-X. It is also called CNOT, for controlled NOT. It acts on two qubits that play different roles. The control qubit is left alone. The target qubit gets flipped (an X gate) exactly when the control is 1:

  • control 0 → target unchanged
  • control 1 → target flipped

Think of a hallway light wired to a motion sensor. The sensor is the control. The light is the target. The light only changes when the sensor says "yes."

Here is where that picture stops working. The gate does not measure the control. Say the control is in a superposition, with amplitudes on both 0 and 1. Then CX acts on each part of the state separately. In the part where the control is 0, the target is left alone. In the part where the control is 1, the target is flipped. Both parts stay in play. The runs below make this visible.

Two notation facts apply to every circuit on this site. First, the control is always listed first. So CX on [0, 1] means q0 is the control and q1 is the target. Second, in result charts the right-hand bit is q0. Because the roles differ, CX on [0, 1] and CX on [1, 0] are different gates. The second and third runs prove it. Both start from the same state: an H on q0 and nothing on q1.

q0 is set to 1, so the CX fires. Every shot reads 11.standby
123q0|0⟩q1|0⟩X
press run to acquire
|00⟩|01⟩|10⟩|11⟩
————
counts: sampledamplitudes: statevector, exactengine: in-browser
The control is in superposition. You get about half 00 and half 11, never 01 or 10. The two qubits branch together. (This is a Bell pair. The next lesson is all about it.)standby
123q0|0⟩q1|0⟩H
press run to acquire
|00⟩|01⟩|10⟩|11⟩
————
counts: sampledamplitudes: statevector, exactengine: in-browser
Roles swapped. Now q1 is the control, and it is 0, so the gate never fires. You get about half 00 and half 01. q0 keeps its own randomness, and q1 never moves.standby
123q0|0⟩q1|0⟩H
press run to acquire
|00⟩|01⟩|10⟩|11⟩
————
counts: sampledamplitudes: statevector, exactengine: in-browser

Why is CZ symmetric when CX isn't?

CZ applies a Z to the target when the control is 1. Another way to say the same thing: it flips the sign of the |11⟩ amplitude and touches nothing else. Notice that this second description never says which qubit is which. "Both qubits are 1" is the same condition either way round. CZ on [0, 1] and CZ on [1, 0] are the same matrix (the same grid of numbers). So CZ has no real control or target at all. It is like a door that needs two keys turned at once. It doesn't matter which key you call the first one.

CZ and CX are close cousins. Put an H gate on each side of a CZ's target and you get exactly a CX. The next circuit builds a CX that way. It sets q0 to 1, then applies H, CZ, H on q1. It acts exactly like the X-then-CX run above.

Let's check it step by step. q1 starts at |0⟩. The first H turns it into (|0⟩+|1⟩)/√2. q0 is 1, so the CZ flips the sign of q1's |1⟩ part. That gives (|0⟩−|1⟩)/√2. The last H turns that into |1⟩. So both qubits read 1.

Every shot reads 11. H·CZ·H on the target is exactly a CX.standby
1234q0|0⟩q1|0⟩XHH
press run to acquire
|00⟩|01⟩|10⟩|11⟩
————
counts: sampledamplitudes: statevector, exactengine: in-browser

What do two-qubit gates cost on real hardware?

Two-qubit gates are where most errors come from. On current devices a single-qubit gate usually goes wrong about 0.01–0.1% of the time. A two-qubit gate is roughly ten times worse or more, and slower too. So on real hardware, the quality of a circuit depends a lot on how many two-qubit gates you can avoid.

Each machine also has its own native gates, the ones its hardware really performs. Most QPUs don't do CX directly. IBM's superconducting devices use ECR. Google's and IQM's use CZ. Trapped-ion machines use Mølmer–Sørensen-style gates. A program called the compiler builds your CX from the native gate plus single-qubit gates. That is just like the H·CZ·H trick you just ran.

Connectivity matters too. That means which qubits are wired to each other. If two qubits aren't wired together, the compiler adds SWAP gates to bring the data together. Each SWAP costs three CXs. Compare native gate sets and connectivity on the hardware comparison.

Primary sources & further reading