Saved

Press the star next to a tool's name to save it.

All my tools

Prime Number Checker

Enter a whole number, and this prime number checker tells you whether it's prime, shows its prime factors if it isn't, and finds the nearest primes on either side.

Restored your last values ·

Enter a whole number of up to 200 digits. Commas and spaces are ignored.

–

Enter a number to check it.

See full result

A prime number checker tells you at once whether a number can only be divided evenly by 1 and itself. Enter any whole number, and this prime number checker gives you a clear answer. If the number isn't prime, you'll see its smallest factor and its full prime factorization. You'll also see the nearest prime on each side. It's helpful for homework, puzzles and programming, and because it uses a fast mathematical test rather than trying every possible divisor, it copes with numbers far too large to check by hand.

What is a prime number?

A prime number is a natural number greater than 1 that can't be made by multiplying two smaller natural numbers. For example, 5 is prime, because the only ways of writing it as a product are 1 × 5 and 5 × 1, which both involve 5 itself. A natural number greater than 1 that isn't prime is called a composite number, so 4 is composite because it equals 2 × 2. The first few primes are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29. Two is the only even prime, as every other even number can be divided by 2.

How to use the prime number checker

  1. Type a whole number into the box.
  2. Press Check.
  3. Read the verdict, along with the factors and the nearest primes.

Is 1 a prime number?

No. By definition, a prime must be greater than 1. There is a good reason for that rule. The fundamental theorem of arithmetic says that every natural number greater than 1 is either prime or can be written as a product of primes in exactly one way, apart from the order. If 1 counted as prime, you could add as many ones as you wished to any product, and that uniqueness would no longer hold. So 0 and 1 are neither prime nor composite.

How to check for a prime by hand

The simplest method is called trial division. You test whether the number is divisible by smaller numbers. You only need to go as far as its square root, since any factor larger than the square root must be paired with one that is smaller. To test 97, take the square root, which is a little under 10, and try dividing by 2, 3, 5 and 7. None of them divides it evenly, so 97 is prime. For 91, try 7, and you'll find that 91 = 7 × 13, so it's composite.

Quick divisibility rules

  • Divisible by 2: the last digit is even.
  • Divisible by 3: the sum of the digits is divisible by 3.
  • Divisible by 5: the last digit is 0 or 5.
  • Divisible by 11: the alternating sum of the digits is divisible by 11.

These rules let you rule out a large share of numbers quickly. A number ending in 0, 2, 4, 5, 6 or 8 can't be prime unless it's 2 or 5.

How this tool tests large numbers

Trial division is simple but slow when numbers get large. This checker uses the Miller–Rabin primality test, which is one of the simplest and fastest tests known. For numbers below 3,317,044,064,679,887,385,961,981, testing with the first thirteen primes as bases is enough for a certain answer. Above that limit, a number that passes is described as almost certainly prime, since the test has a very small chance of error. When a number is shown as not prime, that verdict is always correct. Finding the factors of a huge number is much harder, so a large composite number may only be partly factored.

What is prime factorization?

Prime factorization means writing a number as a product of primes. For example, 360 = 2 × 2 × 2 × 3 × 3 × 5, which can be written more briefly as 2^3 × 3^2 × 5. Factorization is the basis for finding the highest common factor and the least common multiple of two numbers, and for simplifying fractions.

Why prime numbers matter

Primes are central to number theory, and they have practical uses as well. Public-key cryptography relies on them, because multiplying two very large primes together is easy, while working backward from the result to the original primes is extremely hard. That difference helps to keep information secure online.

Famous facts about primes

There are infinitely many primes, as Euclid demonstrated around 300 BC. No known simple formula separates the primes from the composite numbers. Several old questions remain unsolved, too. Goldbach's conjecture says that every even integer greater than 2 is the sum of two primes, while the twin prime conjecture says that there are infinitely many pairs of primes that differ by two. Neither one has been proven.

Listing primes with a sieve

An ancient way to list all the primes up to a limit is the sieve of Eratosthenes. Write out the numbers from 2 up to your limit. Circle 2, and cross out all of its multiples. Move to the next number that hasn't been crossed out, circle it, and cross out its multiples too. Carry on until you pass the square root of your limit. Every number left standing is prime. It's an easy classroom exercise, and it shows how quickly the multiples of a few small primes remove most of the numbers.

Common mistakes

  • Thinking that all odd numbers are prime. 9, 15 and 21 are all composite.
  • Counting 1 as a prime. Primes start at 2.
  • Forgetting 2. It is prime, even though it is even.

Work with factors using the HCF and GCD calculator and the LCM calculator, or pick numbers to test with the random number generator.

What next

Use this often? Add Prime Number to your Home screen.

Frequently asked questions

How does the prime number checker work?

It runs the Miller–Rabin primality test, then looks for factors if the number is composite.

Is 1 a prime number?

No. A prime must be greater than 1, so 0 and 1 are neither prime nor composite.

Is 2 a prime number?

Yes. It's the smallest prime and the only even prime.

How large a number can I check?

You can check whole numbers of up to 200 digits.

What does almost certainly prime mean?

Very large numbers pass a test with a tiny chance of error, so the result is extremely likely but not proven.

What went wrong?

We only receive the reason you pick, never what you typed into the tool.

Thanks for your feedback.

More Math Tools