DEV Community

Malcolm Low
Malcolm Low

Posted on • Originally published at malcolmlow.com

Introduction to Quantum Computing: Qubits, Hadamard Gates, and Superposition

Classical computers store information in bits that are always exactly 0 or 1. Quantum computers exploit the principles of quantum mechanics to do something fundamentally different: they operate on qubits, which can exist in a superposition of both states simultaneously. The Hadamard gate is the simplest gate that creates this superposition, and understanding it from first principles is the entry point to every quantum algorithm that follows.


1 · The Qubit

A qubit is the fundamental unit of quantum information. Unlike a classical bit, a qubit can exist in a superposition of |0⟩ and |1⟩ simultaneously. We write its general state using Dirac (bra-ket) notation:

|ψ⟩ = α|0⟩ + β|1⟩
Enter fullscreen mode Exit fullscreen mode

Here α and β are complex numbers called probability amplitudes. They must satisfy the normalisation condition:

|α|² + |β|² = 1
Enter fullscreen mode Exit fullscreen mode

The two computational basis states are represented as column vectors:

|0⟩ =
1
0
|1⟩ =
0
1
Enter fullscreen mode Exit fullscreen mode

When we measure the qubit in state |ψ⟩ = α|0⟩ + β|1⟩, we get |0⟩ with probability |α|² and |1⟩ with probability |β|². The act of measurement destroys the superposition and collapses the qubit to a definite classical state.

Key distinction: The superposition is not just ignorance about a hidden value. The qubit genuinely occupies both states until measured, and this physical reality is what quantum algorithms exploit.

2 · The Hadamard Gate

The Hadamard gate H is a 2×2 unitary matrix that maps each computational basis state to an equal superposition:

H = (1/√2)
+1 +1
+1 −1
Enter fullscreen mode Exit fullscreen mode

Applying H to each basis state:

Input H |input⟩ Short name
|0⟩ (1/√2)( |0⟩ + |1⟩ ) |+⟩
|1⟩ (1/√2)( |0⟩ − |1⟩ ) |−⟩

Both outputs have equal amplitudes of 1/√2, giving a 50% measurement probability for each outcome. The sign difference between |+⟩ and |−⟩ is what drives interference later.

Unitarity check: H†H = I. Since H is real and symmetric, H† = H, so H² = I. The Hadamard gate is its own inverse.

3 · H² = I: Quantum Interference

Applying H twice to |0⟩ returns the qubit to |0⟩. The algebra shows exactly why the |1⟩ amplitudes cancel through destructive interference:

H(H|0⟩)
= H( (1/√2)(|0⟩ + |1⟩) )
= (1/√2)( H|0⟩ + H|1⟩ )
= (1/√2)( (1/√2)(|0⟩+|1⟩) + (1/√2)(|0⟩−|1⟩) )
= (1/2)( |0⟩ + |1⟩ + |0⟩ − |1⟩ )
= (1/2)( 2|0⟩ )
= |0⟩ ✓
Enter fullscreen mode Exit fullscreen mode

The +|1⟩ and −|1⟩ terms cancel completely (destructive interference) while the |0⟩ terms add (constructive interference). This is the fundamental mechanism behind quantum algorithms: arranging amplitudes so wrong answers cancel and the correct answer survives.

4 · Single-Qubit Circuit: H–H–Measure

A single qubit routed through two Hadamard gates and then measured always returns 0 with 100% probability:

q_0:
H
H
M
Enter fullscreen mode Exit fullscreen mode
Step State Notes
1. Initialise |ψ₀⟩ = |0⟩ Ground state
2. First H |ψ₁⟩ = (1/√2)(|0⟩+|1⟩) Superposition: 50/50
3. Second H |ψ₂⟩ = |0⟩ Interference collapses back
4. Measure Result = 0 100% probability

This is a concrete demonstration that superposition is not just probabilistic noise. The deterministic outcome of 0 is only possible because the two Hadamard gates interact through interference, a purely quantum effect with no classical analogue.

5 · Tensor Products and Multi-Qubit States

Multi-qubit systems are described using the tensor product (⊗). For two qubits, the four computational basis states are:

Ket Tensor form Column vector
|00⟩ |0⟩ ⊗ |0⟩ [1, 0, 0, 0]ᵀ
|01⟩ |0⟩ ⊗ |1⟩ [0, 1, 0, 0]ᵀ
|10⟩ |1⟩ ⊗ |0⟩ [0, 0, 1, 0]ᵀ
|11⟩ |1⟩ ⊗ |1⟩ [0, 0, 0, 1]ᵀ

The tensor product of two vectors is computed by multiplying each element of the first vector by the entire second vector and stacking the results. For |0⟩ ⊗ |1⟩:

|0⟩ ⊗ |1⟩
= [1, 0]ᵀ ⊗ [0, 1]ᵀ
= [ 1×[0,1]ᵀ ] = [0, 1, 0, 0]ᵀ = |01⟩
[ 0×[0,1]ᵀ ]
Enter fullscreen mode Exit fullscreen mode

Dimension growth: n qubits span a 2ⁿ-dimensional Hilbert space. A 3-qubit system already has 8 basis states; a 50-qubit system has 2⁵⁰ ≈ 10¹⁵, impossible to store classically.

6 · Two-Qubit Superposition: H⊗H on |00⟩

Applying independent Hadamard gates to both qubits starting from |00⟩:

q_0:
H
q_1:
H
Enter fullscreen mode Exit fullscreen mode
(H⊗H)|00⟩
= (H|0⟩) ⊗ (H|0⟩)
= (1/√2)(|0⟩+|1⟩) ⊗ (1/√2)(|0⟩+|1⟩)
= (1/2)( |00⟩ + |01⟩ + |10⟩ + |11⟩ )
Enter fullscreen mode Exit fullscreen mode

All four two-qubit basis states appear with equal amplitude 1/2. Each has measurement probability (1/2)² = 25%. This is the two-qubit analogue of the uniform superposition that opens algorithms like Grover’s.

7 · Interference in a Two-Qubit H–H Circuit

Applying H⊗H twice to |00⟩ returns it to |00⟩. The interference analysis on each basis state shows the mechanism:

Input to 2nd H⊗H After (H⊗H)
|00⟩ (1/2)( |00⟩ + |01⟩ + |10⟩ + |11⟩ )
|01⟩ (1/2)( |00⟩ − |01⟩ + |10⟩ − |11⟩ )
|10⟩ (1/2)( |00⟩ + |01⟩ − |10⟩ − |11⟩ )
|11⟩ (1/2)( |00⟩ − |01⟩ − |10⟩ + |11⟩ )

The initial superposition has equal weight 1/2 on each of the four states. Summing contributions to each output:

Output state Amplitude sum (× 1/4) Result
|00⟩ +1 +1 +1 +1 4/4 = 1 ✓ constructive
|01⟩ +1 −1 +1 −1 0 destructive
|10⟩ +1 +1 −1 −1 0 destructive
|11⟩ +1 −1 −1 +1 0 destructive

Only |00⟩ survives. This is the same interference structure that the Grover diffusion operator exploits at scale: constructive interference on the target state, destructive on all others.

8 · The H⊗H Matrix and Why It Matters

The combined H⊗H operator is a 4×4 Walsh-Hadamard matrix (scaled by 1/2). Its sign pattern is exactly the two-qubit case of the popcount rule derived in the Walsh-Hadamard post:

H⊗H = (1/2)
+1 +1 +1 +1
+1 −1 +1 −1
+1 +1 −1 −1
+1 −1 −1 +1
Enter fullscreen mode Exit fullscreen mode

Every quantum algorithm that achieves a speedup over classical computation does so through the same three-phase structure:

Phase Operation Purpose
1. Open Hadamard on all qubits Create uniform superposition over all 2ⁿ states
2. Operate Oracle / phase manipulation Mark or bias the amplitude of the target answer
3. Close Hadamard again (+ measurement) Interference concentrates probability on the answer

The bottom line: the qubit and the Hadamard gate are the entry point to everything. Grover’s O(√N) search, Shor’s O((log N)³) factoring, and every other quantum speedup ultimately trace back to this interference mechanism operating at scale.



Part of the Quantum Series 2026. Originally published on Techucation.

Top comments (0)