Karatsuba Algorithm
The Karatsuba algorithm is a divide-and-conquer multiplication method discovered by Anatoly Karatsuba in 1960 that multiplies two n-digit integers or polynomials using three half-width multiplications in O(n^1.585) time.
Karatsuba Algorithm is a recursive divide-and-conquer algorithm in computation and algorithms and computer arithmetic that multiplies two n-digit integers (or degree-n polynomials) in O(nlog2 3) ≈ O(n1.58496) single-digit operations, improving asymptotically upon the O(n2) classical long-multiplication (schoolbook) algorithm. Discovered in 1960 by 23-year-old Soviet mathematician Anatoly Alexeevich Karatsuba and published in 1962 by Andrey Kolmogorov and Yuri Ofman in the Proceedings of the USSR Academy of Sciences, it was the first sub-quadratic multiplication algorithm ever constructed.
Prior to 1960, Andrey Kolmogorov had conjectured in 1956 that the classical Θ(n2) digit-by-digit multiplication algorithm—known since antiquity across Babylonian, Egyptian, and Hindu-Arabic arithmetic—was asymptotically optimal and that no algorithm could multiply two n-digit numbers in fewer than Ω(n2) elementary operations. During a seminar organized by Kolmogorov at Moscow State University in autumn 1960, Karatsuba disproved the Ω(n2) conjecture within one week by showing that a two-limb product can be evaluated with three half-width multiplications instead of four. This algebraic identity launched the modern theory of fast arithmetic within computational complexity theory, inspiring the Toom–Cook family, fast Fourier transform (FFT) Schönhage–Strassen multiplication, and the Strassen algorithm for sub-cubic matrix multiplication.
Algebraic Derivation and Three-Product Recurrence
Radix Splitting and Classical Four-Product Expansion
Let X and Y be two non-negative n-digit integers expressed in positional radix B (for instance, B = 264 for 64-bit machine words or B = 10 for decimal representation), where n = 2k for exposition. Setting the split midpoint m = ⌈n / 2⌉, decompose X and Y into high-order and low-order m-digit halves:
Expanding the product Z = X · Y algebraically yields a degree-2 polynomial in Bm:
where the three coefficient terms are:
Computing z2, z1, and z0 directly requires four half-width (m-digit) multiplications (x1y1, x1y0, x0y1, x0y0). Because multiplying by Bm or B2m is a zero-cost limb shift and m-digit addition takes Θ(n) linear time, the naive divide-and-conquer recurrence is T(n) = 4T(n/2) + Θ(n) = Θ(nlog2 4) = Θ(n2), yielding zero asymptotic speedup over schoolbook multiplication.
Karatsuba's Three-Multiplication Identity
Karatsuba observed that once the outer products z2 = x1y1 and z0 = x0y0 have been computed, the cross-term sum z1 = x1y0 + x0y1 can be obtained from a single additional multiplication P3 by expanding the product of sums (x1 + x0)(y1 + y0):
- P1 = x1 · y1 (gives z2 = P1)
- P2 = x0 · y0 (gives z0 = P2)
- P3 = (x1 + x0) · (y1 + y0)
Subtracting P1 and P2 from P3 isolates the middle coefficient z1 via two additions and two subtractions:
Alternatively, the subtractive variant computes P3− = (x1 − x0)(y0 − y1) so that z1 = P3− + P1 + P2. Because |x1 − x0| < Bm, the subtractive formulation avoids the extra carry bit required when x1 + x0 ≥ Bm has m + 1 digits, simplifying fixed-width word-aligned software and hardware implementations.
Complexity Analysis and Position in the Fast Multiplication Hierarchy
Master Theorem Solution and Bit-Operation Bounds
Applying the Master Theorem to the Karatsuba recurrence with three recursive subproblems of size n/2 and linear O(n) addition/shift overhead:
Expanding across k = log2 n recursion levels yields:
Since log2 3 = ln 3 / ln 2 ≈ 1.5849625, multiplying two 1,024-limb numbers requires at most 310 = 59,049 single-limb multiplications under pure Karatsuba recursion compared to 1,0242 = 1,048,576 under schoolbook multiplication—nearly an 18-fold reduction in scalar products.
Lagrange Interpolation Viewpoint and the Multiplication Hierarchy
Algebraically, Karatsuba's method is the k = 2 case of Toom–Cook (k-way) polynomial interpolation: treating X(t) = x1t + x0 and Y(t) = y1t + y0 as linear polynomials evaluated at t = Bm, their product Z(t) = X(t)Y(t) has degree 2 and is uniquely determined by its values at three evaluation points: t = 0 (Z(0) = x0y0 = P2), t = 1 (Z(1) = (x1 + x0)(y1 + y0) = P3), and t = ∞ (Z(∞) = x1y1 = P1). Generalizing to k limbs evaluated at 2k − 1 points produces Toom-k in O(nlogk(2k−1)) time, and evaluating at 2K complex roots of unity via the fast Fourier transform yields quasi-linear multiplication.
| Multiplication Algorithm | Year | Splits k & Sub-Products | Asymptotic Time Complexity | Practical Crossover Threshold (64-Bit Limbs) |
|---|---|---|---|---|
| Schoolbook (Long Multiplication) | Antiquity | k = 2 → 4 products | O(n2) | 1 to ~24 limbs (64 to ~1,536 bits) |
| Karatsuba Algorithm (Toom-2) | 1960 / 1962 | k = 2 → 3 products | O(nlog2 3) ≈ O(n1.585) | ~24 to ~120 limbs (~1,536 to ~7,680 bits) |
| Toom–Cook 3-Way (Toom-3) | 1963 / 1966 | k = 3 → 5 products | O(nlog3 5) ≈ O(n1.465) | ~120 to ~350 limbs (~7,680 to ~22,400 bits) |
| Schönhage–Strassen (FFT) | 1971 | 2r-point Fermat ring FFT | O(n log n log log n) | ~2,000+ limbs (> 128,000 bits) |
| Harvey–van der Hoeven | 2021 | Multidimensional Gaussian FFT | O(n log n) | Theoretical bound (n > 2172912 bits) |
Applications in Cryptography, Computer Algebra, and Hardware
Because Karatsuba's algorithm has minimal addition and carry-propagation overhead compared to higher-order Toom–Cook or FFT methods, its practical crossover point against schoolbook multiplication occurs at just 16 to 32 machine words (1,024 to 2,048 bits) in multiprecision libraries such as the GNU Multiple Precision Arithmetic Library (GMP), OpenSSL BIGNUM, Python's native arbitrary-precision integer type (which switches to Karatsuba at a cutoff of 70 30-bit digits ≈ 2,100 bits), and Java's BigInteger.
This 1,024–4,096-bit window coincides directly with the modulus sizes of RSA cryptography, Diffie–Hellman key exchange, and post-quantum lattice polynomial rings (Rq = ℤq[x]/(xn + 1)). Moreover, over binary Galois fields GF(2m) used in elliptic curve cryptography and GCM authenticated encryption (CLMUL), addition is carry-free bitwise XOR (⊕), eliminating the carry bit in x1 ⊕ x0 and making hardware Karatsuba multipliers smaller in gate area even for 64-bit and 128-bit polynomials.
Frequently Asked Questions
Why did Kolmogorov believe O(n2) multiplication was optimal before 1960?
For thousands of years, every known multiplication procedure multiplied each of the n digits of X by each of the n digits of Y. Because the output depends on all n2 pairwise interactions in the bilinear form, Kolmogorov conjectured in 1956 that any circuit or algorithm must perform Ω(n2) operations—until Karatsuba demonstrated that linear combinations prior to multiplication can compress bilinear rank.
At what integer size does Karatsuba become faster than schoolbook multiplication in practice?
Although Karatsuba performs fewer multiplications for any n ≥ 2, each recursive step introduces four extra m-limb additions/subtractions and pointer bookkeeping. On 64-bit processors with single-cycle hardware MULX instructions, schoolbook multiplication is faster up to roughly 16–32 limbs (1,024–2,048 bits); above that threshold, Karatsuba recursion calls down to a 24-limb schoolbook base case.
Can the Karatsuba algorithm be used to compute integer division and square roots?
Yes. Via Newton–Raphson reciprocal iteration (xk+1 = xk(2 − D xk)) and Paul Zimmermann's recursive Karatsuba division and Karatsuba square root algorithms, dividing a 2n-limb integer by an n-limb divisor or extracting an n-limb integer square root reduces to a small constant multiple (within 1.5× to 2×) of the O(nlog2 3) cost of Karatsuba multiplication.
References
- Karatsuba, A., & Ofman, Yu. (1962). "Multiplication of many-digital numbers by automatic computers." Doklady Akademii Nauk SSSR, 145(2), 293–294 (English translation in Physics-Doklady, 7, 595–596, 1963). https://mathscinet.ams.org/mathscinet-getitem?mr=0149692
- Karatsuba, A. A. (1995). "The complexity of computations." Proceedings of the Steklov Institute of Mathematics, 211, 169–183. https://www.mathnet.ru/eng/tm1186
- Knuth, D. E. (1997). The Art of Computer Programming, Volume 2: Seminumerical Algorithms (3rd ed., Section 4.3.3: How Fast Can We Multiply?, pp. 294–318). Addison-Wesley. https://www-cs-faculty.stanford.edu/~knuth/taocp.html
- Brent, R. P., & Zimmermann, P. (2010). Modern Computer Arithmetic (Cambridge Monographs on Applied and Computational Mathematics, Vol. 18, Chapter 1.3: Karatsuba and Toom–Cook Multiplication). Cambridge University Press. https://doi.org/10.1017/CBO9780511921698
- Harvey, D., & van der Hoeven, J. (2021). "Integer multiplication in time O(n log n)." Annals of Mathematics, 193(2), 563–617. https://doi.org/10.4007/annals.2021.193.2.4