Fredkin gate

Also known as: CSWAP gate

On this page 7

The Fredkin gate, also called the CSWAP gate, is a three-qubit controlled-SWAP operation that exchanges the states of two target qubits if and only if the control qubit is in the state |1⟩. In quantum computing, and specifically within Quantum gates & circuits, it is one of the two classic reversible three-bit gates, alongside the Toffoli gate, and it is universal for classical reversible logic.

Edward Fredkin and Tommaso Toffoli introduced the gate in their work on conservative logic around 1982. Its defining property is that it conserves the number of ones between input and output, which made it a model for energy-efficient computation long before it became a standard element of quantum circuit libraries.

How the Fredkin gate acts on three qubits

The Fredkin gate leaves its control qubit unchanged and swaps the two target qubits only when the control is |1⟩. On computational basis states it maps |c, a, b⟩ to |c, a, b⟩ when c = 0 and to |c, b, a⟩ when c = 1. Because it only permutes basis states, its matrix is an 8 × 8 permutation matrix that differs from the identity in just two entries: it exchanges |101⟩ and |110⟩.

Linearity extends this rule to superpositions. A control qubit in an equal superposition produces an entangled state in which one branch holds the original order and the other branch holds the swapped order. This behavior is the basis of the swap test, the most common quantum use of the gate.

The truth table below lists the full classical action of the gate on all eight basis inputs.

Input c a bOutput c a bEffect
000000No change
001001No change
010010No change
011011No change
100100Swap of equal bits
101110Targets exchanged
110101Targets exchanged
111111Swap of equal bits
Fredkin gate truth table on basis states

Key properties of the CSWAP gate

Several algebraic properties make the gate useful in both classical and quantum design. It is self-inverse, so applying it twice restores the input, and it is Hermitian and unitary, so its adjoint equals itself. It is also conservative: the Hamming weight of the output always equals that of the input.

PropertyMeaningPractical consequence
ReversibilityEvery output has one inputNo information is erased
Self-inverseF × F = identityUncomputation is trivial
Number conservationCount of ones is preservedFits particle-conserving models
Classical universalityBuilds any Boolean functionUses ancilla and garbage bits
Clifford membershipNot a Clifford gateNeeds T gates when decomposed
Main properties and their practical consequences

Classical universality requires constant ancilla inputs. For example, setting one target to 0 turns the gate into an AND operation on the control and the other target, and duplicating a bit gives FANOUT. Universality does not extend to quantum computing on its own: the gate creates no superposition, so a universal gate set still needs a Hadamard gate or an equivalent.

Decomposition into native gates

Hardware rarely implements a three-qubit gate natively, so compilers decompose the Fredkin gate into one- and two-qubit operations. The standard construction wraps a Toffoli gate between two CNOT gates: a CNOT from target b to target a, a Toffoli controlled by c and a acting on b, and a final CNOT from b to a.

Because a Toffoli gate itself needs six CNOT gates and seven T gates in the common Clifford+T construction, the resulting circuit cost is significant. Published optimizations reduce the count to about seven two-qubit gates, and some platforms use a native controlled-SWAP or iSWAP family to shorten it further.

Implementation routeTwo-qubit gatesNotes
CNOT plus Toffoli plus CNOT8Simple textbook construction
Optimized Clifford+T circuit7Seven T gates, T depth of 3 or more
Native three-qubit pulse1 operationDemonstrated on some photonic and superconducting setups
Measurement-based variantVariesUses ancilla qubits and feedforward
Typical resource counts for implementing a Fredkin gate

These counts matter because each two-qubit gate adds error. On noisy devices a single Fredkin gate can raise circuit depth noticeably, so algorithm designers often avoid controlled-SWAP chains or replace them with cheaper constructions when the application allows it.

The Fredkin gate is easiest to place by comparing it with its neighbors in the gate library. The Toffoli gate flips a target bit, whereas the Fredkin gate exchanges two targets, which is why one conserves Hamming weight and the other does not.

GateQubitsActionConserves ones
SWAP gate2Always exchanges two qubitsYes
Fredkin gate3Exchanges targets when control is 1Yes
Toffoli gate3Flips target when both controls are 1No
CNOT gate2Flips target when control is 1No
Comparison with neighboring multi-qubit gates

Both three-qubit gates are universal for reversible classical logic, and each can be built from the other with extra gates. Choosing between them is mainly a matter of which operation the algorithm expresses naturally and which costs less on the target hardware.

Uses and limitations in practice

The leading application is the swap test, which estimates the overlap between two quantum states. A Hadamard on an ancilla, a controlled-SWAP across two registers and a second Hadamard yield a measurement probability of (1 + |⟨ψ|φ⟩|²) / 2 for outcome 0.

  • Fidelity estimation between prepared states in quantum machine learning and verification.
  • Quantum fingerprinting and state comparison protocols in communication complexity.
  • Controlled permutations in arithmetic circuits, sorting networks and reversible memory addressing.
  • Purity estimation of a mixed state using two identical copies.

The main limitations are cost and noise. A swap test on two n-qubit registers needs n Fredkin gates, so the two-qubit gate count grows quickly, and the test needs many repetitions because each run yields only one bit. Engineers frequently replace it with the destructive swap test, which uses Bell-basis measurements instead of controlled swaps.

Understanding it simply

Picture two cups on a table and a switch beside them. If the switch is off, the cups stay where they are. If the switch is on, the cups trade places. The Fredkin gate does exactly this with qubits. One qubit is the switch, and two qubits are the cups.

Nothing is lost along the way. The gate never throws information away, and running it twice puts everything back. In a quantum computer the switch can be on and off at once. That lets the gate compare two quantum states in a single clever step.

Applied in practice

A research team training a quantum classifier needs to know how similar a learned state is to a reference state. They prepare both states on two registers of four qubits each and add one ancilla qubit as the control. The circuit applies a Hadamard to the ancilla, then four Fredkin gates that pair matching qubits, then a final Hadamard.

After compilation for a superconducting processor, the four controlled swaps become about 28 two-qubit gates. The team runs 8,000 shots and measures the ancilla as 0 in 89 percent of runs. That result implies a squared overlap of roughly 0.78, which tells them the classifier needs more training before deployment. Because noise lowers the measured overlap, they also run a calibration circuit with identical states to correct the estimate.