Skip to content

How to Find the Next Prime Number

    To find the next prime number, start with the number just after your given number and test each whole number until you find one with exactly two positive divisors: 1 and itself. The first number that passes that test is the next prime number.

    Direct Answer

    The next prime number after n is the smallest prime number greater than n. In notation, it can be written as:

    next prime after n = the smallest prime p where p > n

    For example, the next prime after 100 is 101, because 101 has no positive divisors other than 1 and 101.

    Basic Method for Finding the Next Prime Number

    Step-by-Step Logic

    1. Take the starting number n.
    2. Move to the next whole number, n + 1.
    3. If the candidate is less than 2, the next prime is 2.
    4. If the candidate is greater than 2 and even, skip it.
    5. Test whether the candidate has any factor from 2 up to its square root.
    6. If no factor divides it evenly, the candidate is prime.
    7. If it is not prime, move to the next candidate and repeat.

    This works because every composite number has at least one factor less than or equal to its square root. So you do not need to test every possible divisor.

    Square Root Test

    To test whether a candidate number m is prime, check possible divisors only up to:

    √m

    If no whole number from 2 through √m divides m evenly, then m is prime.

    Example: Find the Next Prime After 120

    Start after 120. The next whole number is 121.

    Testing numbers after 120
    CandidateTestResult
    121121 = 11 × 11Composite
    122Even number greater than 2Composite
    123123 is divisible by 3Composite
    124Even number greater than 2Composite
    125125 is divisible by 5Composite
    126Even number greater than 2Composite
    127No divisor up to √127Prime

    The next prime number after 120 is 127.

    Why You Can Skip Even Numbers

    After 2, every even number is composite because it is divisible by 2. That means a next-prime search usually checks only odd candidates.

    Math Note

    2 is the only even prime number. If your starting number is less than 2, the next prime number is 2. If your starting number is 2 or greater, the next prime must be odd.

    Check the Next Number

    Enter a whole number and test whether a nearby number is prime or composite.

    Enter a number
    Works for integers up to 15 digits

    Fast Manual Process

    If n Is Less Than 2

    The next prime is 2.

    If n Is Even and at Least 2

    Start testing from n + 1, which is odd.

    If n Is Odd

    Start testing from n + 2, because n + 1 is even.

    For each odd candidate, test divisibility by small primes such as 3, 5, 7, 11, 13, continuing only up to the square root of the candidate.

    Examples of Next Prime Numbers

    Next prime examples
    Starting NumberNext Prime NumberReason
    122 is the smallest prime number.
    101111 has only two positive divisors.
    202321 is divisible by 3, and 22 is even.
    100101101 has no divisor up to √101.
    113127114 through 126 are not prime.
    100010091009 passes the square root test.

    Trial Division vs Sieve Method

    For one number, trial division is usually enough. For a whole range of numbers, the Sieve of Eratosthenes is often more efficient because it removes multiples in batches.

    Methods for finding the next prime
    MethodBest UseHow It Works
    Trial DivisionFinding the next prime after one numberTests candidate numbers for divisibility up to the square root.
    Square Root TestReducing manual workStops divisor checks once the divisor is greater than √m.
    Sieve of EratosthenesFinding many primes in a rangeMarks multiples of known primes as composite.
    Computer Primality TestTesting larger numbersUses programmed rules or algorithms to test primality.

    Common Mistakes

    Prime and Not Prime Are Not Always Prime and Composite

    A composite number is a whole number greater than 1 with more than two positive divisors. But 0, 1, and negative integers are not composite under the standard elementary definition. They are simply not prime.

    Do Not Stop at the First Odd Number

    Odd does not mean prime. For example, 121 is odd, but it is composite because 121 = 11 × 11.

    Using a Prime Checker

    If you want to test a candidate directly, use PrimeOrNot’s prime number checker. It can help verify whether a number near your starting point is prime, composite, or neither.

    Related Tool

    To find the next prime manually, test the numbers after your starting value. To verify a candidate, check whether it has exactly two positive divisors.

    FAQ

    What Is the Next Prime Number After 1?

    The next prime number after 1 is 2. The number 1 is not prime because it has only one positive divisor.

    What Is the Next Prime Number After 2?

    The next prime number after 2 is 3. Although 2 is prime, the next prime must be greater than 2.

    Can the Next Prime Be an Even Number?

    Only if the next prime is 2. Every even number greater than 2 is divisible by 2, so it is composite.

    Why Test Only Up to the Square Root?

    If a number has a factor greater than its square root, it must also have a matching factor smaller than its square root. So checking beyond the square root is not needed.

    Is There Always a Next Prime Number?

    Yes. There are infinitely many prime numbers, so for any whole number, there is always a prime number greater than it.