Euler's Totient Function Calculator

Euler's totient function phi(n) counts how many integers from 1 to n share no common factor with n (are coprime to n). This calculator computes phi(n) for any positive integer n, shows the prime factorization used in the calculation, and for n of 50 or less, lists every integer coprime to n. The formula is: phi(n) = n multiplied by (1 - 1/p) for every distinct prime factor p of n. So for n = 12, which factors as 2^2 times 3, phi(12) = 12 times (1/2) times (2/3) = 4. The four coprimes are 1, 5, 7, and 11. Euler's totient function is central to Euler's theorem (a^phi(n) is congruent to 1 mod n when gcd(a,n)=1), which generalises Fermat's little theorem and forms the mathematical basis of RSA public-key cryptography. It also counts primitive roots, determines group orders, and appears in cyclotomic polynomials.

Enter a positive integer
4
2^2 × 3
12 × (1 - 1/2) × (1 - 1/3) = 4
1, 5, 7, 11

Euler's totient formula

phi(n) = n * (1 - 1/p1) * (1 - 1/p2) * ... for all distinct prime factors p of n
Special cases:
phi(1) = 1
phi(p) = p - 1 for prime p
phi(p^k) = p^(k-1) * (p - 1)
phi(m * n) = phi(m) * phi(n) when gcd(m,n) = 1

Phi values for small n

nphi(n)nphi(n)nphi(n)
11761312
2184146
3296158
42104168
5411101716
62124186

Euler phi: frequently asked questions

What is Euler's totient function?

Euler's totient function phi(n) counts how many positive integers up to n are coprime to n (share no common factor with n other than 1). For example, phi(8) = 4 because 1, 3, 5, and 7 are coprime to 8. The function is fundamental in number theory and cryptography.

How do you calculate phi(n)?

If n has prime factorization p1^a1 * p2^a2 * ... then phi(n) = n * (1 - 1/p1) * (1 - 1/p2) * ... For example, phi(12) = 12 * (1 - 1/2) * (1 - 1/3) = 12 * 1/2 * 2/3 = 4. The four integers coprime to 12 are 1, 5, 7, and 11.

What is phi(p) for a prime p?

For any prime p, phi(p) = p - 1. This is because every integer from 1 to p-1 is coprime to a prime (primes have no divisors other than 1 and themselves). For example, phi(7) = 6.

How is phi(n) used in RSA encryption?

RSA key generation relies on phi(n) where n = p * q for two primes p and q. Since phi(n) = (p-1)*(q-1), the private key d satisfies e*d ≡ 1 (mod phi(n)). Knowing phi(n) allows decryption, so the security of RSA depends on the difficulty of factoring n to find p and q.

What is the sum of all phi values up to n?

The sum of phi(k) for k from 1 to n approximates 3n^2/pi^2 for large n. More precisely, it equals (n*(n+1)/2) minus the sum of floor(n/p)*phi(p) terms. The sum formula is related to counting fractions in the Farey sequence.

Sources

Reviewed by the CalculatorHub team, edited by James Graham, 14 June 2026. See our methodology.