BB84 worked by hand: a short run from start to key

Follow a small run step by step, then see how the numbers scale up to thousands of photons.

9 min read · reviewed December 2026

Photons and measurements

Alice sends twelve photons. For each she has a bit and a basis, and Bob has a basis. The table is generated by the lab’s simulator, so you can reproduce it by setting 12 photons and no Eve.

A 12-photon run with no Eve and no noise (seed 7), produced by the lab’s own simulator.
#Alice bitAlice basisBob basisBob bitKept
10+×0no
20++0yes
30×+0no
41+×0no
50+×0no
61××1yes
71×+0no
80++0yes
90+×0no
100++0yes
110××0yes
121××1yes

Sifting

Keep only the rows where the two bases agree. About half the rows survive. Where the bases differ, Bob’s bit is a coin flip, and both sides throw it away.

Checking

Alice and Bob pick a few of the surviving positions at random and read their bits out loud. With no Eve and no noise, all of them match. With Eve intercepting every photon, about a quarter will not.

Scaling up

With 12 photons the sample is far too small to say anything. Real runs use thousands or millions of photons. The table shows two seeded runs at 2 percent noise.

Where the photons go, in two seeded runs with 2% channel noise and a quarter of the sifted bits compared.
Photons sentSiftedComparedMeasured errorSecret bits (asymptotic)
10000492412502.0%2634
10000050110125002.1%26601

The remaining steps

The leftover bits go through error correction and privacy amplification, as in the previous guide. What comes out is a key both sides share and Eve, within the model, knows almost nothing about.

Try it

Questions

Why does the estimate fluctuate so much for small runs?

Because each compared bit is a random sample. With 20 bits, one error moves the estimate by 5 percentage points.

Does the seed button repeat my run?

Each press uses a new seed, so you see a different random run. The same seed always gives the same run.

Can I set up a run that aborts?

Yes. Add Eve at 100 percent and use many photons. With only a few photons the comparison sample is too small to be reliable, so the result varies from run to run.

Read next

Sources and further reading

Check the original sources for exact citations.