Prime Number Calculator
With our prime number calculator you can check if any given number is prime or composite. Keep reading if you want to learn what a prime number is, and how to check if a number is prime. We also discuss how to find prime numbers, as well as what relatively prime numbers are. As a bonus, we tell you if 1 is prime, and also what the oddest prime number is.
What is a prime number?
A natural number greater than 1 is called prime if it has exactly two factors, i.e., if the number is divisible only by 1 and itself.
When a natural number is greater than 1 and isn't prime, then it's called a composite number.
What about 1? 1 is neither prime nor composite as it has only one factor (itself).
Let's discuss some examples:
- 7 is prime because its only factors are 1 and 7. Indeed, none of the numbers preceding 7 (2, 3, 4, 5, and 6) is a factor of it because none of these numbers divide 7 without a remainder.
- 8 is composite because 2 is a factor of 8, and so 8 has more factors than just 1 and 8.
Fun fact. The oddest number among primes is 2, as it is the only even prime; all other primes are odd!
How to use our prime number calculator
Well, this prime number calculator is not a very complicated one. Just enter the number you wish to check into the calculator, and voila! Your answer will be shown below.
If your number is composite, the calculator will tell you its smallest non-trivial factor (non-trivial here means a factor greater than one). The calculator also has two extra modes:
- Relatively prime check — enter two numbers to find out whether they are coprime (share no common factor other than 1).
- Sieve of Eratosthenes — enter an upper limit and get the complete list of every prime up to that number.
How to check if a number is prime or composite
The easiest way to verify that a given integer n is prime is to apply the so-called trial division algorithm: it consists of testing whether n is divisible by any number between 2 and n − 1. That's a lot of computations. Fortunately, the number of trials can be reduced; it is sufficient to check only the divisibility of n by prime numbers that do not exceed √n. A version of the trial division algorithm powers this prime number calculator.
How to find prime numbers
Well, you cannot find every prime number because Euclid proved sometime around 300 BC that there are an infinite number of them.
If you want to find all prime numbers up to some given limit, n, you may resort to the algorithm known as the Sieve of Eratosthenes:
- Write down all numbers from 2 to n.
- Start with the smallest number in our list: 2. Circle 2 and cross out all consecutive multiples of 2 (i.e., 4, 6, 8, …).
- Take the smallest number that is not circled or crossed out: 3. Circle it and cross out all its further multiples: 6, 9, 12, ….
- Continue in the same way: find the smallest available number, p, circle it, and cross out all of its consecutive multiples.
- Check if there are numbers greater than p that have not yet been crossed out. If so, repeat step 4. If not, we're done.
The circled numbers in the list are all the primes below n. The main idea here is that every number assigned to p in any step of the algorithm is necessarily prime; otherwise, it would be crossed out as a multiple of some smaller, already circled prime number.
As you may imagine, for REALLY BIG numbers, it is quite challenging to decide whether they are prime or composite, and therefore, very elaborate methods are required. The search for big primes is ongoing: as of March 2020, the largest known prime number had 24,862,048 digits! It would take roughly 288 days (more than three-quarters of a year) to write this number down in its entirety, provided that one digit per second is being written down.
Why do prime numbers matter?
Prime numbers are the "building blocks" of the whole numbers: the Fundamental Theorem of Arithmetic states that every integer greater than 1 is either prime itself or can be written as a unique product of primes. That makes primes essential in number theory.
They are also crucial in the real world. Modern cryptography — the technology that keeps your online banking, messaging, and passwords safe — relies on the fact that it is easy to multiply two large primes together, but extraordinarily hard to factor the result back into those primes. Primes also appear in hashing, random number generation, and even in nature (for example, cicadas that emerge every 13 or 17 years).
Relatively prime numbers
Two integers are said to be relatively prime (or coprime) if the only positive integer that divides both of them is 1 — in other words, their greatest common divisor (GCD) equals 1.
Note that being relatively prime is a property of a pair of numbers, and neither of them needs to be prime itself. For example:
- 8 and 15 are relatively prime: 8 = 2 × 2 × 2 and 15 = 3 × 5 share no common factor, so GCD(8, 15) = 1.
- 12 and 18 are not relatively prime: they share the factors 2, 3 and 6, so GCD(12, 18) = 6.
Any two different prime numbers are always relatively prime, and two consecutive integers (like 14 and 15) are always relatively prime as well. Use the "relatively prime check" mode of the calculator above to test any pair yourself.
Prime or composite? A quick reference
| Number | Smallest factor > 1 | Prime or composite? |
|---|---|---|
| 1 | — | Neither |
| 2 | 2 | Prime (the only even prime) |
| 7 | 7 | Prime |
| 8 | 2 | Composite |
| 91 | 7 | Composite (91 = 7 × 13) |
| 97 | 97 | Prime |
| 100 | 2 | Composite |