Use HS256 when one service both issues and verifies the token and the secret never leaves it. Use RS256 when anything else has to verify your tokens: another service, a partner, a mobile client, a third-party API. The difference comes down to one question: is everything that verifies a token also allowed to create one? With HS256 the answer is always yes. With RS256 it is no.
This guide covers what the two algorithms are, how the signing works, where each one fails, and how to configure verification so neither fails you. If you want to look at a real token while you read, the free JWT Decoder on Pingfloat shows you the header and payload, including the alg value.
TL;DR
- HS256 is HMAC with SHA-256: one shared secret signs and verifies. Anyone who can verify can also forge.
- RS256 is RSA with SHA-256: a private key signs, a public key verifies. The public key can be handed out freely.
- Pick HS256 only inside a single trust boundary, with a random secret of at least 256 bits. Pick RS256 (or ES256/PS256) when verifiers are separate from the issuer.
- Whatever you choose, pin the allowed algorithm on the server. Never let the token's own
algheader decide how it is verified. - RS256 makes key rotation easier because you publish new public keys instead of redeploying a shared secret everywhere.
Table of Contents
- What HS256 and RS256 actually are
- Symmetric versus asymmetric signing
- Why that difference matters in practice
- What the standards require for keys
- The attack that makes the choice matter: algorithm confusion
- When each algorithm fits
- Side by side
- Rotating keys without breaking sessions
- A checklist before you ship
- Perspective
- Inspect your tokens with Pingfloat
- FAQ
- Sources
What HS256 and RS256 actually are
A JWT (JSON Web Token) has three parts: a header, a payload and a signature. The header names the signing algorithm in its alg field. The signature lets the receiver check that the header and payload were not altered after the issuer signed them.
The names come from the JOSE specifications. RFC 7518 defines the algorithm table:
| Name | Meaning | Key type |
|---|---|---|
| HS256 | HMAC using SHA-256 | One shared secret |
| RS256 | RSASSA-PKCS1-v1_5 using SHA-256 | RSA key pair |
| PS256 | RSASSA-PSS using SHA-256 | RSA key pair |
| ES256 | ECDSA using P-256 and SHA-256 | Elliptic-curve key pair |
The "256" in all of them refers to the SHA-256 hash. It does not mean a 256-bit key, which is a common source of confusion with RS256, where the RSA key is typically 2048 bits or more.
Symmetric versus asymmetric signing
This is the real split behind the two names.
HS256 is symmetric. The issuer computes an HMAC over the base64url-encoded header and payload using a secret. The receiver recomputes the HMAC with the same secret and compares. Both sides hold the same key, so, as the OWASP JWT Cheat Sheet puts it, the same secret is used to generate and verify the token.
RS256 is asymmetric. The issuer signs with a private key that only it knows. Receivers verify with the matching public key, which can be public. OWASP describes this as the issuer generating the signature and the audience verifying it with the associated public key.
The consequence is simple and it drives every other tradeoff: with HS256, every party that can verify a token can also mint a valid one. With RS256, verifiers can only verify.

Why that difference matters in practice
Sharing the secret spreads the risk
Suppose you run an auth service and seven APIs. With HS256, all seven need the same secret. A leak from any one of them lets an attacker sign tokens that every other service accepts. The kataras/jwt algorithm-selection chapter states this plainly: if several services share one HS256 secret, a leak in any one is a signing-key compromise. It also notes that the token itself can then never tell you which service issued it, because every key holder is equally the author.
With RS256, the private key lives only on the issuer. The seven APIs get the public key. Compromising one API gives an attacker nothing they can sign with.
One secret per issuer and audience
If you do use HS256 between several parties, OWASP warns that each issuer and audience pair needs its own secret. Reusing one secret across audiences lets one audience forge tokens that impersonate the issuer. In practice this is the point where many teams find that managing many secrets is harder than managing one key pair.
Rotation is easier with public keys
With RS256, you publish public keys at a stable HTTPS address, usually a JWKS (JSON Web Key Set) endpoint. Each key carries a kid (key ID) that tokens reference in their header. OWASP notes that publishing public keys at a public HTTPS URI simplifies distribution and rotation. Google's Tink documentation recommends asymmetric keys whenever different entities generate and verify tokens, and suggests adding a new public key at least one day before it is used for signing, so verifiers that refresh daily never see a token they cannot check.
With HS256, rotating means changing a secret in every service that holds it, in lockstep, or accepting a window where tokens fail.

Performance is rarely the deciding factor
HMAC is faster than RSA, and OWASP says so, but also notes the difference is usually negligible in practice. RSA signing is the slower operation, and signing happens in one place: the issuer. Verification, which every downstream service does on every request, is the cheap side of RSA. Unless you issue tokens at extreme volume from one process, speed should not push you toward a shared secret.
What the standards require for keys
Both algorithms have minimum key sizes in RFC 7518:
- HS256: the key must be at least as long as the hash output, so at least 256 bits (32 bytes).
- RS256 and PS256: RSA keys of 2048 bits or larger.
OWASP adds that an HMAC secret must come from a cryptographically secure random generator, never from a password. RFC 8725, the JWT Best Current Practices document, goes further: human-memorizable passwords must not be used directly as HS256 keys.
A quick way to generate a proper HS256 secret is 32 random bytes from your language's secure random source, then stored in a secrets manager. WorkOS-style advice applies to RS256 private keys too: keep them in an HSM, a cloud KMS or an encrypted secrets store, not in source control or config files.
The attack that makes the choice matter: algorithm confusion
The two algorithms collide in a well-known vulnerability. A server is set up for RS256 and has a public key it uses for verification. An attacker takes that public key, which is public by design, changes the token header to HS256, and signs the token with HMAC using the public key as the secret. If the library picks the verification method from the token's own alg header, it runs HMAC with the public key and the forged token passes.
This is not theoretical. RFC 8725 documents the attack and its CVE (CVE-2015-9235), and PortSwigger's Web Security Academy walks through exactly how a token signed with HS256 using the server's RSA public key gets accepted by a vulnerable server. RFC 8725 also documents servers that accept alg: none and skip signature checks entirely.
The defenses are short:
- Specify the allowed algorithms in your verification call. RFC 8725 requires libraries to let the caller set an allowed set of algorithms.
- Bind each key to exactly one algorithm. An RSA public key should never be usable as an HMAC secret.
- Check that the header's
algmatches the algorithm actually used, and reject the token if any cryptographic step fails. - Never accept
nonein production.
Here is the pattern in Python with PyJWT, whose documentation lists HS256 as the default and RS256 as the RSA option taking a PEM-format key:
import jwt
claims = jwt.decode(
token,
public_key_pem,
algorithms=["RS256"], # pinned: never read from the token
audience="https://api.example.com",
issuer="https://auth.example.com",
)
The algorithms list is the line that stops algorithm confusion. If your service only ever accepts RS256, a token claiming HS256 is rejected before any key is touched.
When each algorithm fits
Choose HS256 when
- One application issues and verifies its own tokens, for example a monolith with a single backend.
- The secret stays inside one trust boundary and is never given to a partner or a client.
- You generate at least 32 bytes of real randomness and store it as a secret.
- You do not need to tell which service produced a token.
The kataras/jwt book describes HMAC as a reasonable choice only inside one trust boundary, with at least 32 bytes of real entropy. If your design fits that sentence, HS256 is simple and correct. Our write-up on JWTs versus sessions helps if you are still deciding whether you need JWTs at all.
Choose RS256 when
- A separate service, a partner or an unknown third party must verify tokens.
- You run microservices and want only the auth service to be able to sign.
- You want to publish a JWKS endpoint and rotate keys without touching every consumer.
- You are integrating with an identity provider or OpenID Connect, where RS256 is the common default.
The kataras/jwt book calls RS256 the most widely implemented asymmetric JWT algorithm, which is why it is the safe pick when you cannot control what verifies your tokens.
Consider ES256 and PS256
These two come up constantly in searches because they are the natural next question after RS256.
- ES256 uses ECDSA on the P-256 curve. Per RFC 7518, its signature is 64 octets, much shorter than a 2048-bit RSA signature (256 bytes). Smaller tokens help when they travel in headers or cookies. Check that every consumer supports it first.
- PS256 uses RSA with the PSS padding scheme instead of PKCS#1 v1.5. The kataras/jwt book prefers it for new closed systems because PSS has stronger security proofs, while the older padding has a long history of implementation problems. It requires 2048-bit keys or larger, the same as RS256.
If you are starting a new system and control both sides, ES256 or PS256 is worth a look. If you need maximum compatibility, RS256 remains the practical default.
Side by side
| Question | HS256 | RS256 |
|---|---|---|
| Key model | One shared secret | Private key signs, public key verifies |
| Who can forge tokens | Everyone who can verify | Only the private-key holder |
| Minimum key size | 256 bits | 2048 bits |
| Signature size | 32 bytes | 256 bytes at 2048 bits |
| Rotation | Change the secret in every service | Publish a new public key via JWKS |
| Best fit | Single trust boundary | Multiple or unknown verifiers |
Rotating keys without breaking sessions
Rotation is where RS256 pays off, but it still needs a plan:
- Generate the new key pair and assign it a new
kid. - Publish the new public key in your JWKS while the old one stays published.
- Wait until verifiers have had time to refresh their cache. Tink suggests periodic re-fetching, such as daily, and publishing the new key at least a day before signing with it.
- Switch the issuer to sign with the new private key.
- Keep the old public key published until every token signed with it has expired, plus a margin for clock skew and caching.
If your access tokens live for 15 minutes, the overlap is short. Our guides on JWT expiration handling and rotation and refresh tokens cover the lifetime side of this.
One operational note for teams that test sign-up and login flows end to end: those flows often involve SMS one-time codes alongside the tokens you issue afterward. If you are building test setups for that, a guide to SIM cards for OTP verification covers the receiving side, while your auth service stays responsible for signing and the downstream services only verify.
A checklist before you ship
- The
algis pinned on the server, not read from the token. - HS256 secrets are random, at least 32 bytes, and stored in a secrets manager.
- RS256 keys are 2048 bits or more, and private keys never leave the issuer.
- Each token carries and the verifier checks
iss,audandexp. - Keys have
kidvalues and a rotation process you have actually run once. - No hardcoded signing keys in the repository. Real CVEs, including CVE-2025-7079 and CVE-2025-6950 in the AhnLab JWT analysis report, stem from exactly that.
For a longer list, see our JWT best practices checklist and the 15-minute token defaults guide.
Perspective
Most arguments about HS256 versus RS256 turn into arguments about speed or token size. We think that is the wrong end of the problem. The useful question is who in your system is allowed to create a token, and whether that list matches the list of services that merely need to read one.
When we build and test tooling for developers, the failures we care about are the quiet ones: a secret pasted into three services, an
algheader trusted because the default library call allowed it, a token nobody looked at because decoding it meant opening a terminal. Being able to paste a token into a browser and see its header and claims in seconds, with no install and no account, is what makes those mistakes visible early. That is the idea behind having a JWT Decoder next to the hash, base64 and JSON tools in one free suite.Our advice is plain. If you are inside one trust boundary, HS256 with a strong random secret is fine. The moment a second team, a partner or a client app needs to verify, move to an asymmetric algorithm and pin it on the server.
Andreas
Inspect your tokens with Pingfloat
Pingfloat is a free suite of web tools for developers and IT professionals, and the core tools work without installing anything or creating an account. For JWT work, the JWT Decoder lets you look at a token's header and payload, and the suite sits alongside the JSON formatter, base64 tools and a hash generator for SHA-256 checks. You can browse everything from the Pingfloat home page.

If you also run the services that issue and verify these tokens, the Website Uptime Monitor and SSL Checker cover availability and certificate health for your auth endpoint, including the HTTPS address where your public keys are published.
FAQ
Why is RS256 considered better than HS256?
RS256 separates the power to sign from the power to verify. Only the private-key holder can create tokens, while any service can verify with the public key. That limits the damage when a downstream service is compromised and makes key rotation simpler. HS256 is still a sound choice inside a single trust boundary.
Can I switch from HS256 to RS256 without breaking users?
Yes, with a transition period. Have verifiers accept both algorithms, each pinned to its own key, while the issuer starts signing with RS256. Once all tokens signed with HS256 have expired, remove HS256 from the allowed list and retire the shared secret.
What is the difference between RS256 and PS256?
Both use RSA with SHA-256 and need keys of at least 2048 bits. RS256 uses PKCS#1 v1.5 padding, while PS256 uses PSS padding, which has stronger security proofs. With a 2048-bit key both produce 256-byte signatures, but PS256 support is less universal than RS256.
What does ES256 stand for?
ES256 is ECDSA using the P-256 curve and SHA-256. Its signature is 64 bytes, far smaller than an RSA signature, which makes tokens shorter. Confirm that every system that verifies your tokens supports it before you adopt it.
Sources
- RFC 7518: JSON Web Algorithms
- OWASP JSON Web Token Cheat Sheet
- RFC 8725: JSON Web Token Best Current Practices
- PortSwigger Web Security Academy: algorithm confusion attacks
- kataras/jwt: choosing an algorithm
- Google Tink: JSON Web Tokens
- PyJWT: digital signature algorithms
- AhnLab: A Shadow of JWT report
