Calculus How To

Prime Counting Function

Share on

Types of Function >

prime counting function
The prime counting function answers the question “How many primes are there less than or equal to a real number x?” For example, π(2) = 2, because there are two primes less than or equal to 2.

The function is denoted by π(x), which has nothing to do with the number π, ≈3.14. That notation originated with mathematician Edmund Landau in 1909 and is what Eric Weisstein calls “unfortunate”.

The first few values of π(n) for n = {1,2,3,…n} are 0, 1, 2, 2, 3, 3, 4, 4, 4, 4, 5, 5, 6. For example, at n = 12 there are 5 primes (2, 3, 5, 7, 11).

There’s More Than One Prime Counting Function

There isn’t one single function that can be called the counting function. In fact, there isn’t a simple arithmetic formula for determining π(n). All are relatively complex, and all are approximations (i.e. every one of them has a margins of error).

Two functions from the literature:

  • Minác’s formula (Ribenboim, 1995, p181):

  • Willans’ formulae (Ribenboim, 1995, p180):

There are many, many more. Kotnik (2008) discusses many of them , along with the history of the prime counting function, in his paper The prime-counting function and its analytic approximations (PDF).


Borwein, J. and Bailey, D. “Prime Numbers and the Zeta Function.” Mathematics by Experiment: Plausible Reasoning in the 21st Century. Wellesley, MA: A K Peters, pp. 63-72, 2003.
Derbyshire, J. Prime Obsession: Bernhard Riemann and the Greatest Unsolved Problem in Mathematics. New York: Penguin, 2004.
Hardy, G. H. and Wright, E. M. An Introduction to the Theory of Numbers, 5th ed. Oxford, England: Clarendon Press, 1979.
Kotnik, T. (2008). The prime-counting function and its analytic
approximations. Adv Comput Math (2008) 29:55–70
DOI 10.1007/s10444-007-9039-2
Ribenboim, P. (1995). The Little Book of Big Primes. Springer Verlag.
Vardi, I. Computational Recreations in Mathematica. Reading, MA: Addison-Wesley, pp. 74-76, 1991.
Weisstein, Eric W. “Prime Counting Function.” From MathWorld–A Wolfram Web Resource.
Image: Self [CC BY-SA 3.0 (]

Stephanie Glen. "Prime Counting Function" From Calculus for the rest of us!

Need help with a homework or test question? With Chegg Study, you can get step-by-step solutions to your questions from an expert in the field. Your first 30 minutes with a Chegg tutor is free!

Leave a Reply

Your email address will not be published. Required fields are marked *