webtrajans
en

What is a prime number, and how do you check if a number is prime?

A prime has exactly two divisors: 1 and itself. With one trick, only testing divisors up to the square root, you can check most numbers by hand in under a minute.

Updated: 7 min read

A prime number is a whole number greater than 1 that can only be divided evenly by 1 and by itself. 7 is prime because nothing except 1 and 7 goes into it; 9 is not, because 3 × 3 = 9. Numbers greater than 1 that are not prime are called composite. That one definition explains everything else in this guide, from checking a number by hand to how primes keep your online banking secure. To test a number instantly, use our prime number checker.

The definition, and the two exceptions people get wrong

A prime has exactly two different divisors. Two consequences trip people up:

  • 1 is not prime. It has only one divisor. This is not an arbitrary rule: if 1 counted as prime, numbers would no longer have a single prime factorisation.
  • 2 is the only even prime. Every other even number is divisible by 2, so all primes after 2 are odd. That does not mean every odd number is prime: 9, 15, 21 and 27 are odd and composite.

0 and negative numbers are not prime either. The first primes are:

Range Primes Count
1–10 2, 3, 5, 7 4
11–30 11, 13, 17, 19, 23, 29 6
31–50 31, 37, 41, 43, 47 5
1–100 — 25
1–1,000 — 168

How to check if a number is prime: trial division

The classic method is trial division: divide the number by smaller primes and see whether any of them goes in evenly. The trick that makes it fast is that you only need to test primes up to the square root of the number.

Why? If n = a × b and both a and b were bigger than √n, their product would be bigger than n. So any composite number has at least one factor less than or equal to its square root. If you find none there, there are none at all.

Step by step:

  1. Work out √n and round down.
  2. List the primes up to that value.
  3. Divide n by each. If one divides evenly, n is composite and you have found a factor.
  4. If none does, n is prime.

Example 1: 97. √97 ≈ 9.85, so test 2, 3, 5 and 7. 97 is odd, its digit sum is 16 (not divisible by 3), it doesn’t end in 0 or 5, and 7 × 13 = 91, 7 × 14 = 98. No divisor, so 97 is prime.

Example 2: 91. √91 ≈ 9.54. It passes 2, 3 and 5, but 91 ÷ 7 = 13. So 91 = 7 × 13 is composite, one of the most common “looks prime” numbers.

Example 3: 2027. √2027 ≈ 45.02, so test the 14 primes from 2 to 43. None divides it evenly, so 2027 is prime, while 2026 = 2 × 1013 is not.

For numbers with many digits, trial division gets slow. Computers use probabilistic tests such as Miller–Rabin, which is what our checker runs behind the scenes for large inputs, while still showing the trial-division reasoning for smaller numbers.

Divisibility rules that save time

Before dividing, these shortcuts rule out the smallest primes in seconds:

Divisor Rule Example
2 Last digit is even 4,718 → yes
3 Digit sum divisible by 3 2,025 → 2+0+2+5 = 9 → yes
5 Ends in 0 or 5 1,235 → yes
7 Double the last digit, subtract it from the rest; repeat 91 → 9 − 2 = 7 → yes
11 Alternating digit sum divisible by 11 1,001 → 1 − 0 + 0 − 1 = 0 → yes
13 Check directly; 1,001 = 7 × 11 × 13 helps for multiples 1,001 → yes

A number ending in 0, 2, 4, 5, 6 or 8 (and greater than 5) can never be prime, so only numbers ending in 1, 3, 7 or 9 are real candidates.

Prime factorisation

The fundamental theorem of arithmetic says every whole number above 1 can be written as a product of primes in exactly one way (ignoring order). Finding that product is called prime factorisation.

Divide repeatedly by the smallest prime that fits:

360 ÷ 2 = 180
180 ÷ 2 = 90
 90 ÷ 2 = 45
 45 ÷ 3 = 15
 15 ÷ 3 = 5
  5 ÷ 5 = 1      →  360 = 2³ × 3² × 5

Other examples: 1,001 = 7 × 11 × 13 and 323 = 17 × 19.

Factorisation is the basis of the greatest common divisor and least common multiple. For 48 = 2⁴ × 3 and 180 = 2² × 3² × 5, the GCD takes the lowest shared powers (2² × 3 = 12) and the LCM the highest powers of every prime (2⁴ × 3² × 5 = 720). Our GCD and LCM calculator shows both, with the factorisation of each number.

The sieve of Eratosthenes

To list all primes up to a limit, the sieve of Eratosthenes is faster than testing numbers one by one:

  1. Write the numbers from 2 to the limit.
  2. Circle 2 and cross out all its multiples (4, 6, 8…).
  3. Move to the next number not crossed out (3), circle it and cross out its multiples.
  4. Repeat until you pass √limit. Everything left is prime.

For a limit of 50 you only sieve with 2, 3, 5 and 7 (since √50 ≈ 7.07), and 15 primes remain. In code:

def sieve(limit):
    is_prime = [True] * (limit + 1)
    is_prime[0] = is_prime[1] = False
    for p in range(2, int(limit ** 0.5) + 1):
        if is_prime[p]:
            for m in range(p * p, limit + 1, p):
                is_prime[m] = False
    return [n for n, ok in enumerate(is_prime) if ok]

print(len(sieve(100)))  # 25

The prime number checker also lists every prime in a range of up to 100,000 numbers.

How many primes are there?

Infinitely many. Euclid’s proof is short: multiply any finite list of primes together and add 1. The result leaves remainder 1 when divided by every prime on the list, so its prime factors must be new primes the list missed.

Primes thin out as numbers grow (25 below 100, 168 below 1,000), but they never stop. The record holders are Mersenne primes, primes of the form 2ᵖ − 1. Not every such number is prime: 2⁷ − 1 = 127 is prime, but 2¹¹ − 1 = 2,047 = 23 × 89. As of November 2026, the largest known prime is 2¹³⁶²⁷⁹⁸⁴¹ − 1, found by the volunteer GIMPS project in October 2024 and 41,024,320 digits long.

Primes in cryptography (RSA)

The RSA encryption scheme, still widely used for digital signatures and key exchange, relies on an asymmetry: multiplying two large primes is easy, but factoring the product back is extremely hard.

A toy version with tiny primes:

  • Pick p = 61 and q = 53, so n = 61 × 53 = 3,233.
  • φ(n) = (61 − 1) × (53 − 1) = 3,120.
  • Choose the public exponent e = 17; the private exponent d = 2,753, because 17 × 2,753 = 46,801 = 15 × 3,120 + 1.
  • Encrypting the message 65 gives 65¹⁷ mod 3,233 = 2,790; decrypting gives 2,790²⁷⁵³ mod 3,233 = 65 again.

Anyone can factor 3,233 instantly. Real keys use an n of 2,048 bits or more (over 600 decimal digits), which no known method can factor in practical time. If you are curious how this connects to everyday security, see our guide to creating strong passwords.

Common mistakes

  • Calling 1 prime, or forgetting that 2 is.
  • Assuming all odd numbers are prime (9, 15, 21, 91…).
  • Testing every number up to n instead of only primes up to √n.
  • Stopping after 2, 3 and 5: numbers like 49, 77, 119 (7 × 17) and 221 (13 × 17) need 7, 11 or 13.

Frequently asked questions

Is 1 a prime number?

No. A prime must have exactly two different divisors, and 1 has only one. Excluding 1 also keeps prime factorisation unique: otherwise 6 could be written as 2 × 3, 1 × 2 × 3, 1 × 1 × 2 × 3 and so on.

Why is 2 the only even prime?

Every other even number is divisible by 2, so it has at least three divisors (1, 2 and itself). That makes 2 the only even prime and every other prime odd.

How do I quickly check if a number is prime?

Divide it by the primes 2, 3, 5, 7, 11… up to its square root. If none divides evenly, the number is prime. For 97, √97 ≈ 9.85, and 2, 3, 5 and 7 all leave a remainder, so 97 is prime.

What is the largest known prime number?

As of November 2026 it is the Mersenne prime 2^136,279,841 − 1, found by the GIMPS volunteer project in October 2024. Written out, it has 41,024,320 digits.

Related guides