Please enable JavaScript to use CodeHS

Quantum Computing

Quantum Gates and Circuits

Quantum programs look like music staffs: a wire for each qubit, and gates — X, H, Z — that twist and flip the state before the final measurement.

Quantum ~10 min Beginner friendly 6 of 10
The Big Idea

Three gates to know

A quantum program is a list of tiny instructions called gates. Each gate changes a qubit's state — its blend of possibilities. You write gates in order, read left to right, and finish with a measurement that snaps the blend into a definite 0 or 1.

Three gates cover most beginner circuits. X is the flip gate: it turns |0⟩ into |1⟩ and |1⟩ into |0⟩, like the classical NOT. H (the Hadamard gate) takes a solid state and blends it into an even 50/50 mix of 0 and 1. Z is the sneakiest one: it flips the phase of the 1 part. You can't see a phase flip by measuring — but it changes what the next gates do.

One catch: order matters. Applying H then X is not, in general, the same as X then H. Gates stack up like steps in a dance — doing them in a different order lands you somewhere different.

Simple definition: a quantum circuit is a sequence of gates applied to qubits in order, ending in a measurement that turns their blend of possibilities into a definite answer.


Try It

Build a one-qubit circuit

Here is a wire starting at |0⟩. Add gates with the buttons — up to six — then press Run measurement to simulate 100 runs and see how many come out 0 or 1.

Things to try: X alone always gives 1. H alone splits about 50/50. H then Z then H gives a solid 1 — Z's invisible phase flip steered the blend.

Circuit builder 0 / 6 gates
|0⟩ empty wire — add a gate below
State: |0⟩ — solid 0, measurement gives all 0s
100 shots
0
1

Honest footnote: this toy hides some math. A real qubit state tracks two numbers called amplitudes, and gates do more than toggle flags. But the picture — wire, gates, order, measurement — is the real notation scientists use.


Why It Matters

This is real quantum programming

The wire diagram you just built is not a kid version of quantum computing — it is the actual notation. Research papers, textbooks, and quantum software all draw circuits exactly this way: one wire per qubit, gate boxes left to right, a measurement symbol at the end.

Tools like IBM's Qiskit let anyone write quantum circuits in Python and run them on real quantum hardware for free. Professionals use the same X, H, and Z gates you just played with — their circuits just have more wires and more gates. The first time you push code to a real quantum chip, the diagram will already feel familiar.


Your Turn

Check your understanding

Predict: start at |0⟩, apply H then measure — about what fraction of 100 runs give 1? What if you apply H, then Z, then measure?

Your answer:

Sample answer: After H, about half — roughly 50 of 100 runs give 1. After H then Z it is still about half: Z only flips the hidden phase, which measurement cannot see on its own. To reveal the phase flip you need another gate — a second H turns the state back into a solid 1.


Check Yourself

Quick quiz

1. Which gate turns |0⟩ into |1⟩?

2. Which gate puts a solid state into a 50/50 blend of 0 and 1?

3. One circuit applies H then X. Another applies X then H. Same thing?

Keep learning about quantum computing

You can build circuits now — so when do they actually beat a regular computer? Next up: the kinds of problems where quantum interference gives a real speedup.

Part of the Quantum Computing tutorial series.