Mathwords logoMathwords

Prime Counting Function — Definition, Formula & Examples

The prime counting function, written π(x), tells you how many prime numbers are less than or equal to x. For example, π(10) = 4 because there are four primes (2, 3, 5, 7) that do not exceed 10.

For any real number xx, the prime counting function is defined as π(x)={pZ:p is prime and px}\pi(x) = |\{p \in \mathbb{Z} : p \text{ is prime and } p \leq x\}|, where |\cdot| denotes the cardinality of the set. The function π\pi is a non-decreasing, integer-valued step function that increases by 1 at each prime.

Key Formula

π(x)=pxp prime1\pi(x) = \sum_{\substack{p \leq x \\ p \text{ prime}}} 1
Where:
  • xx = A real number serving as the upper bound
  • pp = A prime number
  • π(x)\pi(x) = The count of primes less than or equal to x

How It Works

To evaluate π(x)\pi(x), list all prime numbers from 2 up to xx and count them. The function jumps by 1 at every prime and stays flat between consecutive primes. For large xx, exact computation is difficult, but the Prime Number Theorem gives the famous asymptotic approximation π(x)xlnx\pi(x) \sim \frac{x}{\ln x}, meaning the ratio π(x)/(x/lnx)\pi(x) / (x / \ln x) approaches 1 as xx \to \infty. A more accurate estimate uses the logarithmic integral: π(x)Li(x)=2xdtlnt\pi(x) \approx \operatorname{Li}(x) = \int_2^x \frac{dt}{\ln t}.

Worked Example

Problem: Find π(20).
Step 1: List all primes up to 20.
2, 3, 5, 7, 11, 13, 17, 192,\ 3,\ 5,\ 7,\ 11,\ 13,\ 17,\ 19
Step 2: Count the primes in the list.
π(20)=8\pi(20) = 8
Step 3: Compare with the asymptotic estimate from the Prime Number Theorem.
20ln20203.006.67\frac{20}{\ln 20} \approx \frac{20}{3.00} \approx 6.67
Answer: π(20) = 8. The approximation 20/ln(20) ≈ 6.67 is in the right ballpark but undershoots, which is typical for moderate values of x.

Visualization

Why It Matters

The prime counting function is central to analytic number theory. The Riemann Hypothesis — one of the most famous unsolved problems in mathematics — is equivalent to a precise bound on how far π(x) deviates from the logarithmic integral Li(x). Understanding π(x) also has practical relevance in cryptography, where estimating the density of primes near a given size guides how quickly algorithms can find large primes for encryption keys.

Common Mistakes

Mistake: Confusing π(x) with the constant π ≈ 3.14159.
Correction: The symbol π(x) in number theory is a function, not the circle constant. Context and the presence of an argument (x) distinguish the two.