Skip to content
Home/Quantum Computing News/Quantum Gates Explained: X, H, CNOT, and More
FundamentalsAlgorithmsBeginners

Quantum Gates Explained: X, H, CNOT, and More

Learn what quantum gates do, how single-qubit and controlled gates change states, and how measurements turn circuits into results.

FreeQuantumComputing
·· 7 min read

Quantum gates are reversible operations on qubits. A gate changes amplitudes, phases, or correlations without reading the qubit state. A quantum circuit combines gates, then measures one or more qubits to produce classical data.

The gate names look small. Their combinations create every algorithm covered by current gate-model software.

A qubit before gates

A qubit state uses two complex amplitudes:

|ψ⟩ = α|0⟩ + β|1⟩

The measurement probabilities are |α|² for 0 and |β|² for 1. Their sum equals one. A gate changes the amplitudes while preserving total probability.

A global phase has no measurement effect. A relative phase does affect later interference. This distinction explains why phase gates matter even when immediate measurement probabilities stay unchanged.

The X gate

The X gate is the quantum version of a bit flip:

  • X|0⟩ = |1⟩
  • X|1⟩ = |0⟩

On the Bloch sphere, X rotates a state by 180 degrees around the x axis. Two X gates return the original state because every quantum gate used in a circuit has an inverse.

The Y and Z gates

The Y gate combines a bit flip with a phase change. The Z gate leaves |0⟩ unchanged and adds a minus sign to |1⟩:

  • Z|0⟩ = |0⟩
  • Z|1⟩ = -|1⟩

A Z gate often appears invisible when followed by immediate measurement in the computational basis. A later H gate converts phase information into measurable probability differences.

X, Y, and Z are Pauli gates. Pauli operators also describe error syndromes, observables, and many Hamiltonians used in quantum algorithms.

The H gate

The Hadamard gate creates equal superposition from a basis state:

  • H|0⟩ = (|0⟩ + |1⟩) / √2
  • H|1⟩ = (|0⟩ - |1⟩) / √2

The minus sign in the second expression is relative phase. Applying H twice returns the input. A common pattern is H, apply a phase-dependent operation, then H again so interference moves phase information into measurement probabilities.

Superposition does not mean a measurement returns both values. Each shot returns one classical result. Repeated shots estimate the distribution.

S and T phase gates

The S gate adds a 90-degree phase to |1⟩. The T gate adds a 45-degree phase. Both are diagonal gates, so computational-basis probabilities stay unchanged immediately after application.

S and T matter because phase differences combine with later gates. T gates also matter in fault-tolerant resource estimates because non-Clifford operations require special error-correction resources in many architectures.

The CNOT gate

CNOT, or controlled-X, uses two qubits. The first qubit is the control. The second is the target.

  • Control 0: target stays unchanged.
  • Control 1: target receives X.

Start with |00⟩. Apply H to qubit 0, then CNOT with qubit 0 as control and qubit 1 as target:

|00⟩ → (|00⟩ + |10⟩) / √2 → (|00⟩ + |11⟩) / √2

Measurement returns 00 or 11, never 01 or 10 in an ideal circuit. The pair is entangled. CNOT plus arbitrary single-qubit rotations forms a universal gate set.

Controlled-Z and SWAP

Controlled-Z adds a phase only when both qubits equal 1. Unlike CNOT, it does not exchange computational-basis values. A change of basis turns one controlled gate into another, which lets compilers select hardware-native operations.

SWAP exchanges two qubit states. A standard decomposition uses three CNOT gates. Hardware with limited connectivity often pays extra SWAP cost when a circuit needs interactions between distant qubits.

Rotation gates

Rotation gates vary continuously by angle:

  • Rx(θ) rotates around the x axis.
  • Ry(θ) rotates around the y axis.
  • Rz(θ) rotates around the z axis.

Variational algorithms such as VQE and QAOA optimize these angles with a classical loop. The circuit supplies expectation values. The optimizer changes parameters and repeats the run.

Measurement is not a gate

Measurement converts a quantum state into classical data and usually destroys the measured state. A circuit sometimes measures in the computational basis or rotates first to measure another observable.

A measurement shot gives one bit string. Thousands of shots build counts. Expectation values estimate averages such as the mean of Z measurements. Read our getting started guide for a complete Bell-state example.

How to read a circuit

Read left to right. Track each wire as a qubit. Mark single-qubit rotations, controlled operations, measurement bases, and barriers. Count two-qubit gates separately because they often produce more errors than single-qubit gates.

Then ask four questions:

  1. Which amplitudes changed?
  2. Which relative phases changed?
  3. Which qubits became correlated?
  4. Which measurement basis reveals the result?

Those four questions explain most beginner circuits before advanced linear algebra enters.