Qiskit Tutorial for Beginners
Qiskit is IBM's open-source Python framework for quantum computing. It lets you build quantum circuits, simulate them locally, and run them on real IBM Quantum hardware. This tutorial takes you from zero to running your first quantum circuit.
Prefer no install? TalkinQuantum runs Qiskit-compatible circuits entirely in your browser. Build visually, get auto-generated Qiskit code, and export when you're ready for real hardware. Try it now →
Step 1 — Install Qiskit
You'll need Python 3.8+ installed. Open a terminal and run:
This installs the core Qiskit package and Aer — the local simulator. For IBM Quantum hardware access, you'll also need:
Verify the install:
1.x.x
Step 2 — Your First Circuit
Let's build a simple single-qubit circuit with a Hadamard gate. This puts qubit 0 into superposition and measures it:
from qiskit import QuantumCircuit # Create a 1-qubit, 1-classical-bit circuit qc = QuantumCircuit(1, 1) # Apply Hadamard gate to qubit 0 # Transforms |0⟩ → (|0⟩ + |1⟩)/√2 (superposition) qc.h(0) # Measure qubit 0 into classical bit 0 qc.measure(0, 0) # Print the circuit diagram print(qc.draw())
Output:
q: ┤ H ├┤M├
└───┘└─┘
c: 1/═════╝
Step 3 — Run on a Simulator
The local simulator (Aer) runs your circuit on your machine with no noise and no queuing:
from qiskit import QuantumCircuit from qiskit_aer import AerSimulator qc = QuantumCircuit(1, 1) qc.h(0) qc.measure(0, 0) # Create simulator and run sim = AerSimulator() job = sim.run(qc, shots=1024) # Get results result = job.result() counts = result.get_counts() print(counts)
The qubit is measured 1024 times. Because H creates a perfect 50/50 superposition, you get roughly 512 zeros and 512 ones. The exact split varies each run — that's quantum randomness.
Step 4 — A Two-Qubit Bell State
Now let's build something more interesting: a Bell state using H + CNOT. This creates quantum entanglement between two qubits:
from qiskit import QuantumCircuit from qiskit_aer import AerSimulator qc = QuantumCircuit(2, 2) # Step 1: superposition on qubit 0 qc.h(0) # Step 2: CNOT — control=0, target=1 # If qubit 0 is |1⟩, flip qubit 1 # Creates entanglement: (|00⟩ + |11⟩)/√2 qc.cx(0, 1) # Measure both qubits qc.measure([0, 1], [0, 1]) sim = AerSimulator() counts = sim.run(qc, shots=1024).result().get_counts() print(counts)
Notice: you only ever get '00' or '11'. Never '01' or '10'. The qubits always agree — that's entanglement.
Step 5 — Understanding Counts
The get_counts() dictionary maps measurement outcomes to how many times they occurred. Key points:
• String format: The result string is read right-to-left — '01' means qubit 0 measured 1, qubit 1 measured 0 (Qiskit's bit ordering convention)
• shots=1024: More shots = more accurate probability estimates. Standard is 1024 or 4096 for good statistics
• Statevector: Use save_statevector() before measurement to access the exact quantum state amplitudes
from qiskit import QuantumCircuit from qiskit_aer import AerSimulator import numpy as np qc = QuantumCircuit(2) qc.h(0) qc.cx(0, 1) # Save statevector before measurement qc.save_statevector() sim = AerSimulator() sv = sim.run(qc).result().get_statevector() print(np.round(sv, 3)) # [0.707+0j, 0+0j, 0+0j, 0.707+0j] # Amplitudes for |00⟩, |01⟩, |10⟩, |11⟩ # |amplitude|² = probability: 0.707² = 0.5 = 50%
Step 6 — Running on Real IBM Quantum Hardware
Once you've verified your circuit on the simulator, you can run it on real quantum hardware through IBM Quantum:
from qiskit_ibm_runtime import QiskitRuntimeService, SamplerV2 # Authenticate (get token at quantum.ibm.com) service = QiskitRuntimeService(channel='ibm_quantum', token='YOUR_TOKEN') # Get least-busy real backend with 2+ qubits backend = service.least_busy(operational=True, simulator=False, min_num_qubits=2) print(f'Using: {backend.name}') # Transpile circuit for real hardware's gate set and topology from qiskit import transpile qc_t = transpile(qc, backend, optimization_level=3) # Run and get counts sampler = SamplerV2(backend) job = sampler.run([qc_t], shots=1024) result = job.result() print(result[0].data.meas.get_counts())
Real hardware note: Real quantum computers have noise. You'll see some '01' and '10' results even in a Bell state — that's gate errors and decoherence, not a bug in your code. Aim for error rates below ~5% for a good result.
Common Qiskit Gates Reference
# Single-qubit gates qc.h(0) # Hadamard — superposition qc.x(0) # Pauli-X — NOT gate (flip) qc.y(0) # Pauli-Y qc.z(0) # Pauli-Z — phase flip qc.s(0) # S gate — π/2 phase qc.t(0) # T gate — π/4 phase qc.rx(0.5, 0) # Rotation around X axis # Two-qubit gates qc.cx(0, 1) # CNOT (CX) — control=0, target=1 qc.cz(0, 1) # Controlled-Z qc.swap(0, 1) # Swap two qubits # Three-qubit gates qc.ccx(0, 1, 2) # Toffoli — CCNOT, universal
Try this in your browser — no install needed
TalkinQuantum runs all of these circuits right in the browser. Build with drag-and-drop, get instant Qiskit code, and ask Quanta to explain any gate or result. Free forever.
Open the Circuit Builder →