Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

Prime Number Checker & Generator

Is it prime? Plus factors, next primes, the nth prime, π(x) and twin primes.

Math No upload Works offline Free, no sign-up

Up to 1,000 digits. Expressions work too: 2^61 − 1, 10^100 + 267, 30! + 1, 1e9 + 7.

Try:

Result

— —

—Digits
—Smallest prime factor
—Previous prime
—Next prime

    Next steps

    About the Prime Number Checker & Generator

    Type a whole number — or an expression such as 2^61 − 1, 10^100 + 267 or 30! + 1 — to find out whether it is prime. Numbers below 3,317,044,064,679,887,385,961,981 (about 3.3 × 10²⁴) are decided with certainty: the Miller–Rabin test with the first 13 prime bases is known to make no mistakes in that range. Larger numbers, up to 1,000 digits, get the Baillie–PSW test. It has no known counterexample, but it is not a proof, so a pass is labelled probable prime.

    For a composite number you see its smallest prime factor and, when it can be found, the full prime factorisation. Other modes find the next and previous primes of any number, the nth prime up to n = 10¹¹, the number of primes up to 10¹² — π(x) — and every prime or twin prime in a range. Everything runs in your browser, in a background thread you can stop at any time.

    How to use it

    1. Choose a mode: Check, Next & previous, nth prime, Count or List.
    2. Type a whole number. Digits can be grouped with commas (1,000,003), and you can use + − × ÷ ^ ! and brackets: 2^127 − 1, 100! + 1, 1e9 + 7.
    3. In Check the answer appears as you type. The other modes start when you press the button or Enter; long jobs show a progress bar and a Stop button.
    4. Copy any result. In List, download the primes as a text file, one per line.

    Examples

    A prime
    Input
    97
    Result
    Prime — the previous prime is 89, the next is 101
    A Carmichael number
    Input
    561
    Result
    Not prime: 561 = 3 × 11 × 17

    561 passes the simpler Fermat test for every base that has no common factor with it, but Miller–Rabin is not fooled.

    A Mersenne prime
    Input
    2^61 − 1
    Result
    Prime (2,305,843,009,213,693,951)

    Proven by deterministic Miller–Rabin with the bases 2 to 23.

    Cole’s factorisation
    Input
    2^67 − 1
    Result
    193,707,721 × 761,838,257,287

    In 1903 Frank Nelson Cole showed that this Mersenne number is not prime.

    Around a googol
    Input
    10^100 in Next & previous
    Result
    10^100 − 797 and 10^100 + 267

    Both are probable primes.

    Counting primes
    Input
    x = 10^9
    Result
    50,847,534 primes
    The millionth prime
    Input
    n = 1,000,000
    Result
    15,485,863

    Common uses

    • Checking homework on primes, factors and prime factorisation.
    • Getting test values for programs: large primes, Carmichael numbers, strong pseudoprimes.
    • Exploring prime gaps, twin primes and how closely π(x) follows x ÷ ln x.

    How primality is decided

    • Small numbers are divided by every prime up to their square root.
    • Below about 3.3 × 10²⁴, the Miller–Rabin test (Miller 1976; Rabin 1980) is run with the first prime bases. Most composite numbers fail it for every base, but some pass for a few bases — strong pseudoprimes. The smallest composite that passes for all of the first 13 primes, 2 to 41, is 3,317,044,064,679,887,385,961,981 (Sorenson & Webster 2017), so below it the test is a proof. Smaller numbers need fewer bases: below 2⁶⁴, the twelve primes 2 to 37 are enough.
    • Above that, the tool uses Baillie–PSW: a strong probable-prime test to base 2 followed by a strong Lucas probable-prime test with Selfridge’s parameters (Baillie & Wagstaff 1980). The two tests fail in unrelated ways, and no composite number that passes both has ever been found — but no one has proved that none exists, so these results are called probable primes.

    Finding factors

    Composite numbers are first divided by small primes; the first one that divides is the smallest prime factor. What is left is split with Pollard’s rho method, which quickly finds factors of up to about 12–15 digits, and each piece is tested for primality, so a complete factorisation lists only primes. Splitting a product of two very large primes, as in an RSA key, is beyond any browser tool: the number is still shown to be composite, but its factors are not found.

    Counting and listing primes

    π(x), the number of primes up to x, is computed exactly with a refinement of Legendre’s method (Lucy Hedgehog’s algorithm); π(10¹²) = 37,607,912,018 takes about a second on a typical computer. The prime number theorem says π(x) is close to x ÷ ln x and closer still to the logarithmic integral li(x); both estimates are shown next to the exact count. Lists use a segmented sieve of Eratosthenes. Twin primes are pairs that differ by 2, such as 11 and 13 — whether there are infinitely many is still an open problem.

    Sources

    • Miller, G. L. (1976). Riemann’s hypothesis and tests for primality. Journal of Computer and System Sciences 13: 300–317.
    • Rabin, M. O. (1980). Probabilistic algorithm for testing primality. Journal of Number Theory 12: 128–138.
    • Baillie, R. & Wagstaff, S. S. (1980). Lucas pseudoprimes. Mathematics of Computation 35: 1391–1417.
    • Sorenson, J. & Webster, J. (2017). Strong pseudoprimes to twelve prime bases. Mathematics of Computation 86: 985–1003.

    Limitations

    • Check accepts numbers of up to 1,000 digits. The neighbouring primes are found automatically for numbers of up to 400 digits; use Next & previous for larger ones.
    • Above 3.3 × 10²⁴ a prime is a probable prime (Baillie–PSW), not a proven one. Proving that a very large number is prime needs a dedicated method such as elliptic-curve primality proving (ECPP).
    • Factorisation stops after a few seconds. A number whose prime factors all have more than about 15 digits is shown as composite without its factors.
    • The nth prime works up to n = 10¹¹ and counting up to x = 10¹². Lists go up to 10¹⁵, for ranges of up to 100 million numbers (10 million above 10¹²); above 10¹⁵ a list can cover 10,000 numbers. At most 200,000 primes are listed or downloaded at once.

    Privacy

    Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.

    Frequently asked questions

    How do I know if a number is prime?

    A prime is a whole number greater than 1 whose only divisors are 1 and itself. To check by hand, divide it by every prime up to its square root: if none divides it, it is prime. 97 is prime because 2, 3, 5 and 7 do not divide it, and 11 × 11 = 121 is already more than 97.

    Is 1 a prime number?

    No. A prime has exactly two different divisors, and 1 has only one. Leaving 1 out keeps the prime factorisation of every whole number unique. The smallest prime is 2 — the only even one.

    What does “probable prime” mean?

    The number passed the Baillie–PSW test, which no known composite number passes, but which has not been proved to be infallible. Below about 3.3 × 10²⁴ the answers here are proofs; above that they are probable primes.

    What is the smallest prime factor of a number?

    The first prime that divides it. For an even number it is 2; for 91 it is 7, because 91 = 7 × 13. A number with no prime factor up to its square root is itself prime.

    How many primes are there below 1,000?

    There are 168. Below 100 there are 25, below 1,000,000 there are 78,498 and below 10⁹ there are 50,847,534. Use Count for any limit up to 10¹².

    What are twin primes?

    Pairs of primes that differ by 2, such as (3, 5), (11, 13) and (17, 19). There are 8 pairs below 100. No one knows whether there are infinitely many — that is the twin prime conjecture.

    Can this tool break RSA keys?

    No. An RSA modulus is the product of two primes with hundreds of digits each, and no known method can factor it in a browser — or on any ordinary computer — in a reasonable time. The tool will show that such a number is composite, but it cannot find the factors.

    Quick answers and tool search

    Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.