guide

How to Check If a Number Is Prime (2026)

By Rui Barreira · Last updated: 18 June 2026

A prime number is a whole number greater than 1 that has exactly two divisors: 1 and itself. Determining whether a number is prime is a foundational problem in mathematics and computer science, with applications in cryptography, hashing, and random number generation.

How primality testing works

The simplest approach is trial division: check whether the number n is divisible by any integer from 2 up to the square root of n. If no divisor is found, the number is prime. You only need to check up to the square root because if n has a factor larger than its square root, the corresponding paired factor must be smaller than it — so you would have already found it. For large numbers, more advanced algorithms like the Miller-Rabin probabilistic test or the AKS deterministic test are used, but trial division is sufficient for numbers up to several million.

Quick reference: prime status of common numbers

Small primes come up frequently in programming, cryptography key sizes, and math puzzles. Here is a reference table for numbers up to 50.

NumberPrime?Reason if composite
1NoBy definition, primes must be greater than 1
2Yes
9NoDivisible by 3
17Yes
25NoDivisible by 5
37Yes
49NoDivisible by 7
51NoDivisible by 3 and 17

Edge cases to watch for

The number 1 is not prime — a common source of off-by-one errors in implementations. Negative numbers and zero are also not prime by convention. The number 2 is the only even prime; every other even number is divisible by 2 and therefore composite. If you are writing your own check, handling these special cases before entering the trial division loop avoids unnecessary computation and wrong results.

Use the Prime Number Checker to test any number instantly, directly in your browser with no data sent to a server.

Frequently Asked Questions

Is this tool free?
Yes — completely free, no signup required. All processing happens in your browser.
Does the tool work offline?
Once loaded, most features work without an internet connection since everything runs client-side.
More free toolsSee all 469
Merge PDFsCompress ImageJSON FormatterPassword GeneratorVAT CalculatorQR Code Generator
How to Check If a Number Is Prime (2026) | brevio