top of page

The Qubit: Both 0 and 1 — Your First Step into Quantum Programming

Writer: Sevdanur GENC
Sevdanur GENC
5 days ago
3 min read

Everything on your computer — this article, your photos, your favourite song — is ultimately made of billions of bits. Each bit is either 0 or 1. Like a light switch: on or off. There is no third option.


But what if there were? What if a bit could behave as both 0 and 1 until you looked at it? This isn't science fiction. It is exactly how the qubit works — the building block of the quantum computers you can already access in the cloud today.


In this first QBlog post we'll build an intuition for the qubit, simulate one on your own laptop with Python and Qiskit, and watch that strange moment called "measurement" happen with our own eyes.


Bit vs. qubit: the coin analogy


Think of a classical bit as a coin lying on a table: heads or tails. A qubit is more like a coin spinning in the air. While it spins, the question "heads or tails?" has no single answer — it is a blend of both. Only when you catch it — when you measure it — does it land on one side.


Mathematically, the state of a qubit is written as:


|ψ⟩ = α|0⟩ + β|1⟩

α and β are numbers called amplitudes. When you measure the qubit, the probability of seeing 0 is |α|² and the probability of seeing 1 is |β|². Naturally, the two always add up to 1.


The Bloch sphere: a map of the qubit


There is an elegant way to picture every possible qubit state at once: the Bloch sphere. The north pole is |0⟩, the south pole is |1⟩. Every point on the surface is a valid qubit state. Points on the equator are perfect 50/50 superpositions: measure them and you get 0 half the time and 1 the other half.


That is exactly what the arrow in the cover animation shows: the closer it gets to the north pole, the more likely 0 becomes; the further south, the more likely 1. The bars on the right track the live probabilities.


Your first quantum program


First, install the libraries:


pip install qiskit qiskit-aer matplotlib

Now let's create a single qubit and apply a Hadamard (H) gate. The H gate takes a qubit in |0⟩ from the north pole down to the equator:


from qiskit import QuantumCircuit
from qiskit.quantum_info import Statevector

qc = QuantumCircuit(1)
qc.h(0)                      # superposition

state = Statevector(qc)
print(state.probabilities_dict())   # {'0': 0.5, '1': 0.5}

The output tells us the qubit is half 0 and half 1. But careful: this does not mean the qubit is "secretly 0 and we just don't know". Both possibilities genuinely coexist.


Measurement: where the magic breaks


Now let's measure the same circuit 1000 times:


from qiskit import transpile
from qiskit_aer import AerSimulator

qc.measure_all()
sim = AerSimulator()
counts = sim.run(transpile(qc, sim), shots=1000).result().get_counts()
print(counts)   # e.g. {'0': 514, '1': 486}

Every single measurement gives one answer: 0 or 1. But across 1000 measurements we see a roughly even split. That is the heart of quantum mechanics: a single outcome is random, yet the statistics are perfectly predictable.


Tuning the probability


The H gate takes us exactly to the equator. What if we want a qubit that gives 0 with 75% probability and 1 with 25%? We use an Ry(θ) rotation; the angle θ swings the arrow from north to south:


  • θ = 0° → P(0) = 100%

  • θ = 60° → P(0) = 75%

  • θ = 90° → P(0) = 50%

  • θ = 180° → P(1) = 100%


This simple observation will become the foundation of quantum machine learning later in the series: by writing data into these angles, we can "teach" a quantum computer.


Why it matters


A single qubit doesn't do much on its own. The magic starts when qubits come together: n qubits can hold a superposition of 2ⁿ states at once. 300 qubits can represent more states than there are atoms in the observable universe. But to use that power, the qubits need to be entangled — which is the subject of the next post.


Summary


  • A classical bit is 0 or 1; a qubit can be a superposition of both until measured.

  • A qubit's state is a point on the Bloch sphere.

  • Each measurement yields a single result; probabilities only emerge through repetition.

  • The H gate creates an equal superposition; Ry(θ) gives a tunable probability.



All the code for this post is on GitHub — download it, run it and play with the parameters.



Next up: Entanglement: Spooky Action at a Distance — we'll build the link that bothered Einstein with our own hands.


 
 
 

Comments


©2026 by Sevdanur Genc

bottom of page