Prime Number Calculator

Check if a number is prime. The calculator also shows its prime factors, and the nearest prime numbers above and below it.

How it is calculated

Numbers below 2 are not prime by definition.

The number is tested for divisibility by 2, then by odd numbers only.

Testing stops at the square root, because any factor above it must pair with one below it — so if none were found by then, none exist.

Formula

Prime: A whole number above 1 with exactly two factors

Test: Check divisors up to √n only

Worked example

Checking whether 97 is prime.

Number: 97

√97 is about 9.8, so only divisors up to 9 need testing

97 is not divisible by 2, 3, 5 or 7

No factors found, so 97 has only 1 and itself

Answer: 97 is prime

What is the Prime Number Calculator?

A prime number calculator tests whether a whole number is prime, meaning it has exactly two factors, 1 and itself. If the number is not prime, it shows the divisions that break it into prime factors. It also reports the nearest prime above and below, which helps in puzzles and number theory exercises.

Primes are the building blocks of all whole numbers, and questions about them run from Class 6 factor trees to Class 10 proofs and competitive exam aptitude sections. They also matter outside school: the security of online banking and many encrypted connections relies on the difficulty of factorising very large numbers into primes. The calculator answers a precise question: can this number be divided evenly by anything other than 1 and itself?

How to calculate it by hand

1. If the number n is less than 2, it is not prime. If n is 2 or 3, it is prime.

2. If n is even and greater than 2, it is not prime.

3. Find √n and round it down.

4. Divide n by 3, 5, 7 and every odd number up to that limit.

5. If any division leaves no remainder, n is composite; that divisor is a factor.

6. If none divides evenly, n is prime.

7. For a composite n, keep dividing by the smallest prime that fits to get its prime factorisation.

Why testing up to the square root is enough

If n = a × b with both factors larger than √n, then a × b would be larger than √n × √n = n, which is impossible. So in any factor pair, at least one factor is at most √n. If no number up to √n divides n, no factor pair exists and n is prime. For 221, √221 is about 14.9, so only divisors up to 14 need checking. Testing only 2 and odd numbers halves the work again, since every even number beyond 2 fails whenever 2 fails.

Why 1 is not prime

The fundamental theorem of arithmetic says every whole number above 1 can be written as a product of primes in exactly one way, apart from order. If 1 were prime, uniqueness would break, because 6 = 2 × 3 = 1 × 2 × 3 = 1 × 1 × 2 × 3 and so on. Defining primes as having exactly two distinct factors excludes 1 neatly. By the same definition 2 is prime, and it is the only even prime.

Semiprimes that look prime

Numbers such as 91 = 7 × 13, 221 = 13 × 17 and 391 = 17 × 23 are products of two primes. They pass the quick tests for 2, 3 and 5 and often fool people into calling them prime. The digit-sum test catches multiples of 3 and the last digit catches 2 and 5, but for 7, 11, 13 and beyond you must actually divide. There is no simple formula that generates all primes, and they thin out as numbers grow, though there are infinitely many.

Worked example, step by step

In a maths olympiad practice sheet, Aditya is asked whether 221 is a prime number and, if not, to write its prime factors.

Divide by 13: 221 ÷ 13

Remaining value is prime: 17 is prime — stop

Answer: Is 221 prime? No — it is not prime; Prime factorisation 13 × 17; Next prime 223

Common mistakes to avoid

Calling 1 a prime number.

Assuming every odd number is prime, or that numbers ending in 1, 3, 7 or 9 must be prime.

Declaring a number like 91 or 221 prime after testing only 2, 3 and 5.

Checking divisors all the way up to n instead of stopping at √n, which is slow but not wrong.

Forgetting that 2 is prime because it is even.

Where it is used

Class 6 to Class 10 questions on primes, composites, factor trees and coprime pairs.

Aptitude and olympiad problems that ask for the nearest prime or the number of primes in a range.

Understanding why RSA-style encryption, used by secure websites, depends on large primes.

Choosing prime sizes for hash tables in programming.

Frequently asked questions

Why is 1 not a prime number?

A prime number must have exactly two different factors. The number 1 has only one factor — itself. Leaving 1 out also keeps prime factorisation working correctly, since you could otherwise multiply by 1 forever.

Is 2 really prime?

Yes, and it is the only even prime number. Every other even number can be divided by 2, so it has at least three factors.

Why only check up to the square root?

Factors come in pairs that multiply together to give the number. If one factor in a pair is bigger than the square root, the other one must be smaller. So if nothing below the square root divides evenly, nothing above it will either.

Loading Gananayantra…