Skip to content

What is a JWT? How JSON Web Tokens work

The three parts of a JSON Web Token, what the claims inside mean, how to decode and verify one, and the mistakes that make JWTs insecure.

Guide6 min readUpdated

A JSON Web Token (JWT, pronounced “jot”) is a compact, signed piece of JSON that a server gives a client to prove who they are. After you log in, the server issues a token; your browser or app sends it with every request, usually in an Authorization: Bearer <token> header, and the server checks the signature instead of looking up a session. JWTs are defined in RFC 7519.

The three parts of a JWT

A JWT is three Base64URL-encoded strings joined by dots: header, payload and signature.

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ1c2VyXzEyMyIsIm5hbWUiOiJBbm4gTGVlIiwicm9sZSI6ImFkbWluIiwiaWF0IjoxNzYwMDAwMDAwLCJleHAiOjE3NjAwMDM2MDB9.qQsxyuXRpZqDyVjyHZfuOMFhCtWzMwkSa1HGQhbSCvs

Header

Says how the token is signed:

{
  "alg": "HS256",
  "typ": "JWT"
}

Payload

The claims: statements about the user and the token itself.

{
  "sub": "user_123",
  "name": "Ann Lee",
  "role": "admin",
  "iat": 1760000000,
  "exp": 1760003600
}

Signature

A cryptographic signature of the first two parts, made with the server's secret or private key. If anyone changes a single character of the header or payload, the signature no longer matches and the server rejects the token.

A JWT is signed, not encrypted

This is the most important thing to understand: Base64URL is an encoding, not encryption. Anyone who has the token can read the payload; you can paste the example above into the JWT Decoder or decode each part with the Base64 Converter. The signature only guarantees the data wasn't changed. So never put passwords, card numbers or other secrets in a JWT.

Registered claims

RFC 7519 defines a few standard claim names. All are optional, but most tokens use several:

issIssuerWho created the token, e.g. your auth server's URL.
subSubjectWho the token is about, usually a user ID.
audAudienceWhich service the token is meant for.
expExpiration timeWhen the token stops being valid.
nbfNot beforeWhen the token starts being valid.
iatIssued atWhen the token was created.
jtiJWT IDA unique ID, used to detect reuse or revoke a token.

Times such as exp and iat are Unix timestamps in seconds. In the example, 1760000000 is 9 Oct 2025, 08:53:20 UTC, and the token expires one hour later. The Epoch Converter turns any of these into a readable date; the JWT Decoder does it for you and shows whether the token has expired.

Signing algorithms: HS256, RS256 and ES256

  • HS256 (HMAC with SHA-256) uses one shared secret to sign and verify. Simple, but every service that verifies tokens can also create them.
  • RS256 (RSA) signs with a private key and verifies with a public key, so other services can check tokens without being able to issue them. Common with identity providers.
  • ES256 (ECDSA) works like RS256 with much smaller keys and signatures.

How to decode and verify a JWT

Paste a token into the JWT Decoder to see the header and payload as formatted JSON, every claim explained and the expiry as a date. Open Verify and enter the secret (HS256) or public key (RS256, ES256) to check the signature. Decoding and verifying both happen in your browser, so the token is never sent anywhere. In code, decoding is just Base64URL plus JSON.parse:

const [header, payload] = token.split(".").slice(0, 2).map((part) =>
  JSON.parse(atob(part.replace(/-/g, "+").replace(/_/g, "/")))
);
// For real authentication, verify the signature with a library such as jose.
Fine for reading a token; never trust its contents without verifying the signature.

Common JWT security mistakes

  • Trusting a token without verifying it. Always check the signature on the server, with the algorithm you expect.
  • Accepting alg: none. Unsigned tokens must be rejected; pin the allowed algorithms in your library's settings.
  • Ignoring exp. Keep access tokens short-lived (minutes, not months) and use refresh tokens for longer sessions.
  • Weak HS256 secrets. A short or guessable secret can be brute-forced offline from a single token; use at least 256 random bits.
  • Putting secrets in the payload. Remember that anyone can read it.

Frequently asked questions

Is a JWT encrypted?

Usually not. A normal (signed) JWT is only Base64URL-encoded, so anyone with the token can read the payload. The signature proves it wasn't changed; it doesn't hide anything. Encrypted tokens (JWE) exist but are much less common.

Is it safe to paste a JWT into an online decoder?

Only into one that decodes in your browser without sending the token anywhere, like the JSON Toolkit JWT Decoder. A valid token can be used to act as you until it expires, so treat production tokens like passwords.

What's the difference between HS256 and RS256?

HS256 signs with one shared secret, so whoever verifies the token can also create tokens. RS256 signs with a private key and verifies with a public key, so services can check tokens without being able to issue them.

Tools used in this guide

More guides