Tool to search for prime numbers located before a number, or the nth previous prime number smaller than/inferior to a given number.
Previous Prime Number - dCode
Tag(s) : Arithmetics
dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!
For a given number $ N $, the previous prime number is the smallest number strictly less than $ N $ which is a prime number.
No mathematical formula allow an automatic calculation of the prime number preceding any number N (less than N). dCode performs primality tests on numbers below the requested number until a prime number is found.
Example: The largest prime number that precedes 100 is 97
Example: The 10th prime number preceding 1000 is 937 (so there is a list of 9 prime numbers between 938 and 999 included)
The number $ N $ must be a positive real number superior to 3.
The largest number with $ n $ digits is $ 10^n -1 $ (that is always a multiple of 9), so the largest prime number with $ n $ digits is the prime number that precedes $ 10^n-1 $.
Example: The largest 4-digit number is $ 10^4 -1 = 10000-1 = 9999 $ so the largest prime number with $ n $ digits is the prime number preceding $ 10000 $ that is $ 9973 $.
The first 20 prime numbers in this list are: 7 (largest 1 digit prime), 97 (largest 2-digit prime), 997 (largest 3-digit prime), 9973, 99991, 999983, 9999991, 99999989, 999999937, 9999999967, 99999999977, 999999999989, 9999999999971, 99999999999973, 999999999999989, 9999999999999937, 99999999999999997, 999999999999999989, 9999999999999999961, 99999999999999999989 etc.
A prime number and the previous prime number are twins primes when their difference equals 2.
Example: 17 and 19 are called twin primes as 19-17 = 2.
dCode retains ownership of the "Previous Prime Number" source code. Any algorithm for the "Previous Prime Number" algorithm, applet or snippet or script (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, breaker, translator), or any "Previous Prime Number" functions (calculate, convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (Python, Java, PHP, C#, Javascript, Matlab, etc.) or any database download or API access for "Previous Prime Number" or any other element are not public (except explicit open source licence like Creative Commons). Same with the download for offline use on PC, mobile, tablet, iPhone or Android app.
Reminder: dCode is an educational and teaching resource, accessible online for free and for everyone.
The content of the page "Previous Prime Number" and its results may be freely copied and reused, including for commercial purposes, provided that dCode.fr is cited as the source.
Exporting the results is free and can be done simply by clicking on the export icons ⤓ (.csv or .txt format) or ⧉ (copy and paste).
To cite dCode.fr on another website, use the link:
In a scientific article or book, the recommended bibliographic citation is: Previous Prime Number on dCode.fr [online website], retrieved on 2025-04-16,