✖

Prime factorisation: method, examples and why it is hard

Prime factorisation, or breaking a number down into prime factors, means writing it as a product of prime numbers. For example 360 = 2 · 2 · 2 · 3 · 3 · 5. The fundamental theorem of arithmetic says that this can be done for every positive integer greater than one, and in exactly one way. You can factorise small numbers on paper in a minute. Multiplying is easy; factorising is hard. For numbers with many hundreds of digits, not even all the computers in the world put together can manage it, and that is exactly what the cipher protecting your online banking relies on. In November 2026 Google announced that its artificial intelligence had proved a theorem about factorising numbers that mathematicians had been waiting for for over thirty years. Nobody has checked it yet, and even so it does not threaten online banking: it is a proof, not a faster calculation.

How to find the prime factorisation of a number

If you are only after the method, here it is: divide the number by the smallest prime that goes into it without a remainder, then divide the result by the smallest prime again, and so on, until you reach one. The primes you divided by are the factorisation you are looking for.

Let’s start with 360. It is even, so we divide it by two and get 180. That is even too, so we divide by two again: 90. And once more: 45. The number 45 is no longer even, so two will not help here; let’s try three: 45:3 = 15. Fifteen is divisible by three as well: 15:3 = 5. And five is itself a prime, 5:5 = 1. Done.

At school this is written down in a column with a vertical line. On the left are the intermediate results, on the right the primes we divided by:

Factorising 360 by dividing down a column: on the left 360, 180, 90, 45, 15, 5, 1, on the right in red 2, 2, 2, 3, 3, 5 Factorising 360 by dividing down a column: on the left 360, 180, 90, 45, 15, 5, 1, on the right in red 2, 2, 2, 3, 3, 5

We multiply the primes in the right-hand column together and write the repeated ones as a power:

360=23⋅32⋅5

We can check whether we calculated correctly: 8 · 9 · 5 = 72 · 5 = 360. It works.

Divisibility tests help when looking for a divisor. An even number is divisible by two, a number whose sum of digits is divisible by three is divisible by three, and a number ending in zero or five is divisible by five.

Second example: let’s factorise 1001. It is odd, so not by two. The sum of the digits is 1 + 0 + 0 + 1 = 2, so not by three either. It does not end in zero or five, so five is out. Let’s try seven: 1001:7 = 143. It works! 143 is not divisible by seven (7 · 20 = 140, leaving three), so let’s try eleven: 143:11 = 13. And thirteen is a prime. So

1001=7⋅11⋅13.

It would be a mistake to stop at 1001 = 7 · 143. The number 143 looks like a prime, but it is not. The factorisation is only finished when all the factors are primes.

You can check your result with the prime factorisation calculator. You can use the factorisation, for example, to find the greatest common divisor (GCD) and the least common multiple (LCM), or to simplify fractions.

When to stop trying

What about the number 391? It does not divide by two, three or five. We carry on with 7, 11, 13 and nothing. When should we give up and declare that 391 is a prime?

It is enough to try only the primes up to the square root of the number we are factorising. Take 100, for example; its square root is 10. If both factors were greater than 10, their product would be greater than 10 · 10 = 100. So one of the factors must be less than or equal to the square root, and we will find that one first. For 391 we have 391≈19.8, so it is enough to try the primes 2, 3, 5, 7, 11, 13, 17 and 19. Seventeen works straight away:

391=17⋅23.

If none of them had worked, 391 would be a prime.

Why we cannot factorise large numbers

Trying divisors works, but for factorising large numbers (the technical term is integer factorisation) it is terribly slow. A number with six digits needs divisors tried up to a thousand, a number with twelve digits up to a million. Every two extra digits mean ten times as much work.

The RSA cipher uses numbers with 617 digits that are the product of two large primes. The square root of such a number has 309 digits, so there are roughly 10308 numbers up to it. About seven hundred times fewer of them are primes, but even so there are more than 10305 of them. If every atom in the universe were a computer trying a billion divisors a second from the Big Bang until today, all of them together would not get through even a tiny fraction of that work.

Yet multiplying the two primes together is easy for a computer. Multiplying is easy; factorising is hard. That is what the whole security of RSA rests on. Mathematicians have, however, come up with much faster methods than trying divisors.

Fermat’s difference of two squares trick

The formula for the difference of two squares says:

x2−y2=(x−y)⋅(x+y).

If we manage to write a number N as the difference of two squares, we have factorised it. You can see it in the figure: from a square with side x we cut out a square with side y in the corner. We cut the rest into a red rectangle and a blue strip, rotate the strip and place it alongside the red rectangle. The result is a rectangle with sides x + y and x − y.

From a square with side x without the corner square with side y, rotating the blue strip and placing it alongside gives a rectangle with sides x+y and x-y From a square with side x without the corner square with side y, rotating the blue strip and placing it alongside gives a rectangle with sides x+y and x-y

Pierre de Fermat went about it like this in the 17th century. We want N = x2 − y2, that is y2 = x2 − N. So we try different values of x and watch whether x2 − N comes out as a square. Let’s factorise the number 5959. Its square root is roughly 77.2, and for smaller x the difference would come out negative, so we start at x = 78:

782−5959=6084−5959=125792−5959=6241−5959=282802−5959=6400−5959=441=212

The third attempt worked. So 5959 = 802 − 212, and by the formula

5959=(80−21)⋅(80+21)=59⋅101.

By trying divisors we would have had to go through all the primes up to 59. Fermat needed only three attempts, because the primes 59 and 101 lie close to each other. When the factors are far apart, Fermat’s method takes even longer than trying divisors. That is why the two primes for an RSA key are chosen so that they are not too close to each other; otherwise Fermat’s trick would quickly find them.

Squares with a remainder

Fast modern algorithms start from Fermat’s idea and add one improvement to it. They do not need x2 − y2 to be exactly N. It is enough for it to be some multiple of N. In other words, it is enough for x2 and y2 to leave the same remainder when divided by N.

Let’s take N = 91. We have 372 = 1369 = 15 · 91 + 4, so 372 leaves a remainder of 4 when divided by 91, and that is 22. The difference 372 − 22 = 1365 = 15 · 91 is therefore a multiple of 91. But by the formula we also have 372 − 22 = (37 − 2) · (37 + 2) = 35 · 39. The number 91 divides the product 35 · 39, so its prime factors must be hiding in 35 or in 39. The greatest common divisor finds the ones in 35:

gcd(35,91)=7.

We have a divisor: 91 = 7 · 13. The Euclidean algorithm computes the greatest common divisor in a flash even for huge numbers, without any factorising, so all the work lies in finding suitable x and y. Sometimes the only divisor that comes out is 1 or N itself, and then we look for another pair.

And how do we find them? Let’s try it on N = 1649. We take numbers a little above the square root and look at the remainders of their squares when divided by 1649:

412=1681,remainder 32=25422=1764,remainder 115=5⋅23432=1849,remainder 200=23⋅52

None of the remainders is a square. But the first and the third are made up only of the small primes 2 and 5, and when we multiply them together we get 28 · 52 = (24 · 5)2 = 802. All the indices are even, so it is a square! So we multiply the left-hand sides as well: 412 · 432 = (41 · 43)2 = 17632. The number 17632 therefore leaves the same remainder when divided by 1649 as 802. And since 1763 leaves a remainder of 114 when divided by 1649, the same holds for 1142 and 802. All that is left is

gcd(114−80,1649)=gcd(34,1649)=17

and we have 1649 = 17 · 97.

This is the heart of all the fast methods. They look for numbers whose squares leave remainders made up only of small primes, and then combine them so that all the indices come out even. The quadratic sieve (Carl Pomerance, 1981) looks for such remainders cleverly, all at once, a bit like crossing out multiples when looking for primes. The number field sieve (from 1988 to 1993) does the same with the help of more complicated numbers than integers. In February 2020 the number field sieve was used to factorise the number RSA-250, with 250 digits, which is still the record. A single processor core would have needed roughly 2,700 years for that calculation.

How speed is measured

The speed of an algorithm is measured by how many steps it needs relative to the number of digits of the number, not its size. Trying divisors needs roughly N steps, and when N has d digits in total, that is 10d/2 steps. The number of digits is in the exponent, so this is exponential growth.

For the fast sieves a notation is used that looks frightening. If you do not know logarithms, you can skip the next two paragraphs; the graph and the table below it show what matters.

LN[α,c]=ec⋅(ln⁡N)α⋅(ln⁡ln⁡N)1−α.

What matters most is the exponent α, a number between zero and one. For α = 1 we get ec · ln N = Nc, that is, exponential growth as with trying divisors. For α = 0 we get (ln N)c. The number ln N is roughly 2.3 times the number of digits, so this is a power of the number of digits, and that is a fast algorithm. The smaller α is, the closer we are to a fast algorithm. The number c is only of secondary importance.

The quadratic sieve needs roughly LN[1/2; 1] steps, the number field sieve roughly LN[1/3; 1.923]. The graph shows how big that difference is. The vertical axis is logarithmic: each horizontal line means 1010 times more steps. Trying divisors shoots off the graph already at 200 digits.

Number of steps by the number of digits of the number being factorised: trying divisors (red), the quadratic sieve L_N[1/2; 1] (orange) and the number field sieve L_N[1/3; 1{,}923] (blue), dashed line at the 617 digits of an RSA key Number of steps by the number of digits of the number being factorised: trying divisors (red), the quadratic sieve L_N[1/2; 1] (orange) and the number field sieve L_N[1/3; 1{,}923] (blue), dashed line at the 617 digits of an RSA key

For a number with 617 digits, like the ones RSA uses, it comes out roughly as:

algorithmnumber of steps
trying divisors10308
quadratic sieve, LN[1/2; 1]1044
number field sieve, LN[1/3; 1.923]1035

This is only a rough estimate, because the LN notation ignores smaller terms, but 1035 steps is still more than all the computers in the world can manage in a human lifetime.

What is proved and what is only tested

The number field sieve works in practice, but nobody has proved that it always needs only LN[1/3] steps. The estimate of its speed rests on assumptions that suitable numbers made up of small primes turn up often enough, as if it were down to chance. Everything suggests that this holds, but a proof is missing.

What can be proved? In 1992 Hendrik Lenstra and Carl Pomerance proved that their algorithm needs on average LN[1/2; 1] steps. Since then, for over thirty years, nobody has managed to prove anything with an exponent smaller than 1/2 without further assumptions.

What Google announced in November 2026

On 25 November 2026 Google published six mathematical papers on GitHub. According to the accompanying text, they were created in full, including a formal proof, by the Cogentic system built on the company’s AI model Gemini 4, “without human intervention beyond the initial prompt”. The paper attracting the most attention is called Unconditional Integer Factorization in Time LN[1/3, O(1)].

The paper claims that there is an algorithm that factorises every number N in LN[1/3; 105] steps on average, and that this is proved without any unproved assumptions. The algorithm tosses coins as it works, but never gives a wrong answer: it checks every prime in the result, and at the end it multiplies the factorisation out and compares it with N. If this held, the gap from the previous section would be closed.

The same batch also includes a paper on factorising without tossing coins. It claims that a deterministic algorithm finds a divisor of every composite number in LN[3/4] steps, so by repeating it, it can manage the whole factorisation too. The best proved deterministic method so far needed roughly N1/5 steps, that is, still exponentially many. The expression LN[3/4] grows more slowly than Nc for any c, however small. According to the authors, this would be the first deterministic factorisation faster than exponential.

Has it been checked? Not yet. Google writes that it has the whole proof written in Lean, a program that checks every step by computer, but it only promises to publish that formalisation later. As of 29 November 2026 we have not found any assessment by experts in number theory.

Will it break RSA?

No, and not even if the proof turns out to be correct. The result does not give a faster algorithm. It only proves that the exponent 1/3, which is assumed for the number field sieve, can also be achieved with a proof, but with a much worse constant: 105 instead of 1.923. For a number with 617 digits, LN[1/3; 105] comes out at roughly 101922 steps. That is far more than the 10308 for plain trying divisors! According to the LN notation, the new algorithm would only overtake trying divisors for numbers with more than 13,000 digits, and the quadratic sieve only for numbers with trillions of digits.

This shows well what the LN notation hides. It says how fast the number of steps grows as the numbers grow without bound, but it says nothing about how long the calculation takes for the numbers we care about. For the security of RSA it is precisely the latter that matters. The real threat to RSA therefore remains quantum computers. For them, Peter Shor devised an algorithm in 1994 that factorises numbers quickly. But nobody has yet built a quantum computer that could run it on a number with 617 digits.

See also