← qilong
y² = x³ + ax + b

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

y² = x³ + ax + b

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:

  1. Draw the line through P and Q.
  2. Find the third intersection, counting a tangent contact twice and including the point at infinity.
  3. Mirror that point across the x-axis. That is P + Q.
Drag anywhere on the plot: the nearest of P / Q follows your pointer along the curve. Try dragging Q onto P and watch the line turn into a tangent.

The same rule as formulas, where λ is the slope of the line:

λ = (yQ − yP) / (xQ − xP)   slope through P and Q
λ = (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:

Two points force a third. xR = λ² − xP − xQ
Tangent: P counts twice.
Vertical: the third point is O, 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?
mirror: x-axis O (at infinity) P (2, 4) −P (2, −4)
O is the “point at infinity”, one extra point added to every elliptic curve. It is not on the grid and has no (x, y).
Where it comes from: P and its mirror −P lie on a vertical line, which meets the curve nowhere else. The missing third point is O, imagined at the top and bottom of every vertical line.
What it does: it is the zero of point addition: P + O = P and P + (−P) = 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: −3 and 4 sit on the same spoke.
  • The gap is whole turns: 4 − (−3) = 7 = 1 × 7. Walking from −3 to 4 is exactly one lap.
  • Same remainder: add or remove whole turns until the number is in 0 … 6. −3 + 7 = 4, and 4 is 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³ + ax + b  (mod p)   the curve, in clock arithmetic
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.

Real numbers
y² = x³ + 3x + 2
Clock, mod 17
y² ≡ x³ + 3x + 2 (mod 17)
The two pictures don’t line up point for point. A dot’s position on the left is a decimal like −0.48; you can’t take that number mod 17. What carries over is the calculation: run the same formula with exact fractions, then turn each fraction a/b into a · b⁻¹ mod 17. Geometry on the left, the same algebra on the right.
StepReal numbersClock, 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.
y² ≡ x³ + 7  (mod p)p = 2²⁵⁶ − 2³² − 977 ≈ 1.16 × 10⁷⁷

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.

CurveEquationPrime pWhere 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
G.x
0x79BE667E F9DCBBAC 55A06295 CE870B07
029BFCDB 2DCE28D9 59F2815B 16F81798
G.y
0x483ADA77 26A3C465 5DA4FBFC 0E1108A8
FD17B448 A6855419 9C47D08F FB10D4B8
n
0xFFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE
BAAEDCE6 AF48A03B BFD25E8C D0364141≈ 1.16 × 1077, also the number of points on the curve
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
G.x
0x6B17D1F2 E12C4247 F8BCE6E5 63A440F2
77037D81 2DEB33A0 F4A13945 D898C296
G.y
0x4FE342E2 FE1A7F9B 8EE7EB4A 7C0F9E16
2BCE3357 6B315ECE CBB64068 37BF51F5
n
0xFFFFFFFF 00000000 FFFFFFFF FFFFFFFF
BCE6FAAD A7179E84 F3B9CAC2 FC632551≈ 1.16 × 1077, also the number of points on the curve
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
G.x
9
G.y
0x20AE19A1 B8A086B4 E01EDD2C 7748D14C
923D4D7E 6D7C61B2 29E9C5A2 7ECED3D9
n
0x10000000 00000000 00000000 00000000
14DEF9DE A2F79CD6 5812631A 5CF5D3ED≈ 7.24 × 1075 = 2252 + …; the curve has 8n points, and G stays in the big prime-sized part

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

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:

  1. Initialize the C library pseudorandom generator with srand48, using the Unix timestamp for 16 Aug 1997, 01:52:34 UTC.
  2. Take the top eight bits of each lrand48() output, grouping 20 bytes per candidate. Candidate #1,842 is exactly the published seed.
  3. 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.