How to Decode a JWT Token (and What the Three Parts Mean)

To decode a JWT token, split it on the two dots and base64url-decode the first two parts. The first part is the header, the second is the payload, and the third is the signature. The fastest way is to paste the token into a JWT decoder and read the result. This guide shows you how that works, what each part means, and the one mistake that matters most: decoding a token is not the same as trusting it.

A JWT — JSON Web Token, pronounced “jot” — is defined by RFC 7519. It is a compact way for one system to send claims about a user or a service to another system: who you are, when the token expires, what you are allowed to do. You meet JWTs most often after logging in to a website or API, when the server hands your browser a token to send back with every request.

Padlock symbolising digital security

What a JWT Is: Header, Payload, Signature

Every JWT has the same shape: three base64url-encoded segments joined by dots.

header.payload.signature

Here is a real example token (the standard example from jwt.io, using a public demo secret — never put a real secret in an example like this):

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

Decode the first segment and you get the header:

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

The header says how the token is signed. alg is the signing algorithm — HS256 means HMAC with SHA-256, a symmetric algorithm where the same secret signs and verifies. typ is the token type, almost always JWT.

Decode the second segment and you get the payload, which carries the claims:

{
  "sub": "1234567890",
  "name": "John Doe",
  "iat": 1516239022
}

sub is the subject — who the token is about, usually a user ID. name is a custom claim the issuer added. iat is when the token was issued, as a Unix timestamp: 1516239022 is 18 January 2018 at 01:30:22 UTC.

The third segment is the signature. It is computed from the encoded header and payload plus a secret key:

HMACSHA256(
  base64UrlEncode(header) + "." + base64UrlEncode(payload),
  secret
)

The signature is what lets a server check that nobody changed the header or payload after the token was issued. Change one character in the payload and the signature no longer matches.

One detail worth knowing: JWTs use base64url encoding, a URL-safe variant of Base64 from RFC 4648. It swaps + for - and / for _, and drops the = padding, so a token can travel inside a URL or an HTTP header without escaping.

Decode a JWT Online in Seconds

The quickest way to read a token is the free JWT decoder: paste the token, and it shows the decoded header and payload with the claims laid out. That is usually all you need when you are debugging — checking which user a token belongs to, when it expires, or whether the claims your code expects are actually there.

A word of caution before you paste anything: a JWT is a credential. Anyone holding a valid token can act as that user until it expires. Do not paste production tokens into random websites, and do not share tokens in screenshots, chat logs, or bug reports. If you are debugging with a real token, prefer a decoder that runs in your browser without sending the token to a server, or decode it locally with the code below.

Decode a JWT in JavaScript and Python

Decoding is a few lines in any language, because it is just base64url decoding plus JSON parsing. In Python:

import base64, json

token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"
header_b64, payload_b64, signature = token.split(".")

def decode(segment):
    padding = "=" * (-len(segment) % 4)
    return json.loads(base64.urlsafe_b64decode(segment + padding))

print(decode(header_b64))
# {'alg': 'HS256', 'typ': 'JWT'}
print(decode(payload_b64))
# {'sub': '1234567890', 'name': 'John Doe', 'iat': 1516239022}

The padding line matters: JWT segments drop the = padding, but Python’s decoder expects it, so you add back as many = characters as needed to make the length a multiple of 4.

In JavaScript, the browser’s atob function decodes standard Base64, so you convert base64url back first:

function decodeJwtSegment(segment) {
  const base64 = segment.replace(/-/g, "+").replace(/_/g, "/");
  const padded = base64.padEnd(base64.length + (4 - base64.length % 4) % 4, "=");
  return JSON.parse(atob(padded));
}

const [header, payload] = token.split(".");
console.log(decodeJwtSegment(header));
console.log(decodeJwtSegment(payload));

On the command line, jq pairs well with the same idea:

echo $TOKEN | cut -d. -f2 | tr '_-' '/+' | base64 -d 2>/dev/null | jq .

This prints the decoded payload as formatted JSON. Change -f2 to -f1 for the header.

Rows of servers in a data centre

How to Read the Claims (exp, iss, sub, and Custom Claims)

RFC 7519 defines a short list of registered claims. None of them is mandatory, but they are widely used and every JWT library understands them:

Claim Full name What it means
iss Issuer Who created the token, usually the auth server’s URL.
sub Subject Who the token is about, usually a user ID.
aud Audience Who the token is intended for, usually your API’s URL.
exp Expiration time Unix timestamp (seconds) after which the token must be rejected.
nbf Not before Unix timestamp before which the token is not valid yet.
iat Issued at Unix timestamp marking when the token was created.
jti JWT ID A unique ID for the token, used to detect replays.

All three time claims — exp, nbf, and iat — are whole seconds since 1 January 1970 UTC, not milliseconds. If you see a 13-digit number in one of them, something upstream mixed up the units.

Beyond the registered claims, issuers add their own: name, email, role, permissions, and anything else the application needs. These custom claims are just JSON keys. Your code reads them the same way, but it should never trust them without verifying the signature first — which brings us to the most important section of this guide.

Decoding Is Not Verifying: Why the Signature Matters

Anyone can decode a JWT. The payload is encoded, not encrypted, and the encoding is trivially reversible — you just did it in five lines of Python. A decoded token proves nothing on its own. It only becomes trustworthy when the signature checks out, because the signature is the only part that proves the issuer created the token and nobody altered it since.

Here is the attack that makes this concrete. Suppose a token’s payload says "role": "user". Anyone can decode the token, change that to "role": "admin", re-encode it, and send it to your API. If your server only decodes the payload and reads the role, the attacker is now an admin. If your server verifies the signature, the forged token fails immediately, because the attacker does not have the secret key needed to make a matching signature.

So the rule is simple: decode for debugging, verify for decisions. In your own code, always use a well-known JWT library for verification — never hand-roll the check — and make sure the library actually checks the signature, the exp claim, and the aud and iss claims. Some libraries skip the audience and issuer checks unless you configure them. To create and check signatures yourself, the JWT signer and verifier lets you sign a token with a secret and verify one in the browser.

Padlock on a door, symbolising locked-down security

JWT Security Mistakes to Avoid

  • Putting secrets in the payload. The payload is readable by anyone with the token. Never put passwords, API keys, or payment details in a JWT. Assume every claim is public.
  • Accepting alg: none. RFC 7519 defines an unsigned algorithm for tokens that deliberately carry no signature. A server that accepts it will trust any token anyone makes up. Your verifier must reject none outright.
  • Skipping the expiry check. A token without an exp claim never expires. Always set a short expiry — an hour is a common choice for access tokens — and always check it on the server.
  • Using a weak secret with HS256. HMAC security rests entirely on the secret. A short or guessable secret can be brute-forced offline, and then the attacker can sign any token they like. Use a long random secret, stored as an environment variable, never in source code.
  • Trusting the header’s algorithm blindly. The alg value comes from the token itself, so an attacker controls it. Your verifier should accept only the algorithms you actually use, and never let the token switch the server from an asymmetric algorithm to a symmetric one.

Close-up of programming code on a screen

Frequently Asked Questions

How do I decode a JWT token online?

Paste the token into the free JWT decoder. It splits the token on the dots and shows the decoded header and payload. Avoid pasting production tokens into sites you do not trust — a token is a credential.

What are the three parts of a JWT?

The header (signing algorithm and token type), the payload (claims about the user and the token, such as sub and exp), and the signature (a cryptographic check over the header and payload). They are joined by dots: header.payload.signature.

Is a decoded JWT safe to trust?

No. Decoding only reads the contents — anyone can decode any token, and anyone can forge a payload. Trust comes from verifying the signature with the issuer’s secret or public key, and checking the exp, aud, and iss claims.

Can I decode a JWT without the secret key?

Yes. Decoding needs no key at all, because the header and payload are only base64url-encoded. The secret is needed only to verify the signature or to create a new valid token.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top