Some problems are easy to check but seem very hard to solve. Internet security depends on that gap. This tutorial covers what P and NP mean, why nobody has proved them different, and what would happen to HTTPS, banking and Bitcoin if P = NP.
Computer scientists don't call a problem "hard" because it takes long on today's laptop. They ask a different question: as the input grows, how quickly does the work grow?
n, n² or n³. Doubling the input multiplies the work by a fixed amount, such as 4× or 8×. We call these problems tractable.2ⁿ or n!. Adding one item to the input doubles the work or worse. Past a modest size, no amount of hardware keeps up.n³ is half a millisecond, while 2ⁿ is about 38 million years. Buying a faster computer doesn't close that gap. You need a better algorithm, and for some problems nobody knows whether one exists.P (Polynomial time) is the class of yes/no problems that a normal computer can solve in polynomial time. You use these every day without thinking about it:
| Problem | Everyday example | Algorithm | Cost |
|---|---|---|---|
| Sorting | Order your inbox by date | Merge sort | n log n |
| Searching a sorted list | Look up a word in a dictionary | Binary search | log n |
| Shortest path | Google Maps: home → office | Dijkstra | (V+E) log V |
| Multiplication | Multiply two 600-digit numbers | Schoolbook / Karatsuba | n² / n^1.58 |
| Is this number prime? | Generate a key for RSA | AKS (2002), Miller–Rabin in practice | polynomial in digits |
| Matching | Assign interns to teams by preference | Gale–Shapley | n² |
NP (Nondeterministic Polynomial time) is the class of yes/no problems where, if the answer is "yes", someone can hand you a proof (called a certificate or witness) that you can verify in polynomial time.
A good mental model is a jigsaw puzzle. Assembling a 5,000-piece puzzle takes days. Checking that a finished puzzle is correct takes a glance.
Here is a classic NP problem called Subset Sum: given a list of numbers, is there a subset that adds up exactly to a target? Try it.
Notice the asymmetry:
n numbers: O(n) work.2ⁿ of them. With 14 numbers that's 16,384, which a computer handles easily. With 100 numbers it's about 1030, which no computer can.# subset_sum.py: verifying is fast, solving (naively) is exponential
from itertools import combinations
def verify(numbers, target, certificate):
"""O(n): is the proposed subset valid and does it hit the target?"""
return all(x in numbers for x in certificate) and sum(certificate) == target
def solve_brute_force(numbers, target):
"""O(2^n): try every possible subset."""
for size in range(len(numbers) + 1):
for subset in combinations(numbers, size):
if sum(subset) == target:
return list(subset)
return None
nums = [3, 34, 4, 12, 5, 2]
print(verify(nums, 9, [4, 5])) # True, checked instantly
print(solve_brute_force(nums, 9)) # [4, 5], found by searching
P ⊆ NP. The open question is whether the two classes are actually the same.Stephen Cook stated the question formally in 1971, and Leonid Levin reached the same result independently in the USSR:
If a solution can be verified quickly, can it always be found quickly?
Some problems really are harder to solve than to check. Creativity can't be automated away, and cryptography can be secure.
Any puzzle whose answer you can recognize, you can also solve efficiently. The gap that cryptography depends on is gone.
It is one of the seven Clay Millennium Prize Problems, with a $1,000,000 reward for a proof either way. More than 50 years later it remains unsolved. In surveys, most researchers say they believe P ≠ NP, but nobody has proved it.
In 1971 Cook (and independently Levin) proved something surprising. One NP problem, Boolean Satisfiability (SAT), is at least as hard as every other NP problem. Any NP problem can be translated (reduced) into a SAT question in polynomial time.
In 1972 Richard Karp showed that 21 more classic problems have the same property. Today thousands are known. These problems are called NP-complete.
| NP-complete problem | Plain English | Where it shows up |
|---|---|---|
| SAT / 3-SAT | Can these true/false variables be set so every rule holds? | Chip verification, package dependency resolvers |
| Traveling Salesman (decision) | Is there a tour of all cities shorter than k km? | Delivery routes, PCB drilling |
| Graph Coloring | Can you color the map with 3 colors so no neighbors match? | Exam timetables, CPU register allocation |
| Knapsack / Subset Sum | Best set of items under a weight limit? | Budgeting, cargo loading |
| Generalized Sudoku | Fill an n²×n² grid so the rules hold | Puzzles (and a great teaching example) |
Cryptography needs a one-way function: something easy to compute but hard to reverse. A familiar comparison is mixing paint. Mixing blue and yellow into green is easy, while separating green back into blue and yellow is close to impossible.
The best-known example is multiplying two primes. Multiplying is in P. Reversing it means factoring, and the best known methods are dramatically slower. Try it below. The factoring uses simple trial division running in your browser.
| One-way function | Easy direction | Hard direction | Used by |
|---|---|---|---|
| Integer factorization | Multiply p × q | Factor n | RSA |
| Discrete logarithm | Compute gˣ mod p | Recover x | Diffie–Hellman, DSA |
| Elliptic-curve discrete log | Compute k · G on a curve | Recover k | ECDHE (X25519), ECDSA, Ed25519, Bitcoin |
| Cryptographic hash | SHA-256(x) | Find x from the hash | Passwords, Git, TLS, blockchains |
| Lattice problems (LWE) | Compute A·s + e | Recover s | ML-KEM / Kyber (post-quantum TLS) |
p and q, you can check p × q = n instantly. A one-way function can only exist if P ≠ NP. If P = NP, nothing can be easy forward and hard backward.RSA (1977) is the classic public-key system. Anyone can encrypt with your public key (n, e), but only you can decrypt, because only you know the factors of n.
p, q. Compute n = p × q and φ = (p−1)(q−1).e (usually 65537). Compute the private key d = e⁻¹ mod φ.c = mᵉ mod n. Decrypt: m = cᵈ mod n.The attacker sees n and e. To compute d they need φ, and to get φ they need to factor n.
# toy_rsa.py: needs Python 3.8+ for pow(e, -1, phi)
p, q = 61, 53 # secret primes
n = p * q # 3233, public modulus
phi = (p - 1) * (q - 1) # 3120, secret
e = 17 # public exponent
d = pow(e, -1, phi) # 2753, private key
m = 65 # message ('A')
c = pow(m, e, n) # encrypt: 2790
assert pow(c, d, n) == m # decrypt works
# --- Eve's attack: factor n by trial division ---
def factor(n):
f = 2
while f * f <= n:
if n % f == 0:
return f, n // f
f += 1
p2, q2 = factor(n) # (53, 61), instant for a tiny n
d2 = pow(e, -1, (p2 - 1) * (q2 - 1))
print(pow(c, d2, n)) # 65, Eve reads the message
# For a 2048-bit n this loop would need ~2^1024 iterations.
When you open https:// anything, your browser and the server run a TLS 1.3 handshake. Each step relies on a problem that is easy to verify and believed hard to solve. Step through it:
The same building blocks show up almost everywhere:
TLS plus signed transaction tokens
End-to-end encryption with X25519 key agreement
Ed25519 / RSA host and user keys
Signed packages (apt, App Store, Windows Update)
Stored as bcrypt / Argon2 hashes, never plain text
Signed DNS records so nobody can redirect your domain
ECDSA wallets + SHA-256 proof-of-work
Hash-linked history, optional GPG/SSH signing
Bitcoin mining is a hash puzzle: find a number (a nonce) so that SHA-256(block + nonce) starts with enough zeros. The only known method is to keep guessing, but anyone can verify a winning nonce with one hash. This demo runs real SHA-256 in your browser.
Suppose someone publishes a practical polynomial-time algorithm for SAT. Through reductions, every NP search problem becomes efficiently solvable, including "find the key that decrypts this" and "find a signature that verifies." Flip the switch to see what changes:
P = NP would not affect everything. A one-time pad stays secure, because its security comes from information theory and not from a hard problem. Everything else in today's toolkit, including symmetric ciphers like AES, could in principle fall, because "find the key that turns this plaintext into this ciphertext" is an NP problem.
"P = NP breaks the internet" is a good headline, but the real situation has some caveats:
An algorithm running in n¹⁰⁰ steps is polynomial, but useless in practice. A proof of P = NP might come with an algorithm so slow that crypto stays safe in practice. The internet breaks only if the algorithm is practical.
A non-constructive proof could show that a fast algorithm exists without telling anyone what it is. That would be a mathematical earthquake but not an immediate security crisis.
P ≠ NP is about worst-case hardness: some instances are hard. Crypto needs average-case hardness, meaning randomly generated keys must be hard to break. That is a stronger assumption, and it is also unproven. Cryptography is safe only if P ≠ NP, but P ≠ NP alone is not enough.
Factoring is in NP, but it is not believed to be NP-complete. It is also in co-NP, and its best classical algorithm, the Number Field Sieve, is sub-exponential. Someone could find a fast factoring algorithm tomorrow without resolving P vs NP. RSA could fall while P ≠ NP still holds.
Shor's algorithm (1994) factors numbers and solves discrete logs in polynomial time on a large quantum computer. That breaks RSA and elliptic-curve crypto without P = NP. Quantum computers are not believed to solve NP-complete problems efficiently. That's why the industry is migrating to post-quantum cryptography such as ML-KEM (Kyber) and ML-DSA (Dilithium), standardized by NIST in 2024 and already used in Chrome and Cloudflare's TLS. Those schemes still depend on P ≠ NP.
| Scenario | RSA / ECC | Post-quantum (lattices) | AES / SHA-256 |
|---|---|---|---|
| Today (assume P ≠ NP, no big quantum computer) | ✅ Safe | ✅ Safe | ✅ Safe |
| Large quantum computer built | ❌ Broken (Shor) | ✅ Believed safe | ⚠️ Weakened (Grover), so use 256-bit keys |
| Fast factoring found, P ≠ NP still holds | ❌ RSA broken | ✅ Safe | ✅ Safe |
| Practical P = NP algorithm found | ❌ Broken | ❌ Broken | ❌ Broken |
For each problem, pick the best description. Click an answer to see the explanation.
P = NP with a practical algorithm would remove that assumption, and with it the basis of almost all modern encryption.