Mathematics calculator

Prime Number Calculator

Classify a nonnegative whole number and show a factor pair when the number is composite.

Calculator inputs

Enter your values

Primality test
Calculated output

Result summary

Your result will appear here

Complete the required fields and select the calculate button.

Prime dots that only form one row compared with composite dots arranged in a factor grid
A composite number forms a nontrivial rectangular factor grid; a prime does not.

What Is a Prime Number?

A prime number is an integer greater than 1 with exactly two positive divisors: 1 and itself. A composite integer is greater than 1 and has another factor. Zero and one are neither prime nor composite, and 2 is the only even prime.

The Prime Number Calculator classifies one whole number from 0 through 2,147,483,647. For a composite input it shows the smallest nontrivial factor and a factor pair. It also reports a trial-division bound, helping you understand why factors only need to be considered through the square root.

How to Check Whether a Number Is Prime

  1. Enter the Whole number to test, using digits without grouping commas. The allowed range is 0 through 2,147,483,647.
  2. Select Calculate. Read the featured classification: Prime, Composite or Neither prime nor composite.
  3. For a composite result, inspect the smallest nontrivial factor and multiply the factor pair to recover the input.
  4. For a prime, zero or one, the factor cards say Not applicable. A prime has no nontrivial factor pair; zero and one fall outside the prime/composite split.

The implementation handles 0, 1 and even numbers first, then checks odd candidates until it finds a divisor or passes the square-root bound. It can stop early on a composite number. The bound shown is floor(√n), not a log of the last divisor actually tried.

This is a bounded integer classifier. It does not return every divisor, a full prime factorization, the next prime or a range of primes. Decimal and negative entries are rejected. The diagram illustrates factor grouping rather than redrawing the entered number.

Trial Division and the Square Root Bound

Prime condition: n > 1 and only positive divisors are 1 and n

Composite factorization: n = a × b, with 1 < a ≤ b

Trial-division bound: test possible factors d ≤ √n

Integer comparison used by the loop: d ≤ floor(n ÷ d)

If n = ab and both positive factors were greater than √n, their product would exceed n. Therefore every composite n has a nontrivial factor no larger than √n. This is why checking up to the square-root bound is enough for trial division.

The OpenStax factors chapter defines prime and composite numbers. The numerical implementation skips even candidates after handling factor 2 and uses an integer comparison to avoid squaring a candidate unnecessarily.

A factor pair proves that a number is composite, but failing to find a factor in a few hand trials does not prove primality unless the full required range is covered. The calculator applies its complete trial-division method within its accepted range.

Number, Classification and Factor Results

Whole number n
Integer from 0 through 2,147,483,647. No commas, negative sign or fractional part.
Number classification
Featured Prime, Composite or Neither prime nor composite result.
Entered number
Integer interpreted by the request, useful for checking copied digits.
Smallest nontrivial factor
Smallest positive divisor greater than 1 for a composite input. Not applicable for prime, 0 or 1.
Factor pair
That factor multiplied by its matching integer quotient. It is not a complete prime factorization.
Trial-division bound
floor(√n). The algorithm may stop before this bound when it finds a factor; the value is not an actual iteration log.

Prime and Composite Worked Example

Illustrative example. Test 221. Its square root lies between 14 and 15, so the trial-division bound is 14. The value is odd and is not divisible by 3, 5, 7, 9 or 11.

The next odd candidate is 13. Since 221 ÷ 13 = 17 exactly, 221 = 13 × 17. Therefore 221 is Composite, with smallest nontrivial factor 13.

For comparison, 223 has the same bound of 14, but none of those required candidates divides it. The calculator reports Prime and clears the factor cards to Not applicable.

Calculation check. These illustrative values were checked independently against the formula and calculator response. Retain unrounded intermediate values when checking approximations.

Prime and Composite Worked Example
Input or resultValue
Tested number221
ClassificationComposite
Smallest factor13
Factor pair13 × 17
Trial bound floor(√221)14

Prime, Composite and Neither

The first few integers show why “not prime” does not always mean composite and why oddness alone is not a primality test.

Prime, Composite and Neither
NumberClassificationReason
0NeitherOutside the n > 1 definitions
1NeitherOnly one positive divisor
2PrimeExactly divisors 1 and 2
9Composite3 × 3
13PrimeOnly positive divisors 1 and 13
221Composite13 × 17

How to Interpret a Primality Result

A composite result comes with a concrete proof: a nontrivial factor pair. For 221, 13 × 17 = 221. Neither factor is 1 or 221, so the number cannot be prime.

A prime result means the supported integer has no smaller positive divisor other than 1. Prime does not mean “odd”: 2 is prime and 9 is odd but composite. Likewise, a prime-looking last digit is not enough to establish primality.

Zero and one need a separate reading. The message that a number is not prime does not automatically mean it is composite; the featured classification identifies these two exceptions explicitly.

The reported smallest factor is enough for a composite verdict, but it does not enumerate every factor. If you need a full factorization or arithmetic on integers beyond the accepted bound, use a tool designed for that separate task.

Common Prime Number Mistakes

  • Calling 1 prime even though it has only one positive divisor.
  • Calling every nonprime number composite without separating 0 and 1.
  • Assuming every odd number is prime or that every even number is composite; 2 is the exception.
  • Stopping a hand test before all required candidates through √n have been considered.
  • Reading the trial bound as the last factor actually tested.
  • Treating one factor pair as a complete prime factorization.
  • Entering decimals, negative integers or a value beyond the supported bound.

Frequently Asked Questions

What is a prime number?

An integer greater than 1 with exactly two positive divisors: 1 and itself. Numbers greater than 1 with another factor are composite.

Is 1 prime or composite?

Neither. It has only one positive divisor, so it does not meet the prime definition and is not composite.

Is zero composite?

No. Both the prime and composite definitions used here require an integer greater than 1. The classification for zero is Neither prime nor composite.

Why is 2 the only even prime?

Two has only positive divisors 1 and 2. Every larger even integer has factor 2 as well as 1 and itself, making it composite.

Why is checking up to the square root enough?

Every composite integer has a nontrivial factor no greater than its square root. If both factors were greater, their product would exceed the number.

Is 221 prime?

No. It equals 13 × 17, so it is composite. Its smallest nontrivial factor is 13.

Does the trial bound mean every factor was tested through it?

No. It is floor(√n), a theoretical bound. The algorithm may stop earlier as soon as it finds a divisor.

Can I test huge integers or get a full factorization?

The input is limited to whole numbers from 0 through 2,147,483,647. The result gives a smallest factor and one pair for composites, not a complete factor list or arbitrary-size primality service.

Sources and References