How it’s calculated
Euler's totient function φ(n) counts the whole numbers from 1 to n that are relatively prime to n (share no factor with it other than 1). Counting them one by one is slow, but φ has a formula in terms of the prime factors of n: each distinct prime p dividing n removes the fraction 1/p of the numbers.
φ is multiplicative: φ(m × n) = φ(m) × φ(n) when m and n are coprime. It appears in Euler's theorem, a^φ(n) ≡ 1 (mod n) whenever gcd(a, n) = 1, and in RSA encryption, where the private key is the inverse of the public exponent modulo φ(n).
Example: 200 = 2³ × 5². φ(200) = 200 × (1 − 1/2) × (1 − 1/5) = 200 × 1/2 × 4/5 = 80. Prime power by prime power: φ(2³) = 8 − 4 = 4 and φ(5²) = 25 − 5 = 20, and 4 × 20 = 80.
Frequently asked questions
What is φ of a prime number?
For a prime p, every number from 1 to p − 1 is coprime to p, so φ(p) = p − 1. For example φ(7) = 6.
Why is φ(1) = 1?
The only number from 1 to 1 is 1 itself, and gcd(1, 1) = 1, so it counts. This convention keeps the formula φ(m × n) = φ(m) × φ(n) working.
How is φ(n) used in RSA?
With n = p × q for two primes, φ(n) = (p − 1)(q − 1). The private exponent d is the inverse of the public exponent e modulo φ(n). For p = 61 and q = 53, n = 3233 and φ = 3120.
Is φ(n) always even?
Yes, for every n of 3 or more. The numbers coprime to n pair up as k and n − k, which are never equal when n > 2.
Embed this calculator
Add this free calculator to your own website. Copy the code below into your page’s HTML:
Need this calculator branded, changed or built around your own prices?See custom business solutions →
Sources
- Elementary Number Theory (Raji), §4.2 Multiplicative Number Theoretic Functions (φ(n) = n∏(1 − 1/p), φ(200) = 80) — LibreTexts Mathematics
- Elementary Number Theory (Raji), §3.2 Residue Systems and Euler's φ-Function — LibreTexts Mathematics
Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.
Added · Last updated · How we check our calculators
Spotted a mistake or missing option? Report a problem· Suggest a calculator