Karatsuba and Fast Multiplication
Grade-school multiplication of two -digit numbers takes single-digit operations. Line up every digit of one number against every digit of the other. This is exactly as taught in elementary school. For small numbers this is fine. But modern systems multiply numbers with thousands or millions of digits. Examples include cryptographic keys, arbitrary-precision arithmetic libraries, computer algebra systems, and record-breaking computations of . At that scale, quadratic time is a wall. The question that opens this article is simple to state. Yet it shockingly resisted an easy answer for millennia: can we multiply two -digit numbers in fewer than digit-multiplications? In 1960, Andrey Kolmogorov conjectured — in a seminar at Moscow State University — that multiplications were unavoidable. He believed the schoolbook method to be optimal. Within a week, a 23-year-old student named Anatoly Karatsuba found a method beating it. He used a clever algebraic trick to multiply two -digit numbers with only three half-size multiplications instead of four. Kolmogorov was reportedly so excited he arranged for Karatsuba's result to be published immediately. The seminar itself was discontinued, since its central open problem had just been resolved. Karatsuba's algorithm is a foundational example of the Divide and Conquer Paradigm: split a problem into subproblems, solve them recursively, and combine the results. What makes it pedagogically special is that the split is the easy part. Any schoolchild can split a number into a high half and a low half. But the combine step usually forces four multiplications (a classic block-matrix-like expansion). Karatsuba's insight is an algebraic identity that computes the same information from only three products. This one saved multiplication is precisely what breaks the quadratic barrier via the Master Theorem for Recurrences. This article derives the identity, and states and proves the algorithm precisely. It works the recurrence exactly, and traces a full numeric example by hand. It also situates Karatsuba's algorithm within the broader family of fast multiplication methods. These include Toom-Cook, Schönhage-Strassen, and the more recent Harvey–van der Hoeven near-linear algorithm. Throughout, it stays honest about where the crossover point actually lies in practice.
- Schoolbook multiplication of -digit numbers costs ; Karatsuba's algorithm reduces this to .
- The key trick: compute once and reuse it, needing only 3 half-size multiplications instead of the naive 4.
- The recurrence solves via the Master Theorem, case 1, since .
- Correctness follows from a pure algebraic identity — no approximation, no probability, exact integer arithmetic throughout.
- In practice, Karatsuba beats schoolbook multiplication only past a crossover point (often tens to hundreds of digits); below that, constant factors dominate.
- Karatsuba is one member of a hierarchy — Toom-Cook generalizes it, and Schönhage-Strassen/Harvey–van der Hoeven push toward using FFT-based convolution.
Multiplying two numbers only needs three half-size multiplications, not four, because the cross terms can be recovered from a single extra product .
The idea
Represent each -digit (or -bit) integer in a base (e.g., or ) by splitting it into a high half and a low half at position :
where hold the low-order digits and hold the remaining high-order digits. The product expands exactly as
This is precisely the identity used for multiplying two-digit numbers by hand, generalized recursively. Computed naively, it requires four multiplications of half-size numbers: , , , . Doing this recursively gives the recurrence , which solves to — no asymptotic improvement over schoolbook multiplication at all. Karatsuba's contribution is an algebraic reduction from four multiplications to three. Define the single auxiliary product
Expanding, . If we also compute and (two more multiplications, needed anyway for the outer and inner terms), then the middle cross term — which normally costs two multiplications — is recovered by pure subtraction:
So the entire product is reconstructed from exactly three half-size multiplications (, , ) plus a constant number of half-size additions/subtractions and shifts (multiplications by powers of , which are free — just index shifts):
This is the entirety of the trick: trade one multiplication for a handful of additions. Multiplication of large numbers is expensive; addition is cheap (linear time). The recursive structure is a textbook instance of Divide and Conquer Paradigm: split into subproblems of half the size, recurse, and combine in linear extra work — except here the number of subproblems (3, not 4) is the entire content of the algorithm.
How it works
The algorithm recurses on the size of the operands, bottoming out at some small size (often a single machine word) where multiplication is done directly by hardware. Negative numbers are handled by tracking sign separately and recursing on absolute values; here we describe the unsigned core. ``` function KARATSUBA(x, y, n): // x, y are n-digit numbers in base B (arrays of digits, most significant first // or an arbitrary-precision integer representation). n = max(len(x), len(y)). if n <= THRESHOLD: // base case: small enough for direct multiply return SCHOOLBOOK-MULTIPLY(x, y) m = ceil(n / 2) x1, x0 = split(x, m) // x = x1 B^m + x0 y1, y0 = split(y, m) // y = y1 B^m + y0 z2 = KARATSUBA(x1, y1, n - m) // high high z0 = KARATSUBA(x0, y0, m) // low low s_x = x1 + x0 // O(m) addition s_y = y1 + y0 // O(m) addition z1 = KARATSUBA(s_x, s_y, m + 1) // (x1+x0)(y1+y0); note possible carry digit middle = z1 - z2 - z0 // O(n) subtraction; equals x1y0 + x0y1 result = SHIFT(z2, 2*m) + SHIFT(middle, m) + z0 // O(n) additions/shifts return result ``` Three recursive calls, each on operands of size roughly (the third, on , may have one extra digit due to carry from the addition, but this only affects constants, not the asymptotic recurrence). Everything else — splitting, adding, subtracting, shifting — is linear-time array manipulation. The figure below shows the recursion as a ternary tree for one level of splitting, and how the three half-size products recombine into the full product.
Complexity & correctness
Correctness. The proof is a direct algebraic identity, checked once and then inherited by induction on recursion depth. Write , . Then
Define , , . Expanding by distributivity,
so exactly — no approximation, no rounding, this is an identity over the integers (or any commutative ring). Substituting back:
which is exactly the value the algorithm returns. The base case (schoolbook multiply below the threshold) is trivially correct by definition. By strong induction on : if the three recursive calls on inputs of size return correct products (inductive hypothesis), the identity above shows the combine step produces the correct product for size . This closes the induction, so `KARATSUBA` is correct for all . One subtlety deserves care: and may have one more digit than due to carry (e.g., splitting a 6-digit base-10 number into two 3-digit halves, the halves can each be up to , so their sum can be up to , a 4-digit number). The recursive call on must be sized to accommodate this extra digit. This affects only the constant hidden in the recurrence's additive term, not the asymptotic recursion structure — a detail an implementation must get right, but which does not change the complexity analysis.
Complexity. Let be the time to multiply two -digit numbers. The algorithm makes 3 recursive calls on inputs of size , plus work for splitting, the two additions forming , the final subtraction, and the shift-and-add combination (each of these is linear in the number of digits). Hence
Apply the Master Theorem for Recurrences with , , and . Compare to . Since for , we are in Case 1 of the Master Theorem, giving
A recursion-tree argument confirms this directly: at depth , there are subproblems, each of size , doing work each, for total work at that level. The tree has depth , and since is strictly increasing in , the total work is dominated by the last level (a geometric series growing toward the leaves), giving total cost proportional to . This is the hallmark of Master Theorem Case 1: work increases toward the leaves, so the leaves — not the root — dominate the total cost.
Space. The recursion depth is , and each level allocates auxiliary space for sums, differences, and shifted results, giving space for a naive recursive implementation (or with careful in-place buffer reuse, since siblings' memory can be freed after combining).
Honesty about tradeoffs. Karatsuba is asymptotically better than the schoolbook algorithm, but the constant factor and recursive overhead (allocation, function-call cost, extra additions) mean it only wins past a crossover point — commonly cited as tens to low hundreds of digits/limbs, and empirically tuned in real libraries such as GMP. Below that threshold, schoolbook multiplication (or even direct hardware multiply instructions) is faster in practice. Production big-integer libraries use a hybrid: schoolbook for small operands, Karatsuba (or Toom-Cook) for medium sizes, and FFT-based methods for very large ones.
Worked example
Multiply and (base , , split at ). Split: ; .
| Step | Computation | Value |
|---|---|---|
| middle | ||
| result | ||
Check directly: . ✓ Matches exactly. Notice is itself computed by one more Karatsuba step in a real implementation (split ... though in practice recursion bottoms out once operands are small enough for direct multiplication — here we've simply used ordinary arithmetic for the sub-multiplications to keep the trace legible). The essential point of the trace is structural: only three multiplications (, , ) were needed to synthesize a 4-digit-by-4-digit product, where the schoolbook method would require four partial products (, , , ) — Karatsuba replaced the middle two multiplications with one multiplication plus three additions/subtractions. To see the savings compound, imagine recursing one level deeper on a -digit number. Schoolbook multiplication does single-digit products. Karatsuba's recursion tree at the base-case level (say, single digits) has leaves — roughly a reduction in the total number of elementary multiplications, a gap that widens further as grows, since the ratio scales like .
Common pitfalls & traps
| Pitfall | Why it happens | Fix |
|---|---|---|
| Forgetting the extra carry digit in | can exceed digits, causing buffer overflow or truncation | Size the recursive call for digits, not |
| Not handling negative `middle` | can be negative as an intermediate value even though the final result is positive | Use signed arithmetic internally, or bias/represent with sign-magnitude before combining |
| Ignoring the base case / threshold | Recursing all the way to single digits maximizes overhead from allocation and function calls | Switch to schoolbook multiplication below an empirically tuned threshold (often 20–100 digits) |
| Assuming Karatsuba is always faster | Constant factors and recursive overhead dominate for small | Benchmark; use hybrid schoolbook/Karatsuba/Toom-Cook/FFT dispatch as real libraries do |
| Misapplying the Master Theorem | Treating as if it were , or comparing against the wrong watershed function | Carefully compute and check which Master Theorem case actually applies |
| Splitting asymmetrically without adjusting recursion | Using arbitrarily can break the balanced-subproblem assumption | Keep the split as balanced as possible; unbalanced splits change the recurrence and the exponent |
Pioneers & history
Anatoly Karatsuba's discovery is one of the cleanest stories in algorithms: a graduate seminar led by Andrey Kolmogorov at Moscow State University was devoted to lower bounds for arithmetic computation, and Kolmogorov conjectured that elementary operations were necessary to multiply two -digit numbers — believing the schoolbook algorithm to be optimal. Karatsuba, then a 23-year-old student attending the seminar, found the algorithm described here within about a week of the conjecture being posed. Kolmogorov was so struck by the result that he reported it at the very next seminar meeting, and, since the seminar's central question had been answered, the seminar itself was discontinued. The paper was published in 1962, listing Kolmogorov as an author alongside Karatsuba (a common practice of the era), though the algorithm is universally attributed to Karatsuba individually today.
Origins · 1 minAnatoly Alexeyevich Karatsuba and how this was discovered
Karatsuba went on to a distinguished career in analytic number theory, particularly on the Riemann zeta function and trigonometric sums, but is remembered in computer science almost entirely for this single, brilliantly simple divide-and-conquer trick discovered as a young student — a reminder that foundational algorithmic ideas do not always require elaborate machinery, only the right decomposition.
Where this matters
Arbitrary-precision arithmetic libraries — GMP (GNU Multiple Precision Arithmetic Library), Python's built-in big integers, Java's `BigInteger`, and the arithmetic cores of computer algebra systems like Mathematica and Maple — all implement a hybrid dispatch strategy: schoolbook multiplication for small operands, Karatsuba for medium-sized operands, Toom-Cook variants for larger ones, and FFT-based methods (Schönhage-Strassen or newer variants) for the largest. Karatsuba's algorithm is typically the first asymptotic improvement such libraries reach for once numbers exceed a few dozen machine words. Cryptographic systems that rely on large-integer or large-polynomial arithmetic — RSA key generation and modular exponentiation, elliptic-curve cryptography's underlying field arithmetic, and homomorphic encryption schemes operating over large polynomial rings — benefit directly from subquadratic multiplication, since these operations perform enormous numbers of large-integer multiplications and even modest asymptotic improvements translate into real wall-clock savings at scale. Record-setting computations of and other mathematical constants to trillions of digits depend on fast multiplication (typically FFT-based methods derived from the same divide-and-conquer lineage Karatsuba began). Polynomial multiplication — used in signal processing, error-correcting codes, and symbolic computation — is structurally identical to integer multiplication (treat digits as polynomial coefficients), so Karatsuba's trick applies verbatim there as well, illustrating how the same Divide and Conquer Paradigm idea recurs across disparate application domains. Understanding Karatsuba is also a natural stepping stone toward The Greedy Method and Optimal Substructure, where a different strategy — commit locally, prove no backtracking is needed — replaces the "split, recurse, cleverly recombine" strategy at the heart of divide-and-conquer.
Ask the tutor: How would the recurrence and exponent change if we split each number into three parts instead of two, using five multiplications (as in Toom-3)?
Is Karatsuba's algorithm the fastest known way to multiply integers?
No. Karatsuba was the first subquadratic algorithm, but it was superseded asymptotically by Toom-Cook (splitting into more than 2 parts), then by Schönhage-Strassen's FFT-based method, and ultimately by Harvey and van der Hoeven's 2019 algorithm achieving , matching a conjectured lower bound. In practice, however, Karatsuba remains widely used for medium-sized operands because its overhead is far smaller than FFT-based methods, which only pay off for extremely large numbers (thousands of digits or more). Real libraries dispatch among several algorithms based on operand size.
Why is the Master Theorem's Case 1 the relevant case here, intuitively?
Case 1 applies when the combining work is asymptotically smaller than , meaning the total work is dominated by the sheer number of leaves in the recursion tree rather than by the work done at the root. Here is linear, while grows faster. Concretely, the recursion tree has subproblems at depth , each shrinking by half; because , the branching factor outpaces the size reduction, so the leaves (base cases) collectively dominate the runtime, not the top-level combine step.
Does Karatsuba's algorithm work for polynomial multiplication too?
Yes, directly and without modification to the core idea. Treat polynomial coefficients as the "digits" of a base- representation (with symbolic rather than numeric), split each polynomial into a high-degree half and a low-degree half, and apply the identical identity: recovers the cross terms. This is one reason Karatsuba's trick generalizes so widely — it is really a statement about bilinear algebra over any commutative ring, not specifically about base-10 or base-2 numerals.
What is the actual crossover point where Karatsuba beats schoolbook multiplication in practice?
It varies by implementation, hardware, and how well-optimized the schoolbook inner loop is, but production libraries like GMP typically switch to Karatsuba somewhere in the range of a few dozen to roughly one hundred machine words (each word being 32 or 64 bits), and switch again to Toom-Cook or FFT-based methods at larger sizes still. The exact thresholds are determined empirically by benchmarking on target hardware, not derived purely from asymptotic analysis, since constant factors and memory-access patterns matter enormously at these scales.
How does Toom-Cook generalize Karatsuba's idea?
Karatsuba splits each number into 2 parts and uses 3 multiplications instead of 4 (i.e., multiplications for parts). Toom-Cook generalizes this to splitting into parts, using multiplications instead of , by evaluating the numbers (viewed as polynomials) at points, multiplying pointwise, and interpolating. As grows, the exponent in the resulting recurrence approaches 1, but the overhead (evaluation and interpolation cost, coefficient growth) increases, so in practice only small (Toom-3, Toom-4) are used before switching to FFT-based methods entirely.
Why is exact carry/borrow handling more delicate in Karatsuba than in schoolbook multiplication?
Schoolbook multiplication processes digit pairs directly and carries are handled digit-by-digit in a single predictable pass. Karatsuba, by contrast, computes intermediate quantities like that can be negative even though the final assembled result is positive, and it computes , which can overflow the expected digit width. An implementation must track signs and allocate one extra digit of headroom for these intermediate values, or subtle, input-dependent corruption can occur that ordinary schoolbook code would never produce.
Does Karatsuba's algorithm reduce the number of additions too, or only multiplications?
No — it strictly increases the number of additions/subtractions (from the naive combine step's roughly 2 additions to about 6 operations: two additions to form , one multiplication, and two subtractions to isolate the middle term, plus final shift-adds). This is precisely the tradeoff: Karatsuba spends more linear-time work (additions, which cost ) to save one multiplication (which, recursively, costs far more). Since multiplication is the asymptotically expensive operation, trading multiplications for additions is a net win once is large enough to make the recursion pay off.