Calculator

Prime Number Calculator | Check Primes Instantly

Check prime or composite numbers, find prime factors and divisors, list primes in a range, and find nth or neighboring primes. Includes worked examples and practice answers.
Prime number calculator with a grid from 1 to 25 highlighting 2, 3, 5, 7, 11, 13, 17, 19 and 23 as prime.

NUMBER THEORY • FIVE TOOLS

Prime numbers, with reasons

Check prime or composite status, factor an integer, list primes in a range, find the nth prime, or locate the surrounding primes. Start with a question, then use the worked guide to understand the answer.

Calculate Prime Numbers

Select a mode, enter your number or range, and calculate. The tool supports prime checking, prime factorization, prime lists, nth prime lookup, and nearest-prime search.

Use signed integers with digits only (no decimals or commas), up to one trillion in absolute value. Ranges may have endpoints at most 1,000,000 apart; nth positions run from 1 to 100,000. See the mode guide below.

Check a number, then understand the result

This calculator answers five related questions: Is an integer prime? What are its prime factors? Which primes lie in an interval? What is the prime at a particular position? Which primes come immediately before and after a number? The explanation below helps you check a result by hand instead of memorizing a list.

A prime number is an integer greater than 1 with exactly two positive divisors: 1 and itself. For example, 13 has divisors 1 and 13. The number 12 has six positive divisors, so it is composite. Zero, one and negative integers are neither prime nor composite under the elementary definition used here.

How to use the five calculator modes

  1. Choose a mode. Prime Check classifies an integer and can show trial-division steps. Prime Factors gives a repeated-prime product, exponents, a divisor count and an optional positive-divisor list.
  2. Enter complete integers. Type digits with an optional leading + or − sign. Do not enter commas, decimal points, fractions or scientific notation. A decimal such as 7.9 is rejected rather than changed to 7. Use the ordinary keyboard minus sign (-) for negative inputs.
  3. Calculate or press Enter in an input. A changed input or mode clears the previous result so it cannot be mistaken for the new answer. Reset restores that mode’s example.
  4. Read the explanation. Range mode counts all primes in the inclusive interval, even when only the first 200, 500 or 1,000 are shown. The previous/next search is strict: entering 13 returns 11 and 17, not 13 itself.
Explicit limits: integer inputs and range endpoints must be between −1,000,000,000,000 and 1,000,000,000,000. The difference between range endpoints may be at most 1,000,000; endpoints may be entered in either order. nth Prime accepts positions 1–100,000. Neighbor searches use a bounded window of up to 1,000,000 beyond the input and report a search-limit message if no prime is found within it. These bounds keep the algorithms practical in a browser. This is an educational tool, not a cryptographic prime generator.

Negative inputs in Prime Factors are written with a separate −1 factor; the listed positive divisors belong to the absolute value. The values 0, 1 and −1 do not have a prime factorization of the kind this mode displays.

Prime, composite or neither?

Classification uses positive divisors and integers greater than 1
NumberReasonClassification
2Its positive divisors are exactly 1 and 2Prime
13Its positive divisors are exactly 1 and 13Prime
1515 = 3 × 5 has nontrivial factorsComposite
1Only one positive divisor: 1Neither
0 or a negative integerOutside the greater-than-1 definitionNeither

Two is the only even prime. Every even integer greater than 2 is divisible by 2 and has another positive factor. Being odd is not enough: 9, 15, 21, 25 and 49 are all composite. For a fuller explanation of the special case, see why 1 is not prime.

There are infinitely many primes, but they are not evenly spaced. Euclid’s idea is to suppose that a finite list contains every prime, multiply the primes on that list and add 1. None of the listed primes divides the new number, because each leaves remainder 1. The new number must therefore be prime itself or have a prime factor missing from the list. This contradicts the claim that the list was complete. The product-plus-one number is not necessarily prime.

Why test only up to the square root?

For an integer n ≥ 2, a composite number has a factor pair n = a × b with both factors greater than 1. At least one of a and b must be at most √n: if both were greater than √n, their product would exceed n. So finding no divisor from 2 through floor(√n) proves that n is prime.

The endpoint matters. For 49, √49 = 7 and 7 × 7 = 49. A test that stops before 7 would incorrectly label 49 prime. For 97, √97 is approximately 9.85, so floor(√97) = 9. Testing the prime candidates 2, 3, 5 and 7 is sufficient. This tool first handles 2 and even numbers, then checks odd divisors through the bound. Checking an extra composite odd divisor such as 9 is harmless.

Trial division here is deterministic within the supported bounds; it does not return a probability. The displayed explanation shows a bounded selection of steps for readability and says when intermediate checks are omitted. To practise the division itself, use the long division calculator.

Build a prime factorization

Split a number into any convenient factor pair, then keep splitting every composite branch. Stop only when every leaf is prime. Different first splits produce the same primes with the same multiplicities, apart from order. This is the Fundamental Theorem of Arithmetic for integers greater than 1.

Factor tree: 84 splits into 2 and 42; 42 splits into 2 and 21; 21 splits into 3 and 7. Therefore 84 equals 2 squared times 3 times 7.
A complete tree for 84 ends at the prime leaves 2, 2, 3 and 7. Multiply all the leaves, including repeated ones.

Here 84 = 2 × 2 × 3 × 7 = 2² × 3 × 7. The distinct prime factors are 2, 3 and 7. The full factorization contains two copies of 2. A caret in calculator output means an exponent: 2^3 means 2³ = 8, not 2 × 3.

For negative integers, keep the sign separate: −84 = −1 × 2² × 3 × 7. The factor −1 is not a prime number. Divisibility questions about positive factors can then be answered using |−84| = 84.

Useful formulas, with their conditions

These statements apply to positive integers n greater than 1. In a prime-power factorization, p₁, …, pₖ are distinct primes and a₁, …, aₖ are positive integer exponents.

Composite-number test

n is composite exactly when some integer d satisfies 1 < d < n and divides n with remainder 0.

Square-root test

n is prime exactly when no integer d with 2 ≤ d ≤ floor(√n) divides n.

Prime-power form

n = p₁a₁ × p₂a₂ × … × pₖaₖ

Number of positive divisors

τ(n) = (a₁ + 1)(a₂ + 1)…(aₖ + 1)

Sum of positive divisors

For each prime power pa, form 1 + p + p² + … + pa. Multiply these sums for all distinct prime factors. Equivalently, each sum is (pa+1 − 1)/(p − 1).

Why add 1 to an exponent when counting divisors? A divisor of 2³ × 3² × 5 can choose 2 to the power 0, 1, 2 or 3; 3 to the power 0, 1 or 2; and 5 to the power 0 or 1. That gives 4 × 3 × 2 = 24 independent choices. Exponent zero includes the choice to omit that prime.

Find primes in a range with a sieve

To list primes up to 30, write the integers from 2 through 30. Keep 2 and cross out its larger multiples. Keep the next unmarked number, 3, and cross out its larger multiples. Then do the same for 5. Since the next prime is 7 and 7² > 30, every composite has already been marked.

Numbers 1 to 30 with exactly ten primes highlighted: 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29. One is neither prime nor composite.
The Sieve of Eratosthenes leaves ten primes up to 30. In an efficient implementation, crossing out multiples of p starts at p² because smaller multiples already have a smaller prime factor.

This calculator uses a segmented sieve for a requested interval. It finds the small primes needed up to the square root of the upper endpoint, then marks their multiples only inside the interval. A narrow range near a large number therefore does not require an array extending all the way from zero to that number.

Endpoints are included if they are prime. From 11 to 19, the answer is 11, 13, 17, 19. From 14 to 16, there are no primes. The total count and displayed list length are different when the interval contains more primes than your chosen display limit.

Seven worked examples

1. Is 97 prime?

The test bound is floor(√97) = 9. The prime candidates below that bound are 2, 3, 5 and 7. The number is odd; its digit sum 16 is not divisible by 3; it does not end in 0 or 5; and 97 = 7 × 13 + 6. None divides 97, so 97 is prime.

2. Is 221 prime?

Since 14² = 196 and 15² = 225, test prime divisors through 14: 2, 3, 5, 7, 11 and 13. The final candidate works: 221 = 13 × 17. Therefore 221 is composite. Not ending in an even digit or 5 does not prove primality.

3. Factor 360 and count its divisors

Repeated division gives 360 → 180 → 90 → 45 when dividing by 2, then 45 → 15 → 5 when dividing by 3. The remaining 5 is prime. Thus 360 = 2³ × 3² × 5. It has (3 + 1)(2 + 1)(1 + 1) = 24 positive divisors. Their sum is (1 + 2 + 4 + 8)(1 + 3 + 9)(1 + 5) = 15 × 13 × 6 = 1,170.

4. List primes from 1 to 30

The list is 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, so the count is 10. One is excluded; 30 is composite. Reversing the two inputs returns the same interval.

5. Find the 25th prime

Position counts start with 2 as the first prime, 3 as the second and 5 as the third. Counting onward gives 97 as the 25th prime. Its immediate neighboring primes are 89 and 101. This asks for a position in the prime sequence; it does not ask whether 25 is prime.

6. Find the primes around 1,000

The previous prime is 997, a distance of 3 below 1,000. The next is 1,009, a distance of 9 above it. In the intervening upper candidates, 1,001 = 7 × 11 × 13, 1,003 = 17 × 59, 1,005 is divisible by 5 and 1,007 = 19 × 53; even candidates are composite. Of the surrounding pair, 997 is closer.

7. Use prime factors to simplify a fraction

To simplify 84/126, write 84 = 2² × 3 × 7 and 126 = 2 × 3² × 7. Cancel the common product 2 × 3 × 7 = 42. The fraction becomes 2/3. The same factorizations give a greatest common factor of 42 and a least common multiple of 2² × 3² × 7 = 252.

Practice: predict first, then check

Use a factor, a complete trial-division argument or the definition to justify each answer. Open an answer only after trying it.

1. Classify 0, 1, 2 and 9

0 and 1 are neither prime nor composite. 2 is prime, with exactly two positive divisors. 9 is composite because 9 = 3 × 3.

2. Is 91 prime?

No. 91 = 7 × 13, so it is composite. Seven lies below √91, which is between 9 and 10.

3. Is 101 prime?

Yes. Since 10² < 101 < 11², check prime divisors 2, 3, 5 and 7. None divides 101; 101 = 7 × 14 + 3 is the final check.

4. Why must the test include 11 for 121?

Because √121 = 11 and 121 = 11². Stopping below the square root misses this divisor and gives the wrong answer.

5. Find the prime factorization of 72

72 = 8 × 9 = 2³ × 3². The expanded product is 2 × 2 × 2 × 3 × 3.

6. How many positive divisors does 72 have?

(3 + 1)(2 + 1) = 12. They are 1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36 and 72.

7. List the primes from 20 through 40

23, 29, 31 and 37. There are four. In particular, 21, 25, 27, 33, 35 and 39 are odd but composite.

8. What is the 10th prime?

29. The first ten are 2, 3, 5, 7, 11, 13, 17, 19, 23 and 29.

9. Which primes strictly surround 13?

11 and 17. Although 13 itself is prime, this mode excludes the input and finds the immediately preceding and following primes.

10. Factor −60 without losing its sign

−60 = −1 × 2² × 3 × 5. The positive divisors of |−60| = 60 number (2 + 1)(1 + 1)(1 + 1) = 12. Minus one is a sign factor, not a prime.

11. Does a display limit of 200 mean that 1 to 1,000 contains 200 primes?

No. It contains 168 primes. A display limit of 200 is a maximum list length, not a claim that 200 exist. Conversely, 1 to 10,000 contains 1,229 primes even if only the first 200 are displayed.

12. Find the GCF and LCM of 18 and 24

18 = 2 × 3² and 24 = 2³ × 3. Take the smaller shared exponents for GCF = 2 × 3 = 6. Take the larger exponents for LCM = 2³ × 3² = 72.

Common mistakes to avoid

  • “Not prime” does not always mean composite. First check the greater-than-1 condition. One has only one positive divisor.
  • A prime factor is not every factor. The positive factors of 12 are 1, 2, 3, 4, 6, 12; its distinct prime factors are only 2 and 3.
  • Keep repeated factors. Writing 84 = 2 × 3 × 7 loses a factor of 2. Multiply your factorization back to check it.
  • Test the square-root endpoint. Prime squares such as 49 and 121 require the divisor equal to their square root.
  • Do not round a non-integer into a prime test. Primality here is a property of integers. The tool rejects 7.9 rather than testing 7.
  • Prime gaps are not a fixed pattern. After 2, every prime is odd, but most odd integers are not prime. Twin-prime examples such as 11 and 13 do not imply every pair of odd neighbors is prime.

For broader practice, try the algebra worksheet guide or explore the nth-term calculator for supported arithmetic and geometric patterns. A simple constant-difference rule does not generate the sequence of all primes.

Prime number calculator FAQs

Is 1 a prime number?

No. A prime has exactly two positive divisors, while 1 has only one. It is neither prime nor composite.

Can a negative number be prime?

Not under the elementary definition used here: a prime is a positive integer greater than 1. Negative integers with absolute value at least 2 can be written as −1 times the prime factorization of their absolute value.

Are 2 and 3 special cases?

Both are prime. Two is the only even prime. For either number there is no integer from 2 through floor(√n) to test, so neither has a nontrivial divisor.

Is the range inclusive?

Yes. Prime endpoints are included. The order of the two endpoints does not matter. The count covers the entire interval; the display limit affects only how many primes are printed in the result box.

Does “nearest” include an input that is already prime?

No. The mode finds the previous and next primes strictly before and after your integer. For 2, there is no previous prime and the next prime is 3. Compare the displayed distances if you want the closer member of the surrounding pair.

Can this tool test cryptographic-size numbers?

No. Its integer input limit is one trillion in absolute value, with separate range-width and nth-position limits. Use specialist, reviewed mathematics software for very large integers or security applications.

Sources & References

The explanations and practice on this page are original. These references support the definitions, factorization theorem and algorithms. Reviewed October 4, 2026.

Shares:

Related Posts