Q-Learn

What are quantum gates?

Updated · Part of Learn quantum computing: the beginner’s guide

The short answer

Quantum gates are the operations a quantum computer performs on its qubits, the quantum version of logic gates such as NOT and AND. Each gate changes the state of one or more qubits in a precise, reversible way. Chained together into a quantum circuit, gates create superposition and entanglement and set up the interference that produces an answer.

Learn this step by step in the Quantum Gates and Circuits course, in the free Q-Learn app. Get it on Google PlayGet Q-Learn

From logic gates to quantum gates

An ordinary computer is built from logic gates. A NOT gate flips a bit; an AND gate outputs 1 only if both inputs are 1. Many classical gates throw information away: if an AND gate outputs 0, you cannot tell which inputs produced it.

Quantum gates are different in two ways. They act on amplitudes, so they can create and change superpositions. And they are always reversible: every quantum gate can be undone by another gate. (Mathematically, quantum gates are unitary matrices.) The one irreversible step is measurement, which is usually done at the end.

Single-qubit gates

These act on one qubit at a time. On the Bloch sphere, each one is a rotation.

  • X gate (quantum NOT): swaps |0⟩ and |1⟩. A half turn about the x axis.
  • Z gate (phase flip): leaves |0⟩ alone and turns |1⟩ into −|1⟩. That sign change does not affect probabilities on its own, but it changes how the qubit will interfere later.
  • Y gate: a combination of a bit flip and a phase flip.
  • H gate (Hadamard): turns |0⟩ into an equal superposition (|0⟩ + |1⟩)/√2 and |1⟩ into (|0⟩ − |1⟩)/√2. It is the usual way to create superposition, and applying it twice gets you back where you started.
  • S and T gates: smaller phase shifts, a quarter turn and an eighth of a turn about the z axis.
  • Rotation gates (Rx, Ry, Rz): rotate by any angle you choose. These are the dials adjusted in variational algorithms and quantum machine learning.

Two-qubit gates

Gates that act on two qubits at once are what create entanglement.

  • CNOT (controlled NOT): flips the second qubit (the target) only if the first qubit (the control) is 1. Applied to a control in superposition, it entangles the two.
  • CZ (controlled Z): applies a phase flip only when both qubits are 1. It is the native two-qubit gate on many superconducting chips.
  • SWAP: exchanges the states of two qubits. Useful when the qubits you need to connect are not next to each other on the chip.

There are also three-qubit gates such as the Toffoli (controlled-controlled NOT), which can reproduce any classical logic circuit in a reversible way.

Reading a quantum circuit

Quantum programs are usually drawn as circuit diagrams:

  • Each horizontal line is one qubit, and time runs from left to right.
  • Boxes on a line are single-qubit gates, labelled X, H, T and so on.
  • A dot on one line joined to a ⊕ on another is a CNOT: the dot is the control, the ⊕ the target.
  • A small meter symbol at the end means the qubit is measured.

The simplest interesting circuit is two gates long: an H on the first qubit, then a CNOT from the first to the second. Starting from |00⟩, it produces the entangled Bell state (|00⟩ + |11⟩)/√2.

Universal gate sets

You do not need every possible gate to build any quantum program. A small set is enough to approximate any operation as closely as you like, as long as it includes an entangling gate. A common example is H, T and CNOT. This is the quantum equivalent of the fact that NAND gates alone can build any classical circuit.

Gates on real hardware

Each type of quantum computer has its own native gates, the ones it can perform directly. A compiler translates your circuit into those native gates, routes operations between qubits that are not physically connected, and tries to keep the circuit as short as possible. Every gate adds a little noise, so shorter circuits give better results. That is why circuit optimisation and error correction matter so much today.