Mathematics

Prime Number Checker + Complete FAQ Guide — He Loves Math

Use our free Prime Number Checker to instantly test any number. Learn what prime numbers are, master trial division, key formulas, and get every common question answered with real math expressions.
Red background with large black number 1 and text "Why it's not a Prime Number?" — educational graphic explaining why 1 is not prime.
Free Math Tool & Expert Guide

Prime Number Checker & Complete FAQ Guide

Instantly test any whole number for primality — then master the definition, key formulas, historical theorems, and every common question answered with real mathematical expressions.

🔢 Prime Number Checker Calculator

Enter any whole number to instantly find out whether it is prime or composite.

What Is a Prime Number? The Complete Definition

A prime number is any natural number \( n \) that is strictly greater than 1 and has exactly two distinct positive divisors — the number 1 and the number \( n \) itself. In formal mathematical notation:

\[ n \in \mathbb{P} \iff n > 1 \quad \text{and} \quad \forall \, d \in \mathbb{Z}^+ : d \mid n \implies d \in \{1, n\} \]
Read aloud: "n is prime if and only if n is greater than 1 and every positive integer d that divides n must equal 1 or n."

The first ten prime numbers are: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29. Numbers greater than 1 that fail this test are called composite numbers — they can always be factored into smaller positive integers. For example, \( 12 = 2^2 \times 3 \) is composite, while 13 is prime.

⚡ Quick Reference: Prime vs. Composite vs. Unit

CategoryRuleExamples
PrimeExactly 2 positive divisors: 1 and itself2, 3, 5, 7, 11, 13, 97
CompositeMore than 2 positive divisors4, 6, 9, 15, 91, 100
UnitExactly 1 positive divisor (itself)1 only
SpecialZero divisors / infinite divisors0

The Fundamental Theorem of Arithmetic

Every integer greater than 1 either is a prime or can be written as a unique product of prime numbers. This result, known as the Fundamental Theorem of Arithmetic, is why primes are often called the "atoms" of mathematics:

\[ n = p_1^{\,a_1} \cdot p_2^{\,a_2} \cdot p_3^{\,a_3} \cdots p_k^{\,a_k}, \quad p_1 < p_2 < \cdots < p_k \text{ primes},\ a_i \geq 1 \] Examples: \( 360 = 2^3 \times 3^2 \times 5 \), \quad \( 1001 = 7 \times 11 \times 13 \), \quad \( 2024 = 2^3 \times 11 \times 23 \)

This uniqueness is the deep reason why the number 1 is excluded from the prime definition. If 1 were prime, every number would have infinitely many factorizations: \( 6 = 2 \times 3 = 1 \times 2 \times 3 = 1^2 \times 2 \times 3 = \cdots \). Excluding 1 preserves factorization uniqueness — the cornerstone of number theory.

How to Check if a Number is Prime — Step-by-Step

The standard method is trial division. The mathematical key insight: if a composite number \( n \) has a divisor \( d \), then at least one divisor must be at or below \( \sqrt{n} \):

\[ \text{If } n = a \times b \text{ with } a \leq b, \text{ then } a \leq \sqrt{n} \] \[ \Rightarrow \text{Test divisors } d \text{ with } 2 \leq d \leq \lfloor\sqrt{n}\rfloor \text{ only.} \]
  1. Eliminate base cases: If \( n \leq 1 \), not prime. If \( n = 2 \), it is prime (stop here). If \( n > 2 \) and \( n \) is even (i.e., \( n \bmod 2 = 0 \)), it is not prime.
  2. Compute the test limit: Calculate \( \lfloor\sqrt{n}\rfloor \). This is the highest divisor you ever need to test.
  3. Test odd divisors: Check each odd integer \( i = 3, 5, 7, \ldots \) up to \( \sqrt{n} \). If \( n \bmod i = 0 \) for any \( i \), then \( n \) is composite — stop and report the factor.
  4. Declare prime: If you complete the loop with no divisor found, \( n \) is prime.
💡 6k ± 1 Shortcut: Every prime greater than 3 satisfies \( p = 6k + 1 \) or \( p = 6k - 1 \) for some positive integer \( k \). This is because multiples of 2 and 3 cover all residues except \( 6k+1 \) and \( 6k+5 = 6(k+1)-1 \). You can use this to skip two-thirds of trial divisions.
\[ p \in \mathbb{P},\ p > 3 \implies p = 6k \pm 1 \text{ for some } k \in \mathbb{Z}^+ \]

Prime Numbers 1–100 Visual Grid

The 25 prime numbers between 1 and 100 are highlighted in green. Composite numbers appear in pink, and the unit (1) is shown in indigo.

Prime Composite Unit (1)

There are exactly 25 primes below 100. The density of primes gradually decreases as numbers grow larger — a pattern described precisely by the Prime Number Theorem.

The Prime Number Theorem

The Prime Number Theorem (PNT) answers the question: "About how many primes are there up to a given number \( x \)?" Let \( \pi(x) \) denote the prime-counting function — the number of primes less than or equal to \( x \). The theorem states:

\[ \pi(x) \sim \frac{x}{\ln x} \quad \text{as } x \to \infty \] Equivalently, using the logarithmic integral for better accuracy: \[ \pi(x) \approx \mathrm{Li}(x) = \int_2^x \frac{dt}{\ln t} \]

In plain terms: roughly 1 in every \( \ln(x) \) numbers near \( x \) is prime. At \( x = 1{,}000 \), about \( 1 \) in \( 6.9 \) numbers is prime; at \( x = 1{,}000{,}000 \), about \( 1 \) in \( 13.8 \). The theorem was proved independently by Hadamard and de la Vallée Poussin in 1896, answering one of the deepest questions in 19th-century mathematics.

Upper limit \(x\)Actual \(\pi(x)\)Approx. \(x / \ln x\)% Error
\(100\)2521.713%
\(1{,}000\)168144.813.8%
\(10{,}000\)1,2291,085.711.7%
\(1{,}000{,}000\)78,49872,382.47.8%
\(1{,}000{,}000{,}000\)50,847,53448,254,9425.1%

Special Types of Prime Numbers

Mersenne Primes

A Mersenne prime is a prime of the form \( M_p = 2^p - 1 \) where \( p \) is itself prime. Not every prime \( p \) gives a Mersenne prime, but when it does, the result can be astronomically large. The largest known prime (discovered by GIMPS in 2018) is:

\[ M_{82{,}589{,}933} = 2^{82{,}589{,}933} - 1 \quad \text{(24,862,048 digits)} \] Known small Mersenne primes: \( M_2 = 3,\ M_3 = 7,\ M_5 = 31,\ M_7 = 127,\ M_{13} = 8191 \)

Twin Primes

A twin prime pair consists of two primes that differ by exactly 2. The general form is \( (p,\ p+2) \). Examples include \( (3,5),\ (5,7),\ (11,13),\ (17,19),\ (29,31),\ (41,43),\ (71,73) \). Whether there are infinitely many twin primes remains one of the great unsolved problems in mathematics.

\[ (p,\ p+2) \text{ are twin primes} \iff \text{both } p \text{ and } p+2 \text{ are prime} \]

Sophie Germain Primes

A prime \( p \) is a Sophie Germain prime if \( 2p + 1 \) is also prime. The associated prime \( 2p+1 \) is called a safe prime. These primes have important applications in cryptography, particularly in Diffie–Hellman key exchange.

\[ p \text{ is Sophie Germain} \iff p \text{ is prime AND } 2p+1 \text{ is prime} \] Examples: \( p=2\ (2\cdot2+1=5\ ✓),\ p=3\ (7\ ✓),\ p=5\ (11\ ✓),\ p=11\ (23\ ✓),\ p=23\ (47\ ✓) \)

Fermat Primes

A Fermat prime is a prime of the form \( F_n = 2^{2^n} + 1 \). Only five are known: \( F_0=3,\ F_1=5,\ F_2=17,\ F_3=257,\ F_4=65537 \). It is unknown whether any further Fermat primes exist — all higher Fermat numbers tested so far are composite.

\[ F_n = 2^{2^n} + 1 \quad (n=0,1,2,3,4) \] \[ F_0=3,\quad F_1=5,\quad F_2=17,\quad F_3=257,\quad F_4=65537 \]

Euclid's Proof: Infinitely Many Primes

Around 300 BC, Euclid proved there are infinitely many prime numbers. His elegant proof by contradiction goes as follows:

  1. Assume finite: Suppose there are only finitely many primes \( p_1, p_2, \ldots, p_k \).
  2. Construct a new number: Form \( Q = p_1 \cdot p_2 \cdots p_k + 1 \).
  3. Analyze Q: \( Q \) is either prime or composite. If prime, it is a new prime not in our list — contradiction.
  4. If composite: \( Q \) must be divisible by some prime \( p_i \) in our list. But \( Q \bmod p_i = 1 \neq 0 \) for every \( p_i \) in the list — contradiction.
  5. Conclusion: The assumption of finitely many primes is false. There are infinitely many primes. \( \blacksquare \)
\[ Q = \left(\prod_{i=1}^{k} p_i\right) + 1 \implies Q \not\equiv 0 \pmod{p_i} \text{ for any } p_i \in \{p_1,\ldots,p_k\} \] \[ \therefore \text{ The list } \{p_1,\ldots,p_k\} \text{ is always incomplete. Primes are infinite.} \]

Why 1 Is Not a Prime Number

The number 1 has exactly one positive divisor (itself), while a prime requires exactly two. Allowing 1 to be prime would shatter the uniqueness guarantee of the Fundamental Theorem of Arithmetic — every number would have infinitely many "prime" factorizations:

\[ \text{If } 1 \text{ were prime: } 6 = 2 \times 3 = 1 \times 2 \times 3 = 1^2 \times 2 \times 3 = \cdots \] \[ \text{Reality: } 6 = 2 \times 3 \quad \text{(unique factorization, 1 excluded)} \]

Mathematicians therefore classify 1 as a unit — a separate category that is neither prime nor composite. This is a deliberate, logically necessary convention, not an arbitrary rule.

Why 2 Is the Only Even Prime

Two is the smallest and the only even prime number. Every even number greater than 2 can be written as \( 2k \) for some integer \( k > 1 \), which means it is divisible by 1, 2, \( k \), and \( 2k \) — giving it at least three distinct positive divisors, making it composite by definition.

\[ \forall\, n \in \mathbb{Z}^+,\ n > 2,\ n \text{ even}: \quad n = 2k\ (k>1) \implies 2 \mid n \implies n \text{ is composite} \]

Is N a Prime? Quick Reference Table (1–127)

The table below answers the most-searched "is ___ a prime number?" questions. Where a number is composite, the smallest non-trivial factor is shown so you can see the factorization immediately.

NumberPrime?Reason / Key Factor
1✗ NoUnit — only 1 divisor
2✓ YesSmallest prime; only even prime
3✓ YesDivisors: 1, 3
4✗ No\(4 = 2 \times 2\)
5✓ YesDivisors: 1, 5
6✗ No\(6 = 2 \times 3\)
7✓ YesDivisors: 1, 7
9✗ No\(9 = 3^2\)
11✓ YesDivisors: 1, 11
13✓ YesDivisors: 1, 13
15✗ No\(15 = 3 \times 5\)
17✓ YesDivisors: 1, 17
19✓ YesDivisors: 1, 19
21✗ No\(21 = 3 \times 7\)
23✓ YesDivisors: 1, 23
25✗ No\(25 = 5^2\)
27✗ No\(27 = 3^3\)
29✓ YesDivisors: 1, 29
31✓ YesDivisors: 1, 31
33✗ No\(33 = 3 \times 11\)
35✗ No\(35 = 5 \times 7\)
37✓ YesDivisors: 1, 37
39✗ No\(39 = 3 \times 13\)
41✓ YesDivisors: 1, 41
43✓ YesDivisors: 1, 43
47✓ YesDivisors: 1, 47
49✗ No\(49 = 7^2\)
51✗ No\(51 = 3 \times 17\)
53✓ YesDivisors: 1, 53
57✗ No\(57 = 3 \times 19\)
59✓ YesDivisors: 1, 59
61✓ YesDivisors: 1, 61
63✗ No\(63 = 7 \times 9 = 3^2 \times 7\)
67✓ YesDivisors: 1, 67
69✗ No\(69 = 3 \times 23\)
71✓ YesDivisors: 1, 71
73✓ YesDivisors: 1, 73
79✓ YesDivisors: 1, 79
81✗ No\(81 = 3^4\)
83✓ YesDivisors: 1, 83
87✗ No\(87 = 3 \times 29\)
89✓ YesDivisors: 1, 89
91✗ No\(91 = 7 \times 13\) — commonly mistaken for prime!
93✗ No\(93 = 3 \times 31\)
97✓ YesLargest prime below 100
101✓ YesDivisors: 1, 101
111✗ No\(111 = 3 \times 37\) (digit sum = 3)
113✓ YesDivisors: 1, 113
117✗ No\(117 = 9 \times 13\)
119✗ No\(119 = 7 \times 17\)
121✗ No\(121 = 11^2\)
127✓ YesMersenne prime: \(2^7 - 1\)

Divisibility Rules That Speed Up Prime Testing

Before running full trial division, apply these quick divisibility rules to instantly rule out composites. A number passes ALL of the applicable rules below only if none of the small primes divide it.

Divisible byRuleExample
2Last digit is 0, 2, 4, 6, or 8348 → ends in 8 → divisible by 2
3Sum of all digits is divisible by 3111 → 1+1+1=3 → divisible by 3
5Last digit is 0 or 5325 → ends in 5 → divisible by 5
7Double last digit, subtract from rest; repeat91 → 9 − 2×1 = 7 → divisible by 7
11Alternating digit sum (odd positions − even positions) divisible by 11121 → 1−2+1=0 → divisible by 11
13Add 4× last digit to rest; repeat91 → 9+4×1=13 → divisible by 13
Divisibility by 3 rule in formula form:
\[ 3 \mid n \iff 3 \mid \left(\sum_{i} d_i\right) \quad \text{where } d_i \text{ are the decimal digits of } n \] Divisibility by 11:
\[ 11 \mid n \iff 11 \mid \left(\sum_{i\,\text{odd}} d_i - \sum_{i\,\text{even}} d_i\right) \]

The Sieve of Eratosthenes

When you need to find all primes up to a limit \( N \), the Sieve of Eratosthenes (invented around 240 BC) is far more efficient than testing each number individually. The algorithm eliminates all multiples of each prime discovered, leaving only primes behind.

  1. Write all integers from 2 to \( N \). Mark them all as potentially prime.
  2. Start at \( p = 2 \) (the first prime). Mark all multiples of \( p \) (i.e., \( 2p, 3p, 4p, \ldots \)) as composite. Do not mark \( p \) itself.
  3. Move to the next unmarked number. That number is the next prime. Repeat step 2 for this new prime.
  4. Stop when \( p > \sqrt{N} \). All remaining unmarked numbers are prime.
Time complexity of the Sieve of Eratosthenes: \[ O\!\left(N \log \log N\right) \] Space complexity: \( O(N) \). For \( N = 10^6 \), this finds all 78,498 primes in milliseconds.
💡 Optimized Sieve: You only need to start crossing out multiples from \( p^2 \) (not from \( 2p \)), because all smaller multiples of \( p \) will have already been crossed out by earlier primes. This halves the work in practice.
\[ \text{Start crossing at } p^2,\text{ since } p \cdot k \text{ for } k < p \text{ is already marked by a smaller prime.} \]

Frequently Asked Questions About Prime Numbers

What exactly makes a number prime?

A number \( n \) is prime when it satisfies three conditions simultaneously: (1) it is a natural number, (2) it is strictly greater than 1, and (3) it has no positive divisors other than 1 and \( n \) itself. Formally:

\[ n \text{ is prime} \iff n > 1 \quad \text{and} \quad \nexists\, d \in \mathbb{Z}^+ : 1 < d < n \text{ and } d \mid n \]

The condition \( 1 < d < n \) checks for non-trivial divisors. If none exist, \( n \) is prime. If even one exists, \( n \) is composite.

Is 0 a prime number?

No. Zero fails both major criteria for primality. First, it is not greater than 1. Second, zero is divisible by every non-zero integer — it has infinitely many positive divisors. A prime must have exactly two. Zero is neither prime nor composite; it is simply zero.

\[ \forall\, k \in \mathbb{Z},\ k \neq 0 : k \mid 0 \quad \text{(0 is divisible by everything)} \]
Is 2 a prime number? Why is it special?

Yes, 2 is prime. It is both the smallest prime and the only even prime. Its divisors are exclusively 1 and 2. Every even number \( n > 2 \) satisfies \( 2 \mid n \), giving it at least three divisors (1, 2, and \( n \)), which disqualifies it from being prime.

\[ \text{Primes} \cap \text{Even numbers} = \{2\} \]
What is the square root rule for prime testing?

If a composite number \( n \) has a factor \( a \), then the complementary factor \( b = n/a \) satisfies \( b \leq \sqrt{n} \) whenever \( a \geq \sqrt{n} \). Therefore, you never need to test divisors beyond \( \lfloor\sqrt{n}\rfloor \):

\[ n = a \times b,\quad a \leq b \implies a^2 \leq n \implies a \leq \sqrt{n} \] For example, to test 97: \( \lfloor\sqrt{97}\rfloor = 9 \). Test 2, 3, 5, 7 only. None divide 97 → prime.
Why is 91 commonly mistaken for a prime?

91 looks prime because it is odd, not divisible by 3 (digit sum = 10), not ending in 0 or 5, and its square root is about 9.5 — so you'd need to test 7 specifically. Many people stop their mental check too early and miss that \( 7 \times 13 = 91 \). It is one of the most well-known "prime imposters."

\[ 91 = 7 \times 13 \quad \Rightarrow \quad 91 \text{ is composite, not prime} \]
Are there infinitely many prime numbers?

Yes. Euclid proved this around 300 BC with a clean proof by contradiction (see the detailed proof section above). No matter how large a prime you find, there are always infinitely more primes ahead of it. The prime-counting function \( \pi(x) \to \infty \) as \( x \to \infty \).

\[ \lim_{x \to \infty} \pi(x) = +\infty \]
What is the largest known prime number?

As of the most recent confirmed discovery, the largest known prime is the Mersenne prime \( 2^{82{,}589{,}933} - 1 \), found in December 2018 by the Great Internet Mersenne Prime Search (GIMPS). It contains over 24.8 million digits. Searches for larger primes are ongoing.

\[ M_{82{,}589{,}933} = 2^{82{,}589{,}933} - 1 \quad \text{(24,862,048 digits)} \]
What is a prime factorization and how do you find it?

Prime factorization expresses any composite number as a product of primes. Divide the number by its smallest prime factor, then repeat on the quotient until you reach 1. The collected prime factors form the unique factorization guaranteed by the Fundamental Theorem of Arithmetic.

Example: Find the prime factorization of 360. \[ 360 \div 2 = 180 \to 180 \div 2 = 90 \to 90 \div 2 = 45 \to 45 \div 3 = 15 \to 15 \div 3 = 5 \to 5 \div 5 = 1 \] \[ \therefore\quad 360 = 2^3 \times 3^2 \times 5 \]
How are prime numbers used in cryptography?

Modern public-key cryptography — including RSA encryption used by your browser right now — relies on the fact that multiplying two large primes is computationally trivial, but factoring their product back into the two primes is computationally infeasible for very large numbers.

RSA key generation (simplified): \[ n = p \times q \quad (p, q \text{ large primes}) \] \[ \phi(n) = (p-1)(q-1), \quad e \cdot d \equiv 1 \pmod{\phi(n)} \] Encryption: \( C \equiv M^e \pmod{n} \), \quad Decryption: \( M \equiv C^d \pmod{n} \)

Factoring a 2048-bit RSA modulus \( n \) would take modern supercomputers longer than the estimated age of the universe — which is why prime numbers are the foundation of internet security.

What is Goldbach's Conjecture?

Goldbach's Conjecture (1742) is one of the oldest unsolved problems in mathematics. It states that every even integer greater than 2 can be expressed as the sum of two prime numbers. It has been verified for all even numbers up to \( 4 \times 10^{18} \) but has never been formally proved.

\[ \forall\, n \in \mathbb{Z}^+,\, n > 1 : \exists\, p, q \in \mathbb{P} \text{ such that } 2n = p + q \] Examples: \( 4=2+2,\ 6=3+3,\ 8=3+5,\ 100=3+97=11+89=\cdots \)
What is the Riemann Hypothesis and its connection to primes?

The Riemann Hypothesis (1859) is the most famous unsolved problem in mathematics, with a $1 million Millennium Prize from the Clay Mathematics Institute. It concerns the zeros of the Riemann zeta function and, if proved true, would provide the most precise known bounds on the distribution of prime numbers.

The Riemann Zeta function: \[ \zeta(s) = \sum_{n=1}^{\infty} \frac{1}{n^s} = \prod_{p\,\text{prime}} \frac{1}{1-p^{-s}} \] The Hypothesis: All non-trivial zeros of \(\zeta(s)\) have real part \( \tfrac{1}{2} \), i.e., \( \operatorname{Re}(s) = \tfrac{1}{2} \).
What is Wilson's Theorem for identifying primes?

Wilson's Theorem gives a mathematically exact (though computationally expensive) test for primality using factorials and modular arithmetic:

\[ p \text{ is prime} \iff (p-1)! \equiv -1 \pmod{p} \] Example: \( p = 5 \): \( (5-1)! = 24 \equiv 4 \equiv -1 \pmod{5} \) ✓ prime.
Example: \( p = 4 \): \( (4-1)! = 6 \equiv 2 \pmod{4} \neq -1 \) ✗ not prime.

While Wilson's Theorem is theoretically elegant, computing \( (p-1)! \) is far too slow for large numbers, so it is not used in practice. The Sieve of Eratosthenes and Miller-Rabin tests are preferred instead.

📚 Keep Exploring Mathematics at He Loves Math

Discover hundreds of in-depth math guides, calculators, and visual tools — all free, all human-first.

Explore All Math Topics →
Shares:

Related Posts

mathematics
Math

Topics in Depth Project

Topics in Depth Secondary Collection Angles (straight line and triangle) and handout (first presented at #mathsconf10) + adapted version presented in this video with Craig Barton Angles (parallel lines) and handout (first presented at #mathsconf13) + video version presented with Craig Barton
Math Resources

A Level Math

 *NEW* Quadratic Expressions and Equations Fill in the Blanks (Editable Word | PDF | Answers)*NEW* More Quadratic Expressions and Equations Fill in the Blanks (Editable Word | PDF | Answers)​*NEW* Solving Quadratics by Rearranging Practice Grid (Editable Word | PDF | Answers)*NEW* Sketching Quadratic Graphs Fill
Math Resources

Geometry worksheets with answer sheets

 Area of Rectangles and Squares Practice Strips (Editable Word | PDF | Answers)Area of Triangles Practice Strips (Editable Word | PDF | Answers)Area of Parallelograms Practice Strips (Editable Word | PDF | Answers)Area of Trapeziums Practice Strips (Editable Word | PDF | Answers)Area of Rectangles and