- Home
- Quantum Computing
- Quantum Logic Gates: Hadamard, CNOT and Pauli Explained
Quantum Logic Gates: Hadamard, CNOT and Pauli Explained
Three gates do most of the work in the quantum programs you’ll meet as a beginner. Hadamard puts a qubit into superposition, CNOT ties two qubits together, and the Pauli gates (X, Y and Z) flip a qubit in different ways. Learn what those do and you can read most introductory circuits, including the famous Bell state we build in our first Qiskit circuit. The rest of this guide explains each gate in plain terms, and why they behave so differently from the logic gates in your laptop.
How is a quantum gate different from a normal logic gate?
A classical gate such as AND or OR is a lookup table on bits. Two bits go in, one comes out, and information gets discarded along the way. A quantum gate is closer to a rotation. It takes the state of a qubit and turns it, smoothly and reversibly, into another state. That’s why every quantum gate has an exact inverse, and why you can’t build an AND gate directly out of qubits without extra qubits to hold the “lost” information.
If you’ve read what a qubit is, you know a qubit isn’t just 0 or 1 but a blend of both, described by two numbers called amplitudes. A single-qubit gate changes those amplitudes. Nothing random happens inside a gate; randomness only enters at the end, when you measure. This is the point most explanations skip, and it’s worth holding on to: a circuit is a deterministic recipe for setting up probabilities, and measurement is the one step that rolls the dice.
Picture the qubit as an arrow pointing from the centre of a ball to its surface. The north pole is 0 and the south pole is 1; everything in between is a superposition. Gates move the arrow around the ball. That picture, called the Bloch sphere, is a bit of a simplification once several qubits are entangled, but for one qubit it’s the best mental model we know.
The Pauli gates: X, Y and Z
The three Pauli gates are the simplest. Each one is a half-turn of the ball around one axis.
X is the quantum NOT gate. It sends 0 to 1 and 1 to 0, so if your qubit is a definite 0, X makes it a definite 1. On a superposition it swaps the two amplitudes. If you only remember one thing about X, it’s that it’s the “bit flip” and nothing mysterious happens.
Z is the strange one, because it does nothing visible to a definite 0 and, to a definite 1, only changes its sign (from +1 to -1). A sign sounds like it can’t matter, since measuring a plain 1 gives the same result either way. But in a superposition that sign is the difference between two states that look identical when measured and behave completely differently when you push them through another gate. This hidden property is called phase, and phase is the raw material of quantum interference. Much of the speed-up in algorithms like those in our guide to Shor’s and Grover’s algorithms comes from arranging phases so wrong answers cancel and right ones add up.
Y combines both: a bit flip and a phase flip at once (with a factor of i, the square root of -1, which keeps the bookkeeping consistent). You’ll see it less often in beginner circuits. Its main job is to complete the set, so that X, Y and Z cover half-turns around all three axes.
What does the Hadamard gate do?
Hadamard, written H, is the gate that opens the door to everything else. Give it a definite 0 and it returns an even blend of 0 and 1, so that measuring gives either result with 50% probability. Give it a definite 1 and it returns the same even blend, but with the opposite sign on the 1 part. That sign is invisible to measurement, yet it’s exactly why H is reversible: apply H a second time and the two blends cancel back into the original state. Run H twice on a fresh qubit and you’ll measure 0 every time, which is a tiny, satisfying piece of interference.
Because of this, H is the usual first gate in a circuit. Start every qubit in 0, apply H to each, and you have an even superposition of all possible bit strings at once. That’s the starting point for most algorithms. It’s also where the famous “quantum computers try every answer at the same time” slogan comes from, and where it goes wrong. The qubits are in superposition, but measurement returns only one result, and the algorithm has to use phase and interference to make the answer you want likely. We unpack this properly in quantum superposition explained simply.
One handy identity ties the gates together: sandwiching X between two Hadamards gives Z. In words, H swaps the roles of “bit flip” and “phase flip”. That’s useful when you read a circuit and wonder why somebody wrapped a gate in Hs.
What does CNOT do, and why does it matter so much?
Everything above acts on one qubit. CNOT (controlled-NOT) acts on two: a control and a target. If the control is 0, the target is left alone. If the control is 1, the target gets an X. On definite values it behaves exactly like a classical XOR, which is why it can look underwhelming on first meeting.
The magic arrives when the control is in superposition. Take the Bell-state recipe: H on the first qubit, then CNOT with that qubit as control. The control is now “both”, so the target ends up both flipped and not flipped, but correlated with the control. The two qubits no longer have separate states; there’s only a joint state in which they always agree. That’s entanglement, and CNOT is the gate that creates it. Without a two-qubit gate like this, a quantum computer would be a pile of independent qubits, and a classical machine could simulate it easily.
A reference table you can screenshot
| Gate | Qubits | What it does | Think of it as | Undo it with |
|---|---|---|---|---|
| X | 1 | Swaps 0 and 1 | Bit flip (quantum NOT) | X again |
| Z | 1 | Changes the sign of the 1 part | Phase flip | Z again |
| Y | 1 | Bit flip plus phase flip | Half-turn around the third axis | Y again |
| H | 1 | Definite value to even blend, and back | Entry door to superposition | H again |
| CNOT | 2 | Flips target if control is 1 | Conditional bit flip, creator of entanglement | CNOT again |
Every gate in this table is its own undo, which is a handy property to check when a circuit gives odd results.
See them in code
If you’d like to poke at the gates, Qiskit makes each one a single line. Install qiskit and qiskit-aer, then try this on a laptop simulator:
from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator
qc = QuantumCircuit(1)
qc.h(0) # superposition
qc.h(0) # undo it
qc.measure_all()
sim = AerSimulator()
counts = sim.run(transpile(qc, sim), shots=1000).result().get_counts()
print(counts) # expect every shot to read '0'
If Hadamard behaved like a coin flip, you’d see an even split. Instead the second H undoes the first and the counts come back all zeros. Delete the second qc.h(0) and you’ll get roughly half and half. Library interfaces change between versions, so if something fails after an update, check the current Qiskit docs. Our Qiskit walkthrough covers setup and the usual import errors, and you can run real hardware for free by following how to try a quantum computer free.
Our own qualitative reading, not measured data.
When should you not bother with gate-level thinking?
If your goal is to understand what quantum computing can do for the world, you don’t need gates. The big picture in quantum computing explained and what it’s good for today works without a single circuit diagram. Gates start to pay off when you want to run something, follow a tutorial, or judge a headline about “gate fidelity”. And if you want to go deeper than a blog post, a good book beats a dozen articles; we’ve collected the ones we’d pick in our quantum computing books review.
Also note that the gates above are the textbook set. On real chips, errors on each gate (and especially the two-qubit ones) are the main thing holding machines back, which is the topic of quantum error correction. Don’t expect a hardware vendor’s native gates to match this list one-to-one; the compiler handles the translation.
If you take one thing from this, make it this: H opens a superposition, CNOT links qubits, and X and Z give you the two basic ways to nudge a state. Learn those four and the first dozen tutorials you open will suddenly read like sentences instead of hieroglyphs.