Quantum Gates Explained: From Hadamard to CNOT

If you searched for “quantum gates” expecting AND, OR, and NOT , classical logic gates and transistors, you’re in the right place, but the concept is different. Quantum gates are the quantum computing equivalent: operations that change the state of one or more qubits. Unlike classical gates, they’re reversible and they work on qubits in superposition, not just fixed 0s and 1s.

This guide covers every major quantum gate are X, Y, Z, Hadamard, S, T, CNOT, Toffoli, and SWAP in plain English first, what each is used for second, math only if you want it. All runnable code lives in one place near the end.

What Are Quantum Gates in Quantum Computing?

A quantum gate is an operation that changes the state of one or more qubits , the quantum equivalent of a classical logic gate like AND or NOT. Two things set them apart: they’re always reversible (a classical AND gate destroys information; a quantum gate never does), and they can act on qubits in superposition, transforming every possibility a qubit holds at once.

How Do Quantum Gates Differ From Classical Logic Gates?

Why Are Quantum Gates Reversible?

A classical AND gate takes two input bits and produces one output bit. Feed it a 0 and you can’t tell which input combination produced it , the information is gone. A quantum gate can never do that. Every quantum logic gate is unitary always invertible. If you know the output, you can reconstruct the input by running the gate backward. This isn’t a design choice; it falls out of the physics, since quantum states evolve reversibly.

Classical Logic Gates vs Quantum Gates: What’s the Difference?

 Classical logic gatesQuantum gates
What it acts onBits (0 or 1)Qubits (0, 1, or superposition)
Reversible?Not necessarilyAlways
Can it be undone?Only if no information was lostYes, by applying the inverse
Inputs vs outputsCan differ (e.g. 2 inputs → 1 output for AND)Always equal
What happens to informationCan be destroyedAlways conserved
ExamplesAND, OR, NOT, NAND, XORX, Y, Z, H, S, T, CNOT, Toffoli, SWAP

This is the fastest way to see why quantum logic gates need a different toolbox than classical ones.

What Are the X, Y, and Z Quantum Gates?

X Gate in Quantum Computing

What it does: X flips a qubit’s value 0 becomes 1, 1 becomes 0. Applied to a superposition, it swaps the roles of the 0 and 1 parts.

What it’s for: X is how you turn a qubit that starts as 0 (the standard hardware starting state) into a 1, or invert a bit as setup for a larger circuit.

For the mathematically curious

     X = [ 0  1 ]
[ 1  0 ]

This is the Pauli-X matrix. It’s Hermitian, traceless, and its own inverse , apply it twice and you’re back where you started.

Z Gate in Quantum Computing

Before Z, it helps to explain phase , the idea that trips up most beginners. Phase is an internal property of a quantum state that doesn’t change what you get from measuring a single qubit alone, but changes how that qubit behaves when combined with others, through interference. It’s invisible to one measurement but very real in anything more complex.

What it does: Z leaves a qubit that’s definitely 0 or 1 alone. On a superposition, it flips the phase of the “1” part — a change you won’t see in a single measurement, only in how the qubit interacts later.

What it’s for: Z is essential once you’re combining qubits or building interference effects, which is where quantum computing gets its real speedups.

For the mathematically curious

Z  [ 1   0 ]
[ 0  -1 ]

Z leaves |0⟩ unchanged and multiplies |1⟩ by −1. Hermitian, traceless, its own inverse.

Y Gate in Quantum Computing

What it does: Y combines what X and Z do  it flips the qubit’s value and flips its phase in one operation.

What it’s for: Less common as a standalone gate in beginner circuits, but fundamental to the Pauli group underlying quantum error correction.

For the mathematically curious

Y =       [ 0  -i ]
[ i   0 ]

Hermitian, traceless, and its own inverse, like X and Z  together the three form the Pauli group.

The Hadamard gate : how you create superposition

The Hadamard gate (H) is arguably the single most important gate in quantum computing, and probably why you’re reading this.

What it does: Applied to a qubit that’s definitely 0, H puts it into an even mix of 0 and 1 , a true superposition, not a guess. Applied to 1, H also produces an even mix, with a different internal phase relationship. Measure afterward and you’ll get 0 about half the time, 1 about half the time.

Why this is superposition, not just randomness: Before you measure, the qubit genuinely isn’t 0 or 1 , it’s in a well-defined state where both possibilities are live components, with precise amplitudes and phase. That’s different from a fixed hidden value you just don’t know yet, like a coin already lying heads-up.

Applying H twice returns the qubit to exactly where it started. If H produced classical randomness, doing it again would give another random result. It doesn’t . H is precise and fully reversible, which is one of the cleanest ways to see superposition is a real, structured state, not disguised uncertainty.

 S and T Phase Gates in Quantum Computing

S and T both rotate the phase of a qubit’s |1⟩ component by a fixed amount, without touching |0⟩ or changing what a single measurement shows.

S gate: Rotates phase by a quarter turn (90°) , the “square root of Z,” since applying it twice equals one Z.

T gate: Rotates phase by an eighth of a turn (45°) , half of S. Applying it twice equals one S.

Why phase control matters: X gets you between 0 and 1; H gets you into superposition. But without fine phase control, you can’t build the interference patterns most useful algorithms depend on. T, combined with H and CNOT, forms a commonly used universal gate set gates from which any quantum circuit can be built to arbitrary accuracy. T isn’t magic alone; it’s one ingredient in a universal combination, and on real hardware it’s typically more error-prone than simpler Clifford gates (H, S, X, Y, Z, CNOT).

The CNOT gate : how qubits get entangled

How CNOT works : control and target

CNOT acts on two qubits: a control qubit and a target qubit. If the control is 1, flip the target. If the control is 0, leave it unchanged. The control itself is never modified.

ControlTarget (before)Target (after)
000
011
101
110

Why CNOT is the gate that creates entanglement

Apply Hadamard to qubit 0, then CNOT with qubit 0 as control and qubit 1 as target. Both qubits start at 0; H puts qubit 0 into superposition while qubit 1 stays at 0; CNOT then flips qubit 1 only in the “part” of the state where qubit 0 is 1.

The result is a Bell pair: measuring both qubits gives roughly 50% “00” and 50% “11” , almost never “01” or “10.” This isn’t the qubits “agreeing” after the fact or communicating. There’s a single combined quantum state that never separates into independent single-qubit states after the CNOT , the correlation is a structural consequence of that shared state, not a signal at measurement time.

Toffoli and SWAP : the three-qubit and two-qubit workhorses

The Toffoli gate (CCNOT)

Toffoli extends CNOT with two control qubits: the target flips only if both controls are 1. This reproduces a classical AND gate reversibly feed it two inputs as controls and a 0 as target, and the target holds their AND, with no information lost. That’s how classical logic embeds inside a reversible quantum circuit.

The SWAP gate

SWAP exchanges the states of two qubits  whatever qubit A held, qubit B now holds, and vice versa. It sounds trivial, but on real hardware not every qubit connects to every other one. When two qubits that need to interact aren’t adjacent, SWAP gates move quantum information across the chip until they are.

For the mathematically curious

SWAP = [ 1  0  0  0 ]
    [ 0  0  1  0 ]
    [ 0  1  0  0 ]
    [ 0  0  0  1 ]

SWAP exchanges |01⟩ and |10⟩ while leaving |00⟩ and |11⟩ untouched.

How gates combine into quantum circuits

A circuit is a sequence of gates applied to qubits, each qubit drawn as a wire read left to right. Multi-qubit gates like CNOT and Toffoli connect two or more wires at a point in that sequence.

A universal gate set  like {H, T, CNOT}  is a small collection of gates from which any quantum operation can be built, similar to how classical NAND alone builds any classical circuit. The code appendix includes a complete example chaining H, T, and CNOT together.

Try These Yourself

You don’t need a quantum computer, or anything installed. IBM Quantum Composer lets you build circuits visually in a browser at . Qiskit is the Python library behind every snippet below, it runs on a local simulator, or on real IBM hardware with an account.

A good first exercise: build the Bell-pair circuit from the CNOT section, in Composer or in code, and look at the resulting histogram. Seeing “00 and 11 only, roughly 50/50” on your own screen is worth more than reading about it.

For more, see [what quantum computing actually is](link not yet live), [how entanglement works](link not yet live), our [full Qiskit tutorial](link not yet live), and [Grover’s algorithm](link not yet live).

Want to take your AI engineering skills beyond individual experiments? Explore 

IIT Delhi’s Advanced Certificate in Quantum Computing, a hands-on programme focused on building, deploying, and integrating real-world AI systems

Frequently asked questions

What are quantum gates in simple terms?

Quantum gates are operations that change a qubit’s state , the quantum equivalent of classical logic gates like AND or NOT. Every quantum gate is fully reversible, and gates can act on qubits in superposition, transforming multiple possibilities in a single step rather than just fixed 0s and 1s.

What is the difference between classical and quantum gates?

Two things: reversibility and superposition. Classical gates like AND can destroy information and can’t always be undone; quantum gates always can be. Classical gates act on fixed bits; quantum gates can act on qubits holding a mix of 0 and 1 at once. See the comparison table above.

What does the Hadamard gate do?

It takes a qubit that’s definitely 0 or 1 and puts it into an even superposition of both. Measuring afterward gives 0 about half the time and 1 about half the time — but applying it twice returns the qubit exactly to where it started, showing this is precise and reversible, not random.

What is a CNOT gate used for?

CNOT flips a target qubit only when a control qubit is 1, leaving it alone otherwise. It’s the standard way to entangle two qubits: applying Hadamard to one qubit and then using it as CNOT’s control creates a Bell pair, where measurements of the two qubits become correlated.

Are quantum gates reversible?

Yes, always. Every quantum gate is represented by a unitary matrix, which by definition has an inverse , you can always run a gate “backward” to recover the input. This isn’t a design choice; it follows directly from the reversible nature of quantum mechanics.

How many quantum gates are there?

Infinitely many in principle, since gates like phase rotations can use any angle. In practice, a small universal gate set  such as Hadamard, T, and CNOT  is enough to build any quantum operation to arbitrary precision by combining them in the right sequence.

IIT Delhi

Continuing Education Programme

Certification in Applied Quantum Computing and AI

One of India's first applied quantum programmes — built for the quantum decade.

Duration

6.5 Months

Format

Live Online + Recorded

Batch

Weekend

Application open now

6.5 Months

Weekend batch

4+1 Projects

Incl. capstone

STEM Eligible

B.Tech / BE / BSc

Varsity

×

Quantum Computing