Curriculum / Quantum Foundations / Superposition & the Hadamard Gate
Superposition & the Hadamard Gate
Put a qubit into superposition using the H gate.
Superposition & the Hadamard Gate
Superposition Is More Than "Both At Once"
You have probably heard superposition described as "a qubit can be 0 and 1 at the same time." That phrase is a handy shortcut, but it hides what is actually going on. A qubit in superposition is not flickering rapidly between 0 and 1, and it is not secretly one of them waiting to be revealed. It is in a genuinely new kind of state that carries probability amplitudes for both outcomes at once:
|ψ⟩ = α|0⟩ + β|1⟩
Those α and β are complex numbers, not probabilities. You get probabilities from them by squaring their magnitudes, the Born rule, so P(|0⟩) = |α|² and P(|1⟩) = |β|². The fact that amplitudes live at a deeper level than probabilities is exactly what makes quantum computing more powerful than classical randomness: amplitudes can have negative or complex values, and they can cancel. Probabilities can only ever add up.
Meet the Hadamard Gate
The Hadamard gate, written H, is the single most important one-qubit gate in quantum computing. It is the tool you use to create superposition in the first place. As a 2×2 matrix it looks like this:
1 ⎡ 1 1 ⎤
H = ─── ⎢ ⎥
√2 ⎣ 1 -1 ⎦Apply it to the basis states and you get:
- •
H|0⟩ = (|0⟩ + |1⟩) / √2 - •
H|1⟩ = (|0⟩ − |1⟩) / √2
Notice the minus sign in the second line, it matters enormously. Both resulting states have the same measurement probabilities: 50% chance of |0⟩ and 50% chance of |1⟩, because |1/√2|² = 1/2 for both the plus and the minus case. If all you do is measure, you cannot tell them apart. But they are physically different states. The minus sign is a relative phase, and when you apply further gates it completely changes how the state evolves. That is the difference between "we have randomness" and "we have quantum information."
(|0⟩ + |1⟩)/√2 and (|0⟩ − |1⟩)/√2 give identical measurement statistics on their own. Apply another Hadamard to each, though, and they collapse back to |0⟩ and |1⟩ respectively, completely different outcomes. Phase is hidden until interference brings it into the open.
Truly Random, Not Just Unknown
When you Hadamard a |0⟩ qubit and then measure it, you get 0 or 1 with perfect 50/50 probability. But this is not like flipping a coin, where the outcome is determined by physics you just cannot see. Quantum measurement outcomes are, as far as any experiment has ever been able to tell, fundamentally random. There is no hidden variable lurking inside the qubit that "really" says 0 or 1 before you look. The Bell test experiments that won the 2022 Nobel Prize in Physics rule out a huge family of hidden-variable explanations for this randomness. Your Hadamard-measure circuit is one of the only ways humans know how to generate true randomness, not pseudo-randomness, a property that quantum random number generators exploit commercially today.
Verifying Superposition With Shots
Because the outcome is random, a single run tells you almost nothing. You could get 0 or 1 with equal chance, and either result is consistent with lots of different underlying states. The trick is to run the same circuit many times, 1000 shots, say, and accumulate a histogram of results. For a freshly Hadamarded qubit you should see counts very close to 500 zeros and 500 ones. If you see anything wildly different, your circuit is not doing what you think it is.
In code, the Hadamard gate is applied like this:
qc.h(0) # Apply Hadamard to qubit 0And a typical full circuit for this lesson looks like:
qc = QuantumCircuit(1, 1)
qc.h(0) # put qubit 0 into superposition
qc.measure(0, 0) # collapse it and record the result
counts = simulate(qc, shots=1000)
print_counts(counts)Because each shot is an independent random draw, the counts will not be exactly 500/500. Small fluctuations, say 483/517 or 512/488, are completely normal and expected. As you increase the number of shots, the ratio should get closer and closer to 50/50.
Your Challenge
Create a single-qubit circuit, apply the Hadamard gate to qubit 0, measure it, and simulate with 1000 shots. You should see a roughly 50/50 split between state "0" and state "1" in your output. Congratulations, you are about to generate your first real quantum superposition.
Next: combining gates. Gate order matters, you will see how it changes the quantum state.
How this lesson works
A hands-on coding challenge. You write Qiskit-compatible Python in the browser editor, run it instantly via WebAssembly, watch the circuit and Bloch sphere react, and pass automatic output checks. The AI tutor Qubitus gives Socratic hints if you get stuck.
Part of: Quantum Foundations
Learn the basics: qubits, gates, superposition, and measurement.
Take this lesson free
Create a free account and start this lesson in your browser. No credit card, no installation.