What Is a JWT and How Do You Decode It?

Have you worked with logins or APIs? Then you have probably seen a long string that starts with eyJ. That is almost always a JWT. JWT is short for JSON Web Token. Its standard says you can say it like the English word “jot”.

This guide explains what is inside a JWT and how to read it. It also shows the one big mistake to avoid. That mistake is thinking that a token you can read is a token you can trust.

Quick answer: A JWT is a string with three parts, split by dots: header, payload and signature. The header and payload are small JSON objects written in Base64URL. So anyone can decode and read them. The signature shows who made the token. But only a server with the right key can check it.

What does a JWT look like?

Here is a well-known example token. We split it over three lines so it fits on the page. A real token is one long line.

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ
.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

Decode the first two parts, and you get two small JSON objects:

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

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

The three parts of a JWT

  1. Header. It says how the token was signed. alg is the signing method, such as HS256 or RS256. typ is the token type.
  2. Payload. This is the data the token carries. Each fact in it is called a claim. For example, a claim can be the user’s ID or the time the token expires.
  3. Signature. This is a code made from the header and payload with a secret key. If anyone changes even one character of the payload, the signature no longer matches. The signature is not JSON. So it decodes to bytes that look random.

What is Base64URL?

Base64 is a way to write any data with only 64 safe characters. These are letters, digits and two symbols.

Base64URL is a small change to Base64 that is safe to put in a web address. It uses - and _ instead of + and /. It also drops the = signs at the end.

Each part of a JWT is Base64URL text. That is why almost every JWT starts with eyJ. It is how {" looks in Base64. You can try this yourself with the JSON Base64 tool. It accepts the URL-safe characters.

Base64 is not encryption. It only changes how the data is written. Anyone who has the token can read the payload. So never put passwords or other secrets in it.

Most JWTs you will see are signed, not encrypted. An encrypted kind does exist, called JWE. But it looks different: it has five parts instead of three.

Common JWT claims and what they mean

These short claim names come from the JWT standard, RFC 7519. All of them are optional. Apps often add their own claims too, like email or roles.

  • iss (issuer) — who made the token, such as your login server.
  • sub (subject) — who the token is about, usually a user ID.
  • aud (audience) — which app or API the token is for.
  • exp (expiration time) — after this time, the token must not be accepted.
  • nbf (not before) — the token must not be accepted before this time.
  • iat (issued at) — when the token was made.
  • jti (JWT ID) — a unique ID for this token.

Expiry times are Unix seconds

exp, iat and nbf are plain numbers. They count the seconds since 1 January 1970 (UTC). This is called Unix time.

In the example above, iat: 1516239022 means 18 January 2018, 01:30:22 UTC.

Be careful in JavaScript. Its dates use milliseconds, not seconds. So you must multiply by 1000:

const payload = { exp: 1516242622 };

const expires = new Date(payload.exp * 1000);
console.log(expires.toISOString()); // 2018-01-18T02:30:22.000Z

const expired = Date.now() >= payload.exp * 1000;

How to decode a JWT

With the JWT Decoder

Paste the token into the JWT Decoder. If it starts with “Bearer ”, the tool removes that word for you. The header and payload appear as neat JSON.

The status bar shows the signing method. It also shows when the token was made, and if it has expired. Times are shown as dates you can read.

Is the payload large, with many levels inside it? Copy it into the JSON Viewer. There you can explore it as a tree you can open and close.

With a few lines of JavaScript

function decodePart(part) {
  const base64 = part.replace(/-/g, "+").replace(/_/g, "/");
  const bytes = Uint8Array.from(atob(base64), (c) => c.charCodeAt(0));
  return JSON.parse(new TextDecoder().decode(bytes));
}

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

The TextDecoder step makes accented letters and emoji show correctly. In Node.js, you can write Buffer.from(payload, "base64url").toString("utf8") instead.

Decoding is not verifying

This is the most important part. Anyone can make a token with any payload they like. Decoding only reads it. It does not tell you if the token is real.

Verifying means checking the signature with the right key. For HS256, this is a shared secret. For methods like RS256, it is a public key.

Do this on your server, with a well-tested JWT library. A good check also:

  • Rejects tokens whose exp time has passed.
  • Checks that iss and aud match what you expect.
  • Accepts only the signing methods you use. Some old attacks tricked servers by setting alg to none.

Is it safe to paste a JWT into a website?

Be careful. A JWT often works like a key. Whoever has it may be able to act as that user until it expires.

Some online decoders send what you paste to their server. There, it could be saved in a log.

Never paste a real, live token into a site unless you know it decodes in your browser. JSONPilot’s JWT Decoder runs fully in your browser. So the token is never sent to a server.

Even so, test tokens or expired tokens are the safest choice. Do you think a real token has leaked? Tell the people who run that system, so they can cancel it.

Common questions

Can you decode a JWT without the secret key?

Yes. The header and payload are only Base64URL text, so anyone can read them. You need the key only to make a signature or to check one.

Is a JWT encrypted?

Usually not. A normal JWT is signed. This stops people from changing it, but anyone can read it. Encrypted tokens (JWE) exist, but they are less common.

What does exp mean in a JWT?

exp is the expiry time, written in Unix seconds. After that moment, a server should refuse the token.

Why does my JWT say it expired in 1970?

Your code probably treated the seconds as milliseconds. In JavaScript, multiply exp by 1000 before you pass it to new Date().