How quantum gates forge superposition and entanglement
- Vitalii Manoilo
- May 8
- 8 min read
Today, we will see how researchers and engineers can manipulate qubits to get the results from a quantum computer. We will focus on superconducting quantum computers. We can draw some analogies from the classical computer, like circuits, gates, and wires, which will help us ground these new ideas.
Steering qubits with quantum gates
In the previous post, I explained the unique characteristics of a qubit and its advantages over a classical bit. Rather than a single 0 or 1, a qubit can occupy any point in a continuous superposition of both states and, when measured, still yields a definite 0 or 1. Superposition allows quantum algorithms to explore multiple computational paths at once, which underpins quantum parallelism in specific algorithms..
But one qubit is insufficient to attain such outperformance; you need many entangled qubits, maintained with extremely low noise, to preserve accuracy. I will cover quantum error correction later when I explore algorithms. For now, let’s see how quantum gates organize and transform qubit states.
Earlier, I mentioned that a qubit could be written as:
and each state value |0⟩ or |1⟩ can be written as column vectors:
So, the equation can also be written as a vector of a single qubit with the amplitudes:
You might wonder: why all this math? Why not describe everything in plain English?
I realized that quantum mechanics is fundamentally linear algebra, so the math isn’t optional.
In classical computing, there are logical gates, such as AND, OR, and NOT, which I briefly touched on in my post about classical computers. You may be surprised, or maybe not, to learn that quantum circuits also use analogues of classical gates, but they are implemented via mathematical operations on qubits.
Before adding gates, let's start with the simplest quantum circuit: a wire. It carries a qubit unchanged from input to output. It's just a connection, like any other wire.
Graphically, it's represented like a line:
If we take |0⟩ qubit, nothing will happen to it. With |1⟩ qubit, same thing.
Now, let's explore our first quantum gate, a NOT gate, that is added to our circuit. In quantum mechanics, it is called Pauli-X or simply X, after the physicist Wolfgang Pauli. The Pauli-X gate behaves exactly as you can expect from a NOT gate; it flips the |0⟩ <-> |1⟩ state of a qubit.
Here is a visual representation of it on the circuit:
But you remember that in classical circuits, logic gates are built from transistors arranged as logic gates, which change the electric current; 0 means "no flow", and 1 means "there is flow".
In quantum mechanics, every gate can be represented as a matrix. In particualar Pauli-X is a 2x2 matrix:
To simulate the changing state of a qubit, we need to multiply the qubit vector by the gate matrix. Let's take our circuit example where we simulate flipping |0⟩ to |1⟩.
So, we indeed flipped the state with linear algebra.
To multiply a matrix (A) by a vector (x), multiply each entry in a row by the corresponding entry in the vector, then add the results for that row:
Reversibility principle: why all quantum moves can be undone
One of the significant differences between classical and quantum gates is that quantum gates should follow the reversibility principle, meaning you can always tell what the original state of the qubit was before the gate was applied.
Most classical logic gates are irreversible, meaning they lose input information. To see this difference in practice, first, we need to review a classical XOR gate.
The XOR gate uses two bits as input and outputs one bit. The output bit will be 1 only if two input bits have different values: 1 and 0, or 0 and 1. Otherwise, the output is 0. For better understanding, it can be represented as a table:
Input A | Input B | Output |
---|---|---|
0 | 0 | 0 |
1 | 0 | 1 |
0 | 1 | 1 |
1 | 1 | 0 |
Now, by looking at the output, there is no way of knowing the original values of Input A and Input B. Was it 1 and 0, or 0 and 1 — no idea. If you take other classical gates, like AND and OR, you will notice that the output is irreversible, too.
In quantum computing, the best analog for the XOR gate is the CNOT, controlled-X, or controlled Pauli-X gate. Like the classical XOR gate, the CNOT gate also has two inputs: control and target. The output value depends again on both inputs, but is slightly different. The CNOT gate flips the state of the target qubit only if the state of the control qubit is |1⟩. Otherwise, the state of the target doesn't change.
Control (Input) | Target (Input) | Control (Output) | Target (Output) |
|0⟩ | |0⟩ | |0⟩ | |0⟩ |
|0⟩ | |1⟩ | |0⟩ | |1⟩ |
|1⟩ | |0⟩ | |1⟩ | |1⟩ |
|1⟩ | |1⟩ | |1⟩ | |0⟩ |
You can notice that, by looking at both outputs (control and target), you can always tell what the original states of the qubits were. So, the principle of reversibility is satisfied.
To prove the behaviour of the CNOT gate, we can use its matrix representation, a 4x4 matrix and multiply it by a 4x1 vector of two qubits:
If we accept the 4×4 matrix representation of the CNOT gate as given, the next question is: where does the 4×1 input vector come from? There is a simple formula: For an n-qubit system, the state space is a vector of length 2^n. Each state corresponds to one standard basis vector with a single 1 and all other entries 0.
If you take a system of two qubits — |ab⟩ (where a is the first qubit, and b is the second), there are four possible states: 2^2 = 4, which are |00⟩, |01⟩, |10⟩, and |11⟩.
Each state maps to a binary number, an index in the vector. As in programming, the Hilbert-space labeling starts with zero: 0, 1, 2, 3, etc. So, in our example |00⟩ = index 0, |01⟩ = index 1, |10⟩ = index 2, and |11⟩ = index 3. So, each two-qubit state can be represented as these vectors:
Now, let's see how the CNOT gate affects the system where |1⟩ is a control, and |0⟩ is a target (the |10⟩ example from above).
Graphically, the |10⟩ circuit with a CNOT gate looks like this:
Let's do the multiplication of the matrix and vector:
As you can see, the new vector corresponds to the 2-qubit system where the target was flipped from |0⟩ to |1⟩, given the control is |1⟩. You can verify the remaining cases by multiplying the CNOT matrix with each 4×1 input vector.
Going back to the reversibility principle, every quantum gate is invertible: you can recover inputs from outputs and also ‘undo’ any operation by applying the same gate again. Let's use a simple Pauli-X gate and apply it twice to prove this.
The circuit with two Pauli-X gates would look like this:
To recover the original state of a qubit, let's first find the product of two matrices of the Pauli-X gates by multiplying them. The result is the following 2x2 matrix:
It is also called the Identity matrix.
Now, if you multiply the vector of the qubit in |0⟩ state with the Identity matrix, the result won't change.
But actually, it did change twice, from |0⟩ to |1⟩ to |0⟩ again. We don't see it because we multiplied by the product of two Pauli-X matrices. In other words, applying the Pauli-X gate twice is the same as multiplying by the Identity matrix, so you always return to the starting state. Recognizing this lets you simplify circuit analysis.
Now, what will happen if we apply the CNOT gate twice? The circuit will look like this:
Not surprisingly, the qubit states (control and target) should be reversed to their original state before the first CNOT gate is applied. The multiplication is a bit harder because we deal with two qubits and a 4x4 matrix.
Let's first find a product of two CNOT gates. The result is this matrix, which is also the Identity 4x4 matrix.
If you multiply the Identity 4x4 matrix with the 4x1 vector of |10⟩, you will notice that the vector won't change.
Again, similar to our calculation with two Pauli-X gates, the original states of control and target qubits were reversed — the reversibility principle is satisfied.
Hadamard gate: the superposition switch
One of the most essential gates in quantum computing is called the Hadamard Gate, named after Jacques Hadamard. And why is it so important? It's because this gate brings the qubit into a superposition.
It can also be represented as this matrix:
If you apply the H gate to a |0⟩ state qubit and a |1⟩ state qubit, the vectors will become as follows:
I also used Dirac notation (middle part of the expressions) to illustrate better that the qubits are in a superposition.
In the superposition state, both |0⟩ and |1⟩ have equal probability (50% each) when measured. Remember that when we calculate probability, we use the modulus of amplitudes, so the negative sign in |1⟩, while in superposition, won’t affect the measurement probabilities.
What will happen if we apply two Hadamard gates to a qubit? We should return the qubit to its original state according to the reversibility principle.
As you can see, the result is the same Identity 2x2 matrix that we saw in our example of two Pauli-X gates, because we deal with only one qubit, not two, like in the CNOT example.
You already know that multiplying |0⟩ or |1⟩ state vectors with the Identity matrix results in the same state — the reversibility principle is again satisfied.
How qubits link across space
Now you understand how some of the quantum gates affect the qubit states. However, we have reviewed only a calculation of a single qubit or two single qubits in the example with the CNOT gate. This is pretty much the same behaviour as in classical computers, where gates control individual bits; apart from the linear algebra calculations, the behaviour of gates is somewhat similar.
What gives quantum computing such a superpower is not just how qubits can be in a superposition individually, but also how one qubit can influence the state of another qubit, in other words, be in a joint superposition. This behaviour in quantum mechanics is called entanglement.
When two qubits are entangled, one qubit's measurement instantaneously determines the second qubit's state. Or better say, if you measure one qubit, you automatically know the value of both the one you measure and the entangled one.
Imagine two kids in different rooms; they can't see or interact with one another. Now, one kid walks out wearing some kind of pants, and instantaneously, without anyone doing anything, you know what pants the other kid is wearing. It’s not that someone rushed in to change the other’s pants right after the first kid appeared, nor did the kids agree beforehand. Somehow, their pants were just mysteriously coordinated. The pants might be the same or different colors, depending on how the coordination was set up.
In this analogy, the kids represent qubits in entanglement, and when you see one kid's pants (measure the first qubit), you instantly know the other's pants, no matter how far apart they are.
How Bell pairs share outcomes
So, how can we represent this entanglement on a circuit? We need to use two quantum gates we just learned: the Hadamard gate and the CNOT gate. The Hardamard gate is responsible for bringing the first qubit into a superposition, and the CNOT gate will change the target qubit (our second qubit from the entangled pair) based on the state of the first (control) qubit.
The circuit will look like this:
No calculation is needed to prove this behavior since we’ve already discussed how each gate works individually. We can look at the circuit and reason it out.
Remember: the Hadamard gate puts the qubit into a superposition: it's now in both |0⟩ and |1⟩ states with 50% probability. That means the control qubit in our circuit has a 50% chance of being in |1⟩, which activates the CNOT gate and flips the target qubit. Note that both qubits start in |0⟩, so there's a 50% chance the target will flip to |1⟩, purely due to the superposition of the control qubit.
And that simple two‑gate sequence is all it takes to weave two qubits into a Bell pair, one of the purest examples of quantum correlation. The combination of superposition and entanglement gives us the essential building blocks that make quantum computing truly powerful. In the following few articles, I’ll begin exploring real-world use cases and algorithms that rely on these exact mechanics, including how quantum systems search faster, optimize smarter, and simulate nature more precisely than classical ones ever could.