Free Qiskit tutorial · Beginner
Make a Bell state in Qiskit: entangle two qubits
Two gates are enough to entangle two qubits. Run it, and the qubits agree every time: both 0 or both 1, never one of each.
- To work through
- 10 min
- Level
- Beginner
- Tested on
- Qiskit 2.6
- Runs on your laptop
- Free
The idea
Bell state, in plain words
A Bell state is the simplest kind of entanglement: two qubits whose results are tied together, even though each one on its own is a coin toss. The usual one is written (|00⟩ + |11⟩)/√2: half the time you measure 00, half the time 11, and never 01 or 10.
It takes two gates. A Hadamard gate puts the first qubit into an equal superposition of 0 and 1. A CNOT gate then flips the second qubit only when the first is 1. Because the first qubit is both at once, the pair ends up as both 00 and 11 at once.
The code
The whole script, ready to run
Install Qiskit and its simulator once, save the script as bell_state.py and run it with python bell_state.py. It runs on Qiskit's free simulator, so you don't need an account or a quantum computer.
Install onceTerminal
pip install qiskit qiskit-aerbell_state.pyPython · Qiskit
from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator
qc = QuantumCircuit(2, 2) # two qubits, two classical bits for the results
qc.h(0) # qubit 0 into an equal superposition of 0 and 1
qc.cx(0, 1) # flip qubit 1 when qubit 0 is 1: this entangles them
qc.measure([0, 1], [0, 1])
print(qc.draw())
sim = AerSimulator(seed_simulator=7)
counts = sim.run(transpile(qc, sim), shots=1000).result().get_counts()
print(dict(sorted(counts.items())))What it printedSeed 7 · 1,000 shots
┌───┐ ┌─┐
q_0: ┤ H ├──■──┤M├───
└───┘┌─┴─┐└╥┘┌─┐
q_1: ─────┤ X ├─╫─┤M├
└───┘ ║ └╥┘
c: 2/═══════════╩══╩═
0 1
{'00': 489, '11': 511}What happened
What the output shows
Only 00 and 11 come up, 489 and 511 times out of 1,000: never 01 or 10. Measure the first qubit and you know the second without looking: that's entanglement.
Each qubit alone still looks random, which is why entanglement can't send a message faster than light. The pattern only shows when you compare the two results.
The four Bell states differ by one extra gate. Add qc.x(1) after the CNOT and you get 01 and 10 instead. Add qc.z(0) and the counts look the same, but the sign between the two halves flips, which only shows if you measure in another basis.
Try next
Three things to try next
- Make the other three Bell states with an X or a Z gate, and print each one with Statevector(qc) (leave out the measure line for that).
- Entangle a third qubit: make the circuit QuantumCircuit(3, 3), add qc.cx(1, 2) and measure all three. That's a GHZ state, and you'll only see 000 and 111.
- Run it on a real IBM quantum computer with a free account, and see how often noise gives you 01 or 10.
Take it further · Project 09
Build Quantum Teleportation for real
Teleportation uses exactly this Bell pair to move a qubit's state from one place to another. The project builds it, then superdense coding, with tests that check every step.
Start my 7-day free trialSee the Quantum Teleportation project
Keep going
More free Qiskit tutorials
Questions
Bell state in Qiskit
What is a Bell state?
One of four maximally entangled states of two qubits. The most common, (|00⟩ + |11⟩)/√2, gives 00 or 11 with equal chance when you measure it, and never 01 or 10.
Which gates make a Bell state in Qiskit?
A Hadamard on the first qubit, qc.h(0), then a CNOT from the first to the second, qc.cx(0, 1).
Do I need a quantum computer to run this?
No. Qiskit Aer simulates it on your laptop in under a second. A free IBM Quantum account lets you run the same circuit on real hardware.
Your first circuit is 10 minutes away
Stop watching quantum. Start shipping it.
$0 today. 7 days free, then $7.99 a week or $190 a year. Cancel any time.