Prime Number Test Calculator

This prime number test checks whether a whole number is prime, meaning it has no divisors other than 1 and itself. Enter a number up to a billion and the calculator tells you whether it is prime or composite, and if it is composite it shows the smallest number that divides it. A prime number is one of the basic objects of number theory, important in cryptography, hashing and many algorithms. The test uses trial division by 2 and then the odd numbers up to the square root, which is enough to settle primality exactly. The method, a worked example and the assumptions are set out below.

Conservation Amendment Bill
 
Smallest divisor (if composite) 
Classification 

The formula

A number n greater than 1 is prime if no integer from 2 up to the square root of n divides it evenly. If any does, n is composite and that divisor is a proper factor.

Worked example

97 is not divisible by 2, 3, 5 or 7, and the square root of 97 is under 10, so there is nothing left to test: 97 is prime. By contrast 91 = 7 times 13, so its smallest divisor is 7. Enter 97 or 91 to confirm.

Frequently asked questions

What makes a number prime?

It is a whole number above 1 whose only divisors are 1 and itself, such as 2, 3, 5, 7 and 11.

Is 1 prime?

No. By definition a prime has exactly two distinct divisors. The number 1 has only one, so it is neither prime nor composite.

How does the test work?

It tries dividing by 2 and the odd numbers up to the square root of n. If none divide evenly, n is prime.

Who this calculator is for

This calculator is for students, programmers and anyone exploring number theory.

What this calculator assumes

  • You enter a whole number within the stated range.
  • The exact integer algorithm is used.
  • Very large results are shown grouped for readability.

Formula and sources

Related calculators

If you've found a bug, or would like to contact us, or learn more about James Graham and Calculate.co.nz.

Calculate.co.nz is partnered with Interest.co.nz for New Zealand's highest quality calculators and financial analysis.

All calculators and tools are provided for educational and indicative purposes only and do not constitute financial advice.

Calculate.co.nz is proudly part of the Realtor.co.nz group, New Zealand's leading property transaction literacy platform, helping Kiwis understand the home buying and selling process from start to finish. Whether you're a first home buyer navigating your first property purchase, an investor evaluating your next acquisition, or a homeowner planning to sell, Realtor.co.nz provides clear, independent, and trustworthy guidance on every step of the New Zealand property transaction journey.

Calculate.co.nz is also partnered with Health Based Building and Premium Homes to promote informed choices that lead to better long-term outcomes for Kiwi households.

Calculate.co.nz is hosted in Auckland via SiteHost new Zealand.

All content on this website, including calculators, tools, source code, and design, is protected under the Copyright Act 1994 (New Zealand). No part of this site may be reproduced, copied, distributed, stored, or used in any form without prior written permission from the owner.

About & trust: Why Calculate is NZ's most comprehensive · By the Numbers · How we compare · Editorial standards · How we keep data current · NZ finance glossary · Research & data · Financial literacy NZ · About · Privacy policy · Terms of use

Reviewed and maintained. Last reviewed 2026-06-21 and checked on a twice-monthly cycle against IRD, RBNZ and Stats NZ. How we keep data current.

© 2026 Calculate.co.nz. All rights reserved. Building free NZ calculators since 2011.