← Back to section · Tutorials & Labs

Your First Quantum Circuit with Qiskit: From a Bell State to a Measurement Histogram

Set up the environment and build a first quantum circuit: prepare a Bell state with a Hadamard gate and a CNOT, run it on a simulator, learn to read the measurement histogram, and understand how real hardware execution differs.

Published 22 November 2026 · 7 min read · PQ Frontier

Your First Quantum Circuit with Qiskit: From a Bell State to a Measurement Histogram
AI-generated illustration by PQ Frontier
Video explainer · Code examples and hands-on projects

Setting Up

You need Python 3.9 or newer, and two install commands:

pip install qiskit qiskit-aer

qiskit is IBM’s open-source quantum computing framework — it describes circuits and submits jobs. qiskit-aer provides a local simulator so you can get circuits running before touching a real quantum computer. The code below follows the current Qiskit 1.x / 2.x interfaces.

Writing the Circuit: Hadamard + CNOT = Bell State

The target is the Bell state ∣00⟩+∣11⟩2\frac{|00\rangle + |11\rangle}{\sqrt{2}}: two qubits entangled so that measurement yields 00 or 11 with equal probability, and never 01 or 10. The recipe has three steps: put the first qubit into superposition with a Hadamard gate, turn that superposition into entanglement with a CNOT, then measure.

from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator

qc = QuantumCircuit(2, 2)   # 2 qubits, 2 classical bits for results
qc.h(0)                     # Hadamard gate on qubit 0
qc.cx(0, 1)                 # CNOT: qubit 0 controls, qubit 1 is the target
qc.measure([0, 1], [0, 1])  # measure into the classical bits

print(qc.draw())

draw() prints a text diagram of the circuit. Check that the gates and wiring are where you expect before running anything — the quantum-programming equivalent of “compile before you execute”.

Running It on the Simulator

simulator = AerSimulator()
compiled = transpile(qc, simulator)
result = simulator.run(compiled, shots=1024).result()
counts = result.get_counts()
print(counts)
# Typical output: {'00': 505, '11': 519} (numbers differ on every run)

shots=1024 means the whole circuit is executed 1024 times; each run produces one two-bit outcome, and the results are tallied into counts. For the graphical version, hand the counts to a histogram:

from qiskit.visualization import plot_histogram
plot_histogram(counts)

Reading the Histogram

The histogram should show exactly two bars, 00 and 11, at roughly 512 counts each. Three things to notice:

  • Why not exactly 512/512? Every measurement is a probabilistic sample. Over 1024 shots the statistical fluctuation is on the order of 1024=32\sqrt{1024}=32, so 505/519 is entirely normal. Raise the shots to a million and the bars move closer to 50/50 — but they never land exactly equal.
  • Why are 01 and 10 absent? That absence is the signature of entanglement: the two outcomes are perfectly correlated. If your histogram shows substantial 01/10 bars, suspect the circuit first — a reversed CNOT or a wrong measurement mapping are the usual culprits.
  • Bit-string order. Qiskit writes count keys from the highest classical bit down, the reverse of naive reading order. With more qubits this trips everyone up; build the checking habit now, on a small circuit.

How Real Hardware Differs

Submit the same circuit to real quantum hardware (via the IBM Quantum platform) and the workflow is identical — but the results are much dirtier:

  • Noise and decoherence. Real qubits interact with their environment; superposition survives only for a limited coherence time, and gate operations carry their own errors. The 01 and 10 bars appear, typically at the level of a few percent.
  • Readout error. The measurement step itself flips results, and is currently one of the largest error sources.
  • Heavier transpilation. Real chips offer only specific native gate sets and coupling topologies, so transpile must rewrite the circuit and insert SWAPs; depth grows and noise accumulates further.
  • Queues and calibration drift. Hardware jobs queue, and devices are recalibrated daily, so the same circuit drifts from day to day.

The standard workflow follows from this: get the logic right on the simulator first, then go to hardware to see what the noise looks like. The simulator answers “is the circuit correct?”; the hardware answers “does the physical world agree?”.

A Common Follow-Up: Can We Just Subtract the Noise?

Beginners often ask whether the noise can simply be removed. There is indeed a whole family of error mitigation techniques: zero-noise extrapolation (deliberately scale the noise up, measure at several levels, and extrapolate the result back to zero noise) and readout-error correction (calibrate the measurement step’s flip probabilities, then invert them out of the count distribution). These pull distributions closer to the ideal, at the price of many more samples and longer runtimes — and they mitigate rather than eliminate. True fault-tolerant quantum computing requires quantum error correction, encoding one logical qubit into many physical ones; that is an engineering effort of a different magnitude, and a topic for later articles in this site’s quantum section. Until then, read hardware results with this default assumption: every “shouldn’t be there” bar in the distribution is telling you something true about the machine’s physical state.

Going Further: The Three-Qubit GHZ State

Extending entanglement from two qubits to three takes just one more CNOT:

from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator

qc = QuantumCircuit(3, 3)
qc.h(0)
qc.cx(0, 1)
qc.cx(0, 2)          # second CNOT: qubit 0 controls qubit 2
qc.measure([0, 1, 2], [0, 1, 2])

simulator = AerSimulator()
counts = simulator.run(transpile(qc, simulator), shots=1024).result().get_counts()
print(counts)
# Typical output: {'000': 498, '111': 526}

The resulting state, ∣000⟩+∣111⟩2\frac{|000\rangle + |111\rangle}{\sqrt{2}}, is the GHZ state. The histogram reads exactly as before: only two bars, 000 and 111, at roughly half each, with all six middle outcomes (001, 010, …, 110) absent. The three measurement results are perfectly correlated — measure the first qubit as 0 and the other two are instantly “locked” to 0. This is entanglement graduating from a two-party to a multi-party correlation, and it is the basic building block of multi-party quantum protocols such as secret sharing and quantum networks.

Try a destructive control while you are here: change the second CNOT’s control from qubit 0 to qubit 1 (qc.cx(1, 2)) and run again — new bars appear in the histogram. Derive which outcomes should show up before you run it; if your prediction matches, you genuinely understand how cascaded CNOTs act.

A Different View: Look at the State Itself, Without Measuring

So far we have known quantum states only through measurement counts — like judging a student by exam scores without ever seeing the answer sheet. Qiskit also offers statevector simulation, which prints the complete quantum state before any measurement:

from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

qc = QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)

sv = Statevector(qc)
print(sv)
# Statevector([0.70710678+0.j, 0.+0.j, 0.+0.j, 0.70710678+0.j])

The four complex numbers are the probability amplitudes of ∣00⟩,∣01⟩,∣10⟩,∣11⟩|00\rangle, |01\rangle, |10\rangle, |11\rangle: 0.707≈120.707 \approx \frac{1}{\sqrt{2}} sits on 00 and 11, with 01 and 10 exactly zero — matching ∣00⟩+∣11⟩2\frac{|00\rangle + |11\rangle}{\sqrt{2}} term by term. Squaring the amplitudes gives the probabilities (0.5, 0, 0, 0.5), the theoretical values behind the histogram. Note the difference from counts: the statevector is an exact mathematical object with no statistical fluctuation, while counts are an empirical distribution over repeated measurements. On real hardware you can never obtain the statevector — measurement collapses the state, and full tomography costs exponentially in the number of qubits. The statevector simulator exists only on classical machines; it is a privileged tool for learning and debugging.

Keep its cost in mind, too: a statevector stores 2n2^n complex numbers, so 30 qubits need roughly 16 GB of memory and 40 qubits reach the terabyte scale. That is exactly why quantum computation resists classical simulation, and where discussions of “quantum advantage” begin. As an exercise, rerun the GHZ circuit as a statevector and check which two of the eight components are non-zero — the payoff is concrete.

Summary

One Bell-state circuit teaches four things at once: the division of labor between qubits and classical bits, how gates create superposition and entanglement, why measurement is probabilistic, and the layer of noise that separates simulators from hardware. As a next step, drop the shots from 1024 to 100 and watch the statistical fluctuations grow — that is the starting point for understanding every quantum experimental result you will ever read.

References

Tags: Qiskitquantum circuitsBell statequantum computing basics