opyeb JWTScope

Guides · Token basics

The three parts of a JWT, byte for byte

Updated 28 Nov 2026 · 7 min read

A JSON Web Token in its usual form is a string of three base64url segments separated by dots: header.payload.signature. The first two segments are UTF-8 JSON objects encoded with base64url. The third is the raw signature bytes, also base64url encoded. Nothing else is added: no line breaks, no padding equals signs, no quotes around the whole token.

Take the token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIn0.dozjgNryP4J3jVmNHl0w5N_XgL0n3I9PlFUP0THsR8U. Split it at the two dots and decode each part. The header is {"alg":"HS256","typ":"JWT"} and the payload is {"sub":"1234567890"}. The third segment is 32 bytes, which is the length of an HMAC-SHA256 output. None of those bytes mean anything to a reader without the secret.

What belongs in the header

The header is a small JSON object that tells a verifier how to process the token. alg names the signature algorithm, such as HS256, RS256, ES256 or EdDSA, and is mandatory. typ is a media type hint and is usually JWT; RFC 9068 access tokens use at+jwt. kid identifies which key signed the token, which matters as soon as a service rotates keys. cty is used only when the payload is itself a JWT, as in nested tokens.

The header is not a place for secrets. It is readable by anyone holding the token, and a verifier must never let the header choose a weaker algorithm than the one it was configured to accept. A common attack is to change alg to none or from RS256 to HS256 and hope the library follows the token instead of its own policy.

What belongs in the payload

The payload is a JSON object of claims. Seven claim names are registered in RFC 7519 and mean the same thing everywhere: iss (issuer), sub (subject), aud (audience), exp (expiration time), nbf (not before), iat (issued at) and jti (JWT ID). Every other name is defined by the application or by a profile such as OpenID Connect, which adds auth_time, nonce, acr, amr and identity claims.

Time claims are numeric seconds since the Unix epoch, not milliseconds and not ISO strings. A token issued at 2026-11-28 07:00:00 UTC carries iat equal to 1795858800. Sending milliseconds produces a date tens of thousands of years in the future, and some verifiers will accept it while others reject the token as not yet valid. This one mistake accounts for a large share of production JWT failures.

SegmentContentEncodingReadable without a key?
Headeralg, typ, kid and other parametersbase64url of UTF-8 JSONYes
PayloadClaims about the subject and the grantbase64url of UTF-8 JSONYes
SignatureMAC or public-key signature bytesbase64url of raw bytesNo, but it can be checked with the right key

How the signature is computed

For a JWS, the signing input is exactly header.payload — the two encoded segments joined by a dot, as ASCII. The signature is computed over those bytes, then appended as the third segment. A verifier must reconstruct the same string from the token it received, not from re-serialised JSON. Re-encoding the JSON with different key order or whitespace produces a different signing input and a false mismatch, which is why well-written libraries keep the original segments.

Because the signature covers the encoded text, it also protects the header. Changing kid or alg invalidates the signature just as changing a claim does. The only freedom a forger has is to produce a completely new token and sign it with a key the verifier trusts, which is the whole point of key management.

Sizes and practical limits

A minimal HS256 token with two short claims is around 120 characters. A typical OIDC ID token with an email, a name and a few groups is 800 to 1,500 characters. Once a token passes roughly 4 KB it becomes awkward in cookies and can hit reverse-proxy header limits, so bulky data belongs in an API call, not in the token. The verifier on this site warns when a token is larger than 4 KB.

Compact serialization versus JWE

The three-part form is called JWS Compact Serialization. A JWE, which encrypts its payload, uses five parts: protected header, encrypted key, initialization vector, ciphertext and authentication tag. If you split a token and get five segments, it is encrypted rather than merely signed, and a JWS verifier will refuse it. Both forms can be nested: a signed token can be the payload of an encrypted one.

Rule of thumb: a JWT is a container, not a security guarantee. Its value depends entirely on which key signed it and which claims your service checks afterwards.

Sources

Questions

Is a JWT encrypted?

No. A signed JWT (JWS) is only encoded, so anyone who holds it can read the header and payload. Encryption is a separate format, JWE, which has five parts and hides the payload from everyone without the key.

Why base64url instead of ordinary base64?

A JWT has to travel in URLs, HTTP headers and cookies, where +, / and = have special meanings or need escaping. Base64url replaces + with -, / with _, and drops the padding, so the token is safe to place in a query string without further encoding.

Can I edit the payload and keep the signature?

No. The signature is computed over the exact ASCII text of header.payload, so any change to either part invalidates it. Editing a payload produces a token that a correct verifier rejects — which is exactly how you can test a verifier.

Paste any token into the verifier to see its three parts decoded side by side.

Open the verifier

Written against the JOSE specifications (RFC 7515–7519), RFC 7636 and RFC 8037; every example can be reproduced in the verifier linked above.

Back to the guides