How to Find Prime Numbers

Last Updated : 14 Sep, 2026

Prime numbers are those numbers that have only two factors: 1 and the number itself.

Below are some methods to check whether a number is prime or not:

1. Even numbers are not prime [except 2]

All even numbers are non-prime, except for 2. This means if a number ends with 0, 2, 4, 6, or 8, it is not prime.

2. Division Method

One simple method is to divide numbers by all integers from 2 up to the square root of a given number.

Example:

Number = 29

Find square root of 29, which is 5.39. Now, we need to divide 29 by each whole number which is 2 to 5.

29 ÷ 2 = not a whole number,
29 ÷ 3 = not a whole number,
29 ÷ 4 = not a whole number,
29 ÷ 5 = not a whole number.

We can see non of these results are in whole number. So, 29 is a Prime Number.

This method is not suitable for very small primes [like 2, 3, 5, 7, etc.]. It is better to use divisibility rules for such small numbers. Also, this method doesn't work well for large numbers [say, 100003] since the square root of a large number itself might be a large number [316 in this case]. You might need to check the divisibility of those many numbers.

3. Trial Division Method

The trial division method checks for primes by dividing the numbers by all possible divisors to check if any divisor evenly divides without a remainder. This method is very similar to the above-discussed method. The divisor method checks only up to the square root of the number, but the trial division method continues dividing by all integers up to the number itself [except 1 and the number itself].

Example:

Number = 17

Divide 17 by 2 -> doesn’t divide evenly (not divisible by 2).
Divide 17 by 3 -> doesn’t divide evenly.

--> We can skip checking for all even numbers. Since it is not divisible by 2, it can’t be divisible by any higher even numbers.

Divide 17 by 5 -> doesn’t divide evenly.

We can continue checking with all odd numbers till 15 [7, 9, 11, etc.]. Since none of these divide 17 evenly, it's clear that 17 is prime.

This method is time consuming as well for large numbers. If N is 100000, then you will have to check all divisors up to N-1. Hence, this method is useful for a small number only.

4. Factorization Method

In this method, we break down the numbers into prime factors. If the number has a product of two smaller numbers (other than 1 and itself), then it is composite. Otherwise, it is Prime.

Examples:

Number = 17

Divide 17 by 2 -> Not divisible, leaves a remainder
Divide 17 by 3 -> Not divisible, leaves a remainder
Divide 17 by 5 -> Not divisible, leaves a remainder
We can keep on checking. There is no smaller number which divide 17 evenly. So, 17 is Prime.

Number = 35

Divide 35 by 2 -> Not divisible, leaves a remainder
Divide 35 by 3 -> Not divisible, leaves a remainder
Divide 35 by 3 -> Not divisible, leaves a remainder
Divide 35 by 7 -> It's divisible evenly. 5 x 7. So, 35 is Not Prime.

5. Prime Numbers in the Form 6n ± 1

Any prime number (greater than 3) can be written in the form of 6n + 1 or 6n - 1, where n is a whole number.

For example:

  • The number 19 can be written as 6(3) + 1 = 19, making it a prime number.
  • The number 23 can be expressed as 6(4) - 1 = 23, confirming it is also prime.

Exceptions: This rule helps identify possible prime numbers, but not all numbers of the form 6n+1 or 6n−1 are prime, so further checking is needed.

25 = 6(4) + 1 is not prime (it is 52)
35 = 6(6) - 1 is not prime (it is 5 × 7)

6. For prime numbers greater than 40

To know the prime numbers greater than 40, this formula can be used: n2 + n + 41, where n = 0, 1, 2, ….., 39
For example:
(0)2 + 0 + 0 = 41
(1)2 + 1 + 41 = 43
(2)2 + 2 + 41 = 47

Note -

For n>39, this formula can give composite numbers which is non-prime. So, we need to further verify to confirm if the result is correct or not.
Example - (41)2 + 41 + 41 = 1763. It is divisible by 41 and 43, so 1763 is not Prime.

Comment

Explore