Multi-Controlled Gates and Their Decompositions
A controlled- gate is the smallest conditional in the quantum circuit model: it fires a unitary on a target only when one control reads . A multi-controlled gate raises the bar — acts as the identity on the whole -dimensional space except on the single sector where all controls are , where it applies to the target. In the computational basis it is block-diagonal: the identity on every control string but the all-ones one, which carries . This is the natural language of conditional logic — "do only if every one of these predicates holds" — and it is how oracles, arithmetic carries, and the Grover reflection are written down. But no hardware executes for natively; a backend offers one- and two-qubit gates and nothing more. The entire subject is therefore a compilation problem: how to build a high-fanin conditional out of a fixed universal set of CNOTs and single-qubit rotations, and how cheaply. The answer has three moving parts, and they organize everything below. First, the algebra: a doubly-controlled splits into single-controlled square roots and with , which interfere so that two controls behave like a logical AND. Second, the recursion: that same interference pattern, applied with multi-controls in place of single controls, reduces to smaller multi-controlled gates. Third, and decisively, the space–time tradeoff: the gate count of a multi-controlled NOT depends almost entirely on the ancilla budget — clean scratch qubits buy a linear circuit, a single borrowed qubit still buys linear, and zero scratch forces quadratic. The reference for all of it is Barenco et al. (1995), which proved two-qubit gates universal and gave the sharp ancilla–gate tradeoffs a fault-tolerant compiler still uses.
- A multi-controlled gate applies to a target only when all controls are , leaving every other basis state untouched; the smallest nontrivial case is the Toffoli, .
- Any can be built from CNOTs and single-qubit gates alone — but the cost is governed by the ancilla budget, not by .
- The square-root identity turns a doubly-controlled into single-controlled , and a CNOT between the controls, whose interference encodes the logical AND.
- With clean ancillas, costs Toffolis (a compute–fire–uncompute AND ladder); with one borrowed dirty ancilla it is still ; with none it is (Barenco et al.).
- Controlling on instead of is free — sandwich that wire between two gates — so the whole theory needs only the all-ones case.
- These primitives are the guts of the Grover diffusion operator, modular arithmetic in Shor's algorithm, reversible oracle synthesis, and the Fredkin controlled-SWAP.
- Key idea: every multi-controlled gate is built by recursion on the number of controls — a control on splits via into interfering controls on and , and a high-fanin control collapses to a chain of Toffolis that compute the AND of the controls into ancillas; the gate cost is set by the ancilla budget, not by .
Every multi-controlled gate is built by recursion on the number of controls: a control on splits using into controls on and that interfere as a logical AND, and a high-fanin control collapses to a chain of Toffolis that compute the AND of the controls into ancillas. The gate cost is governed by the ancilla budget, not by itself.
Where this lives today
Multi-controlled gates are the connective tissue of every serious quantum algorithm, and their compilation is an active optimization frontier. In Grover's search the diffusion operator is a multi-controlled- on all qubits, so each of the roughly iterations pays for one ; the choice of ancilla budget for that gate sets the circuit's width-versus-depth balance. In Shor's algorithm the modular-exponentiation core — the dominant cost of fault-tolerant factoring — is assembled from controlled adders and comparators, each a nest of multi-controlled gates, and Gidney and Ekerå's 2021 estimate for breaking 2048-bit RSA is dominated by roughly Toffolis, every one of which is a two-control gate compiled by exactly the constructions here. Reversible oracle synthesis lays down one multi-controlled- per satisfying assignment of a Boolean predicate, so SAT-style oracles and lookup tables are literally stacks of gates. The Fredkin controlled-SWAP, a Toffoli flanked by CNOTs, powers the SWAP test that estimates state overlap for fidelity and entanglement diagnostics. And because the non-Clifford cost dominates on a surface-code machine, cheaper multi-controls are a live research target: measured "temporary AND" constructions spend only four gates per Toffoli when the result will be uncomputed, borrowed-ancilla and catalytic schemes trade a spare qubit for depth, and layout-aware synthesis under lattice surgery shaves the cost of every high-fanin conditional in the machine.
The physical picture
Read a multi-controlled gate as a logical AND wired to an enable line: the target gate fires only when every control reads . There are two ways to realize that AND from two-qubit pieces, and both are the whole subject. The first is interference. If is a square root of , so , then a and a placed on the target and toggled by a CNOT between the two controls arrange themselves so that both controls set apply , exactly one set applies , and neither set does nothing. The controls never touch the target directly; they interfere two half-turns into either a full turn or nothing. The first figure is this mechanism in full, with the four control settings tabulated.
The second way to realize the AND is storage. Compute the conjunction of the controls step by step into a scratch (ancilla) qubit with a ladder of Toffoli gates — , then , and so on — use the last scratch qubit as one ordinary control on the target, then run the ladder backward to erase every scratch qubit to . Bennett's uncomputation principle guarantees the ancillas come back clean and disentangled, so they factor out and the controls are undisturbed. This trades qubits for gates: with enough clean scratch the whole thing is linear in ; with none you must fall back on nested square roots and pay quadratically. The second figure is the object a compiler actually costs — the ancilla ladder and the three scaling regimes it lives in.
Finally, conditioning on instead of costs nothing: since , sandwiching that control wire between two gates converts a zero-control into a standard one-control, adding no two-qubit gates and no ancillas. The whole theory therefore needs only the all-ones-controlled case, and everything else is a change of basis on the control wires.
The core equations
A multi-controlled gate is defined by what it does on each control string: nothing, unless the string is all ones, in which case the target sees . Written with projectors onto the control register, this is a sum that is the identity on every sector but one.
where: — number of control qubits; — projector onto the control bitstring ; — the all-ones string; — the Iverson bracket, equal to when the condition holds and otherwise; — the single- (or multi-) qubit target unitary. Reading: the operator is block-diagonal in the control basis — the identity on the -dimensional complement, and on the two states . The smallest nontrivial case, and , is the Toffoli gate, the reversible AND that anchors the whole recursion. It writes the conjunction of the controls onto the target, modulo 2.
where: — control-qubit values in ; — target-qubit value; — addition modulo 2 (XOR); — logical AND. Reading: the target flips exactly when both controls are set; fixing leaves in the target, a reversible AND. The algebraic heart of single-target multi-control is the square-root identity: a doubly-controlled is built from single-controlled square roots and a CNOT between the controls, provided .
where: — the gate on qubit controlled by qubit ; — CNOT from control 1 onto control 2; — a square root of , ; qubits are controls and is the target. Reading: read right-to-left — the inter-control CNOT toggles which of , is live so that only the all-ones branch accumulates . Reducing to single controls needs one more ingredient: a single-controlled itself, from the Z-Y (ABC) decomposition of a one-qubit unitary. Any factors so that a CNOT-conjugated pair of rotations rebuilds it, with the global phase pushed onto the control.
where: — single-qubit unitaries with ; — global phase of ; — a phase gate on the control that absorbs the global phase. Reading: on control the target sees ; on control it sees , and restores the phase. For a multi-controlled NOT with clean ancillas, the cost is a linear count of Toffolis: compute the AND upward, fire once, uncompute downward.
where: — clean ancillas, all starting and ending in ; the ladder computes into , fires the target, then reverses. Reading: Toffolis build the conjunction, one CNOT fires the target, and Toffolis erase the scratch — linear in . Without any scratch space the same reduction must be done by nested square roots, and the cost climbs to quadratic — the best general bound for an arbitrary target unitary.
where: elementary — CNOT plus single-qubit gates; — quadratic scaling with zero scratch; — the linear cost restored by a single borrowed (dirty) ancilla. Reading: even one work qubit of unknown state, returned to that state at the end, collapses the quadratic back to linear (Barenco et al.). The Fredkin gate — the controlled-SWAP — shows how a controlled two-qubit operation reduces to a single Toffoli flanked by CNOTs, the template for turning any controlled permutation into multi-controlled NOTs.
where: — CNOT between the two swap targets; — a Toffoli with control and controls/target on qubits . Reading: the outer CNOTs express SWAP as three CNOTs, and controlling the middle one promotes it to a controlled-SWAP.
The goal is to prove the central identity of the whole subject — that a doubly-controlled unitary is exactly the five-gate sequence of equation (3), built from single-controlled square roots with and one CNOT between the controls — by tracking the operation applied to the target for each of the four control settings and showing it is on three of them and on the fourth. This is the base case of every multi-control recursion, so its correctness underwrites everything downstream. We read the circuit right-to-left, remembering that the inter-control CNOT changes which controlled- is active.
Step 1. Take both controls unset, . The first gate is inactive (control 1 is ); the CNOTs are inactive (control 1 is ), so qubit 2 stays ; and both and are inactive (control 2 is ). The target sees the identity. Why: with no control set, no controlled gate fires, and the circuit must reduce to — the trivial but necessary boundary.
Step 2. Take . Now fires and applies to the target. The first CNOT flips qubit 2 to , so fires and applies ; the second CNOT flips qubit 2 back to , so the final is inactive. The target sees . Why: this is the interference at work — a lone control triggers exactly one and one , which annihilate by unitarity regardless of what is.
Step 3. Take . Here is inactive; the CNOTs are inactive (control 1 is ), so qubit 2 stays throughout; thus then both fire, giving . Why: the symmetric single-control case, again cancelling to the identity — the two off-diagonal control settings are the ones the AND must reject.
Step 4. Take both controls set, . Now applies . The first CNOT flips qubit 2 to , switching off ; the second CNOT flips qubit 2 back to , switching on the final . The target sees . Why: the all-ones branch is the only place two 's meet with no intervening , so it is the only branch that accumulates — and is the sole constraint on . *Verified: the four settings give ; equivalent to multiplying the four (or block) factors, and matches Nielsen & Chuang §4.3, Fig. 4.8 and Barenco et al. (1995), Lemma 6.1.*
Go deeper · Derivation B · 2 minMulti-controlled NOT with a clean ancilla ladder
The goal is to build from Toffoli gates using clean ancillas, and to prove that every ancilla returns to so that the controls and target are left in exactly the state a native would produce. The construction is a compute–fire–uncompute sandwich: it stores the running conjunction of the controls in the ancillas, uses the final ancilla as a single ordinary control on the target, and then reverses the storage step so no scratch information survives. This linear-in- circuit is the workhorse whenever qubits are plentiful, and it is why the Toffoli is the atom of multi-control.
Step 1. Compute the conjunction. Apply a Toffoli with controls and target , giving ; then a Toffoli with controls and target , giving ; continue up to . This is Toffolis. Why: each Toffoli ANDs one more control into the running product, so after of them the last ancilla holds the full conjunction — the single bit that decides whether the target fires.
Step 2. Fire the target. Apply one CNOT with control and target , flipping exactly when , i.e. when all controls are set. Why: the whole point of computing the AND into a scratch qubit was to reduce an -fold control to a single control, which one CNOT can act on.
Step 3. Uncompute. Apply the same Toffolis of Step 1 in reverse order. Because each Toffoli is its own inverse, this drives back to , leaving no entanglement between the ancillas and the data. Why: Bennett's uncomputation principle — reversing the compute step disentangles the scratch so it factors out cleanly and can be reused, which is exactly what "clean ancilla" means.
Step 4. Count and confirm. The tally is Toffolis plus one CNOT, with ancillas, and the ancillas begin and end in for every control input, so they contribute a trivial tensor factor. The net action on controls and target is precisely . Why: the resource count is linear in , the best possible scaling, and the ancilla-reset check is what guarantees the circuit is a genuine and not merely one that agrees on a subspace. *Verified: ancillas return to for all control inputs and the target flips iff the control string is ; count matches Barenco et al. (1995), Lemma 7.2.*
Go deeper · Derivation C · 2 minThe ancilla-free recursion and its quadratic cost
The goal is to derive the recursion that builds from smaller multi-controlled gates with no scratch qubits at all, and to show the resulting gate count is — the price of zero ancillas. The idea is to apply the square-root pattern of equation (3) but with the two single controls replaced by an -fold control and a single control, so that the recursion peels one control off at a time. Each peel costs a smaller multi-controlled NOT, and summing those linear-per-level costs over levels produces the quadratic bound that Barenco et al. proved optimal for a general target without work qubits.
Step 1. Split the controls. Choose with and write, in exact analogy with the doubly-controlled identity, , where qubit plays the role of the second control and qubits the first. Why: the same interference argument as the base case shows the target sees only when qubit and all of are set, so this is a correct .
Step 2. Identify the pieces. The two single-controlled gates and cost a constant number of elementary gates each (via the ABC decomposition of equation (4)); the two gates and the one are strictly smaller multi-controlled gates that recurse. Why: peeling one control off has reduced an -control problem to -control problems plus constant overhead, which is the signature of a linear recursion depth.
Step 3. Write the recurrence. Let be the elementary-gate cost of . Then
because an ancilla-free is itself linear-cost at each level of the outer recursion. Why: the multi-controlled NOTs, unlike the general , admit a cheaper ancilla-free treatment, so the dominant per-level cost is the from the two gates.
Step 4. Solve. Summing an per-level cost over the levels of the recursion gives . Adding even one clean or borrowed ancilla short-circuits this by replacing the nested square roots with the linear AND ladder of the previous derivation. Why: the quadratic is entirely a consequence of having no place to store the running conjunction; storage is what turns into , which is the whole moral of the ancilla budget. *Verified: the all-ones setting yields and every other setting yields inductively; the ancilla-free and single-ancilla scalings are Barenco et al. (1995), Lemma 7.5 and Corollary 7.4.*
Limiting cases
The cost of a multi-controlled NOT is not one number but a spectrum set by how much scratch space you are willing to spend.
| Case | Result | Meaning |
|---|---|---|
| constant cost | A single controlled- from the ABC decomposition — the base of the recursion, a fixed handful of CNOTs and rotations. | |
| , | Toffoli, CNOTs | The reversible AND; exact ancilla-free compilation costs six CNOTs and seven non-Clifford gates. |
| clean ancillas | Toffolis | The linear AND ladder; ancillas returned to . Lowest gate count, highest qubit count. |
| borrowed dirty ancilla | elementary | A single unknown-state work qubit, restored at the end, still buys linear cost (Barenco Cor. 7.4). |
| No ancilla | elementary | Nested square-root recursion; is the best general scaling for arbitrary with zero scratch. |
Worked examples
1 · Resource count for a five-control NOT (fully worked)
You need a (five controls, one target) inside a Grover oracle. Cost it two ways: with clean ancillas, and note what changes with none. Assume the standard exact Toffoli of seven gates.
Step 1. Count ancillas. A clean AND ladder for controls needs clean ancillas, each prepared in and returned to . These are scratch qubits the surrounding circuit must be able to spare.
Step 2. Count Toffolis. The ladder computes the conjunction with Toffolis, fires the target with one CNOT, and uncomputes with more Toffolis, for Toffolis plus one CNOT. The CNOT is Clifford and essentially free in the fault-tolerant cost model.
Step 3. Convert to -count. Each exact Toffoli spends non-Clifford gates, so the -count is gates — 56 distilled magic states for one five-control NOT. This is the number a surface-code resource estimate actually pays.
Step 4. Compare with no ancillas. Strip the scratch and the same must be built by the nested square-root recursion, whose cost is elementary gates rather than — a strictly worse scaling that grows quadratically as the control count rises. With 4 clean ancillas: 8 Toffolis ≈ 56 T gates, linear; with none: , quadratic. The ancilla budget, not , decides the bill.
2 · A doubly-controlled phase gate from the square-root construction (fully worked)
Build the doubly-controlled phase gate , where , using the square-root identity. Find the square root , verify the four control cases, and state the net action on the computational basis.
Step 1. Find the square root. We need with . The gate is exactly this: , so . Thus , a native, cheap single-qubit gate — no compilation of an exotic root is needed.
Step 2. Write the circuit. Substituting into equation (3), : two single-controlled 's, one controlled , and two CNOTs between the controls. Every piece is a controlled phase, so this is a purely diagonal circuit.
Step 3. Verify the four cases. Both controls : identity. One control set: a and a meet on the target and cancel, . Both controls set: the inter-control CNOT switches off the , leaving on the target. So applies to the target only on the all-ones control setting. The four cases give — exactly .
Step 4. State the net action. Since multiplies target- by and fixes target-, the whole gate multiplies the single basis state by and leaves the other seven fixed: . A controlled-controlled phase built from three -type gates and two CNOTs — the same construction that, with , gives the Toffoli.
3 · Turning a zero-control into a one-control
The Grover diffusion operator needs a phase flip on — a multi-controlled gate that fires when every qubit is , the opposite of the standard convention. Show how to build it from an all-ones multi-controlled gate.
Step 1. State the target operation. The diffusion reflection (up to Hadamard conjugation) is a that fires on rather than — every control is conditioned on .
Step 2. Flip each control basis. Apply an gate to every control wire before the multi-controlled gate and another after. Since , the pre-'s map the desired all-zeros condition onto the standard all-ones condition the hardware construction expects.
Step 3. Insert the standard gate. Between the two layers of 's, place the ordinary all-ones (itself a conjugated by a Hadamard on the target). The post-'s undo the basis flip on the controls, restoring them.
Step 4. Count the overhead. The conversion added single-qubit gates and no two-qubit gates and no ancillas. Conditioning on is free up to single-qubit 's, so the all-ones construction covers every control polarity — which is why the theory only ever solves the all-ones case.
Physics of the portrait
Multi-controlled gates are where an abstract universality theorem became an engineering discipline, and the person who did most to make that happen is the physicist whose name is on the field's founding decomposition paper.
Origins · 1 minAdriano Barenco and how this was discovered
Adriano Barenco did his doctoral work at the University of Oxford in the early-to-mid 1990s, in the group around Artur Ekert and David Deutsch that turned quantum computation from a curiosity into a research program. His single-author 1995 paper "A universal two-bit gate for quantum computation" showed that almost any two-qubit gate is by itself universal — a sharp strengthening of the picture that had required special gate sets — and the family of general two-qubit gates he analysed is still called the Barenco gate. That same year he was the lead author of "Elementary gates for quantum computation" (Physical Review A 52, 3457), written with Bennett, Cleve, DiVincenzo, Margolus, Shor, Sleator, Smolin and Weinfurter, which became the standard reference for compiling arbitrary unitaries into CNOTs and single-qubit rotations. It is that paper that established the multi-control results this article rests on: the controlled- square-root construction, the ancilla-assisted linear , the single-borrowed-ancilla linear bound, and the ancilla-free scaling. The work is quietly foundational — every quantum compiler, every fault-tolerant resource estimate that quotes a Toffoli or count, is downstream of the tradeoffs Barenco and his collaborators made explicit. A set of lemmas about counting gates turned out to be the bridge from "quantum computers are universal in principle" to "here is the circuit, and here is what it costs".
Going further
Texts. Nielsen & Chuang, Quantum Computation and Quantum Information, §4.3 (universal gates, controlled operations, Figs. 4.8–4.10) · Barenco, Bennett, Cleve, DiVincenzo, Margolus, Shor, Sleator, Smolin, Weinfurter, "Elementary gates for quantum computation", Phys. Rev. A 52, 3457 (1995) · Preskill, Lecture Notes for Physics 219, Ch. 5–6 · Kitaev, Shen & Vyalyi, Classical and Quantum Computation, §8 · Watrous, The Theory of Quantum Information, Ch. 2 (unitary channels) · Mermin, Quantum Computer Science, Ch. 2.
Provenance. The definition and the block-diagonal form follow Nielsen & Chuang §4.3; the controlled- square-root identity, the ABC decomposition of , the -Toffoli clean-ancilla ladder, the single-borrowed-ancilla linear bound, and the ancilla-free scaling are all from Barenco et al. (Phys. Rev. A 52, 3457, 1995), Lemmas 6.1, 7.2, 7.5 and Corollary 7.4. A verifier should confirm: (1) the four-case evaluation of equation (3) gives ; (2) , so the Example-2 circuit yields ; (3) the AND ladder resets all clean ancillas to for every control input and flips the target iff the string is ; (4) the resource arithmetic Toffolis gates. All stated counts (6 CNOTs and 7 for a Toffoli, , , ) are standard textbook figures; the -Toffoli factoring estimate is Gidney & Ekerå (2021).
Prerequisites. Controlled-U Gates · CNOT Gate · Phase Gates (S and T) · Z-Y Decomposition of Single-Qubit Gates · Circuit Identities and Equivalences. Leads to. Quantum Circuit Model · SWAP Gate · Controlled-Z Gate.
Ask the tutor: Ask me to trace the square-root construction gate by gate for a specific , or to compare the clean-ancilla, borrowed-ancilla, and ancilla-free circuits for a given control count and target.
Why is the ancilla budget, and not the target unitary U, what sets the gate count?
Because the hard part of a multi-controlled gate is the control logic — computing the AND of many controls — not the single application of . Applying once costs a fixed handful of gates via the ABC decomposition; what scales with is reducing an -fold control to a single control. If you have scratch qubits you store the running conjunction in them with a linear ladder of Toffolis, so the cost is . If you have none, you must recreate that conjunction on the fly with nested square roots, and the same information costs to marshal and unmarshal. The target enters only through the two constant-cost single-controlled 's, so it never changes the scaling — which is why the whole theory is phrased around the multi-controlled NOT.
What exactly is a "dirty" or borrowed ancilla, and why is it almost as good as a clean one?
A clean ancilla is a scratch qubit you are handed in a known state and may leave in . A dirty or borrowed ancilla is a qubit already in use elsewhere, in an unknown (possibly entangled) state, that you may use only if you return it to exactly that state when you are done. Barenco et al. showed that even a single borrowed qubit collapses the ancilla-free cost of a multi-controlled NOT back to linear , using a conjugation pattern whose forward and backward halves cancel any effect on the borrowed qubit regardless of its state. This matters enormously in practice: a large circuit almost always has some qubit idle for a moment, and borrowing it is free, whereas dedicating a fresh clean ancilla costs precious width. The one non-negotiable is the restoration — a borrowed qubit left perturbed corrupts whatever computation owns it.
Why must V be a square root of U, and what happens if I pick a different V?
The constraint comes entirely from the all-ones control setting. In the five-gate construction, every control setting except the all-ones one places a and a on the target, which cancel to the identity by unitarity no matter what is — those branches are automatically correct. Only when both controls are set does the inter-control CNOT switch off the , leaving two 's in a row, , on the target. For that branch to apply the intended you need , and nothing else about is constrained. Pick a with and the three cancelling branches still work, but the all-ones branch applies the wrong operator, so the circuit is not . The freedom in choosing among the several square roots of is sometimes exploited to pick a that is cheap to compile.
Is the Toffoli special, or just the n = 2 case of this whole story?
Both. Formally the Toffoli is exactly , the smallest nontrivial multi-controlled gate, and the square-root construction with produces it. But it is special in being the recursion's atom: the linear AND-ladder for is built entirely from Toffolis, computing the conjunction one control at a time, so the whole linear-cost regime is "count the Toffolis". It is also special because it is non-Clifford — its exact compilation needs seven gates — which makes the Toffoli count the headline resource metric on a fault-tolerant machine. So the Toffoli is simultaneously a member of the family (the NOT) and the currency in which the rest of the family is priced.
How do multi-controlled gates connect to the Grover diffusion operator?
The Grover diffusion step is the reflection about the uniform superposition, and conjugating by Hadamards and gates turns it into a conditional phase flip on a single basis state — a multi-controlled- acting on all the qubits. That is just a with a Hadamard sandwiching the target (since ), so compiling the diffusion operator is compiling a multi-controlled NOT. Every Grover iteration pays for one such gate, so the ancilla budget you choose for it — clean ladder, borrowed qubit, or ancilla-free — directly sets the per-iteration depth and width of the search. It is a clean example of the whole subject in miniature: an abstract reflection becomes a concrete high-fanin conditional, and the cost is an ancilla-budget decision.
What is a relative-phase multi-controlled gate, and when is it safe to use?
A relative-phase multi-control reproduces the correct permutation of basis states — it fires the target on exactly the right control string — but attaches an extra phase to one or more basis states, so as a unitary it is not equal to the true multi-controlled gate. The prototype is the three-CNOT Margolus Toffoli, cheaper than the six-CNOT exact one but carrying a stray on a single state. Such gates are safe precisely when that phase is guaranteed to cancel, which happens in the ubiquitous compute-then-uncompute pattern: you use the cheap gate to write a value into an ancilla, do some work, and later apply its inverse to erase the ancilla — the stray phase appears twice and squares to . If instead you keep the output as a lasting part of the register, the extra phase changes the overall unitary and silently corrupts the computation. The saving is real, but it is bought against a promise you must actually keep.