elliptic curves primer
The math behind Bitcoin keys, Signal messages and HTTPS connections, built up in eight steps: a curve, a way to add its points, a clock that keeps the numbers small, and a calculation that is easy one way and practically impossible to undo. Every figure is live.
1 The curve
Over the real numbers, this equation describes an elliptic curve when 4a³ + 27b² ≠ 0. Its points (x, y) are mirrored across y = 0, and a and b set its shape. We also include one extra point, O, explained below. The cusp and self-crossing presets show what happens when the condition fails.
2 Adding points
Points on the curve can be added, and repeated adding gives multiplication: 2P = P + P, 3P = P + P + P, and so on. Everything else on this page is built from one rule. To add P and Q:
- Draw the line through P and Q.
- Find the third intersection, counting a tangent contact twice and including the point at infinity.
- Mirror that point across the x-axis. That is P + Q.
The same rule as formulas, where λ is the slope of the line:
λ = (3xP² + a) / (2yP) slope of the tangent, when P = Q
xR = λ² − xP − xQ
yR = λ(xP − xR) − yP
If the line is vertical (P plus its own mirror), there is no third finite point. The answer is a special extra point, O, the point at infinity.
Note · Why there is always exactly one more point
A line through two curve points has a third intersection on the same curve, counting repeated intersections and the point at infinity:
Why: substituting a nonvertical line into the curve equation gives a cubic. Once two roots are known, the remaining root lies in the same field, whether the real numbers or numbers mod p. A tangent counts as a repeated root. More generally, Bézout’s theorem counts three intersections in the projective plane over an algebraic closure, with multiplicity; an arbitrary line need not have three intersections in the original field.
Note · What is O?
Note · Why call it addition?
It follows the same rules as adding ordinary numbers. Mathematicians call a set with an operation like this a group.
- Identity
- P + O = P. The point at infinity plays the role of zero.
- Inverses
- Every P has a −P, its mirror image, with P + (−P) = O.
- Commutative
- P + Q = Q + P, since the line through P and Q is the same line as through Q and P.
- Associative
- (P + Q) + R = P + (Q + R). This one is not obvious from the picture; the proof takes real work, but it holds.
Because of these rules, kP gives the same answer however the additions are grouped, which the rest of the page relies on.
3 Clock arithmetic
Computers need exact answers, so cryptography works modulo a prime p: numbers wrap around a clock with p hours, and dividing by a nonzero d means multiplying by d⁻¹, the number with d · d⁻¹ ≡ 1. The curve then becomes a set of dots.
Note · What does ≡ mean?
a ≡ b (mod p) is a statement, like =, not a calculation. It says: put a and b on a clock with p hours, and they land on the same spot. The (mod p) belongs to the whole line, both sides at once.
The number line is wound around the clock, seven numbers per turn, so every number sits on one of seven spokes. ≡ means “on the same spoke”. Three ways to check it, all saying the same thing:
- Same spot:
−3and4sit on the same spoke. - The gap is whole turns:
4 − (−3) = 7 = 1 × 7. Walking from−3to4is exactly one lap. - Same remainder: add or remove whole turns until the number is in
0 … 6.−3 + 7 = 4, and4is already there.
So “−3 and 4 are the same mod 7”, “−3 mod 7 is 4” and “4 ≡ −3” are all true; ≡ works in both directions, like =. When a single answer is wanted, the convention is the one in 0 … p − 1, which is why the clocks in this primer only show 0 … p − 1.
Bigger clocks work the same way: −5 ≡ 92 (mod 97), so the mirror of the point (x, 5) is (x, 92).
That is why −y ≡ p − y: going y steps backwards on the clock is the same as going p − y steps forwards.
From curve to dots
On a 17-hour clock: for each x, compute x³ + 3x + 2, wrap it, and find the y values whose square lands on the same spot.
Change the curve, the dots move
p must be a prime bigger than 3; try 15 to see why.
4 Adding on the clock
Point addition on the clock uses exactly the section 2 formulas, with division replaced by the inverse:
y² ≡ x³ + 3x + 2 (mod 97) the toy curve used in section 6
λ ≡ (yQ − yP) · (xQ − xP)⁻¹ (mod p) ⁻¹ = modular inverse
λ ≡ (3xP² + a) · (2yP)⁻¹ (mod p) when P = Q
xR ≡ λ² − xP − xQ, yR ≡ λ(xP − xR) − yP (mod p)
P = (2, 4) lies on both the real curve and the 17-hour clock. Below, it is added to itself in both worlds, step by step; then keep going to see P visit every dot and return to O.
| Step | Real numbers | Clock, mod 17 |
|---|
5 Multiplying: k·G
kG means a fixed starting point G added to itself k times. The answer hops around with no visible pattern and returns to O after n steps, the order of G. These are two different numbers: p controls the arithmetic of the coordinates; n counts the additions of G needed to return to O. On a clock with about a thousand hours the dots already look like noise:
Note · Why k → kG is fast
Read k in binary: every bit costs one doubling, and every 1 bit costs one extra addition of G. So the work grows with the number of digits of k, not its size.
A real Bitcoin key: k has 256 bits, about 78 decimal digits. Computing kG takes about 255 doublings + about 128 additions, roughly 380 steps, a few milliseconds in this browser. Adding G to itself one step at a time would take about 10⁷⁷ steps instead.
The real thing: secp256k1
Bitcoin’s curve, computed exactly in your browser.
- Fixed, public
- the same for everyone: the curve y² ≡ x³ + 7, the prime p (78 digits), the starting point G, and n, the number of points (about 10⁷⁷).
- Yours
- k, the private key: a secret number chosen uniformly at random from 1 to n − 1.
- kG, the public key: G added to itself k times. For a uniformly random private key, recovering k from kG is computationally infeasible with known classical methods.
The hopping is only there to watch. Real software never walks G → 2G → 3G → …: it reads k in binary and uses double-and-add from the note above, one doubling per bit plus one addition per 1 bit. For k = 1,000,000 that is 27 steps instead of 999,999; for a 78-digit Bitcoin key, about 380.
6 The hard direction
Going back from kG to k is the discrete logarithm problem. For well-chosen cryptographic curves with a large prime-order subgroup, no efficient classical algorithm is known. Generic attacks such as Pollard’s rho take roughly √n group operations, where n is the order of G. On the toy curve y² ≡ x³ + 3x + 2 (mod 97), with n = 103, you can simply try every k:
On secp256k1, n ≈ 2²⁵⁶, so √n ≈ 3.4 × 10³⁸ steps: about 10¹⁹ years at a trillion steps per second.
Note · Is this quantum safe?
No. The 10¹⁹ years above is for ordinary computers. A large quantum computer running Shor’s algorithm solves “given kG, find k” efficiently, for any elliptic curve.
- How big
- Resource estimates depend strongly on the circuit, hardware architecture and error correction. A September 2026 preprint estimates about 1,450 logical qubits and 19,397 physical qubits to attack secp256k1 in about 26 days on a proposed trapped-ion architecture. This is a theoretical estimate, not a demonstrated attack.
- What’s at risk
- Key exchanges recorded now could be decrypted later (“harvest now, decrypt later”). Bitcoin coins whose public key kG is already on the blockchain could be stolen.
- The fix
- New schemes built on different hard problems (lattices, hashes), standardized by NIST in 2024: ML-KEM for key exchange, ML-DSA and SLH-DSA for signatures. TLS is already rolling out hybrid key exchange that combines X25519 with ML-KEM.
Sources: RFC 6090: classical attacks; Häner et al., September 2026: quantum resource estimate.
7 In the wild
A well-chosen 256-bit elliptic curve offers roughly 128 bits of classical security, comparable to a 3072-bit RSA key. Short keys and efficient arithmetic make curves useful on phones and in browsers.
| Curve | Equation | Prime p | Where you meet it |
|---|---|---|---|
| secp256k1 | y2 = x3 + 7 | 2256 − 232 − 977 ≈ 1.16 × 1077 · 78 digits | Bitcoin and Ethereum signatures |
| generator G and its order n |
| ||
| P-256 secp256r1 | y2 = x3 − 3x + b b is a fixed 256-bit constant | 2256 − 2224 + 2192 + 296 − 1 ≈ 1.16 × 1077 · 78 digits | TLS certificates, passkeys (WebAuthn), smart cards |
| generator G and its order n |
| ||
| Curve25519 | y2 = x3 + 486662x2 + x Montgomery form | 2255 − 19 ≈ 5.79 × 1076 · 77 digits | Signal, WireGuard, SSH, TLS 1.3 key exchange (X25519). Ed25519 signatures use the related twisted Edwards curve, edwards25519. |
| generator G and its order n |
| ||
These systems use the same arithmetic for different jobs. In key agreement, Alice publishes aG and Bob publishes bG; each can compute the shared point abG using their own secret. A key-derivation function turns that point into encryption keys. In digital signatures, a private key produces a signature that others can verify with the public key.
Curve forms: RFC 7748 and RFC 8032.
Bitcoin’s keys
- Private key k: a secret random number from 1 to n − 1 (about 10⁷⁷). Whoever knows it controls the coins.
- Public key K = kG: the point on secp256k1 you reach by hopping from G k times. Easy to compute, practically impossible to reverse (section 6). Depending on its type, a Bitcoin address encodes a public-key hash, a script commitment, or a Taproot output key. A Taproot output key is a tweaked public key, encoded by its x-coordinate.
- Spending: you sign each transaction with k. Anyone can check the signature against K, without learning k, provided the signature scheme is implemented securely, including its nonce handling.
Taproot construction: BIP 341.
Optional epilogue
8 P-256’s origins
In October 2026, Anthropic reported that Claude had recovered the origins of several long-unexplained curve seeds. One of those curves is P-256 (y² = x³ − 3x + b), widely used in TLS authentication and passkeys. TLS key exchange often uses X25519 or a hybrid of X25519 and ML-KEM instead.
Its constant b was set by the NSA in the late 1990s, generated from a 160-bit seed with no explanation of where the seed came from. The unexplained seed raised concerns about whether the curve parameters had been deliberately selected for an unknown weakness; no such weakness in P-256 is known.
The report reproduces the seed and its role in curve generation in three steps:
- Initialize the C library pseudorandom generator with srand48, using the Unix timestamp for 16 Aug 1997, 01:52:34 UTC.
- Take the top eight bits of each lrand48() output, grouping 20 bytes per candidate. Candidate #1,842 is exactly the published seed.
- Use the standard SHA-1-based curve-generation procedure to derive b from the seed. It constructs a value c from hash outputs, then derives b satisfying b²c ≡ −27 (mod p).
This reproducible recipe makes deliberate weakening less plausible, but it does not explain every choice. The report notes that earlier viable candidates were skipped for unknown reasons and that P-256’s base-point origin remains unexplained. It is evidence about parameter selection, not a proof of security.
Source: Anthropic, “Claude reveals ECDSA curve origins”, October 16, 2026. Parameter derivation: NIST SP 800-186, Appendix C.3. TLS usage: Cloudflare’s TLS documentation.