RS256 vs ES256: RSA or elliptic curve signatures for your JWTs

ES256 makes compact tokens and signs quickly. RS256 is supported everywhere and verifies quickly. Both are safe when your library handles them correctly.

RS256 and ES256 are both public key algorithms, so they solve the same problem: one issuer signs, many services verify. RS256 uses RSA with a 2048-bit or larger key. ES256 uses ECDSA on the P-256 curve with a 256-bit key that gives about the same security. The differences show up in token size, signing speed and how much can go wrong in an implementation.

By TechCompare · Updated

Topic
RS256 vs ES256
Signing algorithms
Category
Algorithm Comparison
Signing algorithms side by side

How this is calculated

Size is the most visible difference. An ES256 signature is two 32-byte numbers, r and s, for 64 bytes, or 86 Base64url characters. An RS256 signature with a 2048-bit key is 256 bytes, or 342 characters. That gap matters when tokens travel in cookies or headers on every request. Key generation and signing are quick with ECDSA, while RSA verification is very cheap, so a busy API that only verifies won't feel much difference. ECDSA has sharper edges. Each signature needs a fresh random or deterministic nonce, and a repeated nonce leaks the private key. JWS also writes the signature as raw r and s, not the DER format many crypto libraries produce, so a hand-built signer can create tokens that other libraries reject. A verifier needs care too: in 2022 a Java bug known as Psychic Signatures accepted an ECDSA signature of all zeros. RSA's pitfalls are mostly about key size, since RFC 7518 requires at least 2048 bits. ES384 and ES512 use the P-384 and P-521 curves with 96 and 132 byte signatures, and they're rarely needed for tokens.

Verdict

Pick ES256 for new systems that control both ends and care about token size, like mobile apps and cookies. Pick RS256 when you need every language, gateway and identity provider to work out of the box. Either way, keep libraries patched and let the library build the signature format.

More JWT scenarios

Frequently asked questions

Why does my ES256 signature fail in another library?
The signer probably wrote a DER encoded signature, which is common in OpenSSL and Java. JWS needs the raw 64 bytes of r followed by s. The JWT Decoder flags an ES256 signature of the wrong length for this reason.
Is ES256 more secure than RS256?
They're considered about equally strong at their usual key sizes. ES256's risks are in implementations, like reused nonces. RS256's main rule is to use keys of at least 2048 bits.
What about EdDSA?
EdDSA with Ed25519 gives compact 64-byte signatures with deterministic nonces, which removes the biggest ECDSA pitfall. Support is growing but still not universal across gateways and older libraries.