For any positive integer , how many integers from to share no common factor with other than ? This is the question Leonhard Euler asked in the 1760s, and the function he defined to answer it — denoted — has turned out to be one of the most useful tools in number theory.
The first few values of the Euler totient function are straightforward to compute. For , the integers have ‘s with . Only and are coprime to , so . For , the coprime numbers up to are , so . For a prime , every integer from to is coprime to , so .
What at first appears to be an unremarkable counting function turns out to govern the structure of modular arithmetic, the multiplicative group , the RSA encryption algorithm that secures the web, and a great deal of analytic number theory. This article is about , what makes it useful, and how its properties cascade through pure and applied mathematics.
The formula
For prime powers, the totient is easy. Consider where is prime. The integers from to that share a factor with are exactly the multiples of : namely , a total of numbers. So .
For general , the totient is multiplicative: if , then . The proof uses the Chinese Remainder Theorem: every integer mod corresponds uniquely to a pair of integers mod and mod , and the pair is coprime to exactly when each component is coprime to its respective modulus.
Combining these two facts, if is the prime factorisation, then
The product runs over all distinct primes dividing . For :
A quick check: among , the coprime numbers are — exactly values.
Erratic behaviour
For all that the closed-form formula is clean, the function behaves erratically as varies. It depends only on the prime structure of , not on its size, so numbers with many small prime factors have small totients and numbers that are prime (or products of large primes) have nearly the maximum possible totient. The plot below shows for .
The pattern is exactly what the formula predicts. Prime numbers have , which approaches for large primes — almost every integer below is coprime to it. Smooth numbers with many small prime factors — like , which has — have very small totients relative to their size. The function thus encodes how “prime-like” or “composite-like” is, in a precise multiplicative sense.
Euler’s theorem and modular arithmetic
The totient function’s most important property links it to the multiplicative structure of integers modulo . Euler’s theorem (1763) states:
If , then .
This generalises Fermat’s little theorem ( for prime ), which is the special case . The proof is short: the multiplicative group of units modulo has exactly elements, and by Lagrange’s theorem, every element raised to the power of the group’s order gives the identity. So in , i.e., over integers.
This deceptively simple result is the engine of all of modular exponentiation. When you need to compute for some huge integer , you don’t need to compute the full power — you can replace by and get the same answer. This is what makes large-exponent computations tractable in cryptography.
Connection to RSA
The most consequential application of the totient function is in RSA encryption, the cornerstone of public-key cryptography. Here is how it works in outline.
Choose two large prime numbers and , and let . By the multiplicativity of , . Choose an integer that is coprime to — this is the encryption exponent, and it is published openly along with . Privately, compute the multiplicative inverse of modulo , call it — this is the decryption exponent, kept secret.
To encrypt a message , compute . To decrypt, compute . The fact that decryption recovers follows from Euler’s theorem: , since for coprime to .
The security of the protocol rests on the difficulty of computing from alone. If an attacker could factor , they would immediately know and could invert the encryption. But integer factorisation of large semiprimes (products of two large primes) is currently infeasible: for of around bits, factorisation would require thousands of years on the most powerful computers in existence. So the totient function — defined as a simple count in 1763 — is the mathematical lock that protects every secure HTTPS connection, every encrypted email, every bank transaction on the web.
Other appearances
Beyond cryptography, the totient appears in many corners of number theory.
Möbius inversion. The totient satisfies , an identity discovered by Gauss. This is one of the simplest applications of Möbius inversion, a technique for inverting summation identities in multiplicative number theory.
Cyclotomic polynomials. The -th cyclotomic polynomial — whose roots are the primitive -th roots of unity — has degree exactly . This connects the totient to Galois theory of cyclotomic field extensions.
Asymptotic density. The average value of over tends to as — the same number that gives the probability that two random integers are coprime. The connection runs through the Riemann zeta function: is a multiplicative function whose Dirichlet series is , and the asymptotic average comes from evaluating this at .
Counting solutions in modular equations. Whenever you want to count the number of solutions of a polynomial equation modulo , the totient often appears in the answer.
A small counting function with enormous reach
Euler defined as a piece of pure curiosity: how many numbers below are coprime to it? What he could not have anticipated is that his counting function would, two and a half centuries later, sit at the foundation of a global infrastructure for secure communication. Every time you visit a website over HTTPS, every time you send an encrypted message, every time you authenticate with a public key, the totient function is doing its work behind the scenes.
The beauty of the function is twofold. Pure beauty: a simple count gives a multiplicative function with a clean closed-form formula and an elegant connection to the group structure of modular arithmetic. Applied beauty: the same function provides the mathematical scaffolding for one of the most widely-deployed cryptographic protocols in human history. The gap between definition and impact is enormous, and one of the most striking demonstrations of how often the apparently abstract questions of number theory turn out to underwrite the practical machinery of the modern world.
Euler counted numbers in 1763. Two centuries later, his function was protecting the web. That is what a great mathematical concept looks like.
Frequently asked
What does the word 'totient' actually mean?
It comes from Latin tot, meaning 'so many' — the same root as English 'total'. The mathematician James Joseph Sylvester coined the English word 'totient' in 1879 specifically for Euler's function, describing it as 'the count of numbers that are totient (i.e., that constitute a complete coprime set) with n'. The Greek letter φ (phi) used to denote the function was Gauss's choice in his 1801 Disquisitiones Arithmeticae, where he gave the first systematic treatment of modular arithmetic and the function's properties.
How do you actually compute φ(n)?
Factor n into primes. For each prime p that divides n, the contribution to φ(n) is (p − 1)/p. Multiply n by all these fractions: φ(n) = n · ∏ (1 − 1/p), where the product runs over all distinct primes p dividing n. For example, φ(60) = 60 · (1 − 1/2)(1 − 1/3)(1 − 1/5) = 60 · 1/2 · 2/3 · 4/5 = 16. Factoring n is the hard part; once you have the factorisation, computing φ(n) is essentially free.
What is Euler's theorem?
If gcd(a, n) = 1, then a^φ(n) ≡ 1 (mod n). This generalises Fermat's Little Theorem (a^(p−1) ≡ 1 mod p for prime p, since φ(p) = p − 1). Euler's theorem is the foundation of modular exponentiation in cryptography: when you exponentiate a number to a large power modulo n, the exponent can be reduced modulo φ(n) without changing the result. This is exactly what makes the RSA algorithm tractable: encryption and decryption keys live in arithmetic modulo φ(n), and the whole security argument rests on the difficulty of computing φ(n) without knowing the prime factorisation of n.
How does the totient relate to RSA encryption?
In RSA, you publish a number n that is the product of two large primes p and q. The encryption exponent e is public, and the decryption exponent d is computed as the multiplicative inverse of e modulo φ(n) = (p − 1)(q − 1). To decrypt, an attacker would need to recover d, which requires knowing φ(n), which requires factoring n. Since factoring large semiprimes is currently infeasible, RSA is secure. The whole protocol turns on Euler's totient function and the difficulty of computing it from n alone.