Montgomery Reduction
August 25, 20265 min readbeginner
Montgomery's technique, from 1985, is used differently from Barrett. Instead of reducing each product back to an ordinary residue, it changes the representation of every number so…
Montgomery's technique, from 1985, is used differently from Barrett. Instead of reducing each product back to an ordinary residue, it changes the representation of every number so that reduction becomes almost free.
That trade only pays when there is a long chain of multiplications to amortise the conversion over. The inner loop of an NTT is exactly such a chain, which is why this is the method most implementations use.
01.Working in a different representation
Pick a power of two with , typically or . Represent each by its Montgomery form
Two observations about what that does.
Addition is unaffected. . So sums need no conversion at all.
Multiplication picks up an extra factor. , whereas the Montgomery form of should be . The product is one factor of too large.
So what is needed is an operation taking to . That is Montgomery reduction.
And here is why it is cheap: is a power of two, so dividing by is a right shift. The entire problem collapses to "make a multiple of , then shift".
02.The algorithm
Precompute with , once, by the extended Euclidean algorithm.
Given :
M1. . Both operands are bits and so is the result, which means taking the low half of a product, exactly what a DSP slice provides naturally.
M2. . The division is exact, because makes a multiple of . So it is a right shift.
M3. If , subtract . Return .
The result is .
Step M1 is the trick worth pausing on. It chooses precisely so that adding clears the low bits of , without changing anything modulo , since . Adding a multiple of is free modulo , and it is being used to buy divisibility by .
03.A worked example
Take and , which are coprime.
First find with . Trying : . So .
Convert and into Montgomery form:
Now multiply them and reduce.
T. .
M1. .
M2. .
M3. , so return .
Check it. The answer should be the Montgomery form of , which is . Since , that is . Correct.
Note that came out exactly, with no remainder. That is step M1 doing its job.
To leave Montgomery form, reduce once more with :
And , so . Correct again.
04.How it is used in practice
The conversions at each end are not free, so Montgomery is only worthwhile if many operations happen in between.
The standard arrangement is to convert once on the way in, perform the entire transform, the pointwise multiplication and the inverse transform without ever leaving Montgomery form, and convert once on the way out. Additions cost nothing extra, and every multiplication is followed by one Montgomery reduction to absorb the surplus .
Mature ML-KEM and ML-DSA implementations go further and keep coefficients in what is usually called Montgomery-NTT form almost everywhere, converting only at the boundaries where data is serialised. The twiddle-factor tables are themselves stored pre-converted, so the constants entering each butterfly need no adjustment.
05.Hardware cost
One truncated multiplication , taking the low word of a product. One widening multiplication . One addition. One right shift, which is wires. One conditional subtraction, which must be branchless exactly as in Barrett Reduction.
The total gate count is within a few percent of Barrett. The reason Montgomery is usually preferred is not area but arrangement: the truncated multiplication's output width matches what the next stage consumes, so less width-matching logic sits in the critical path.
The next note describes a more recent method that shortens that path further.