How to jwt decode

Content on WhatAnswers is provided "as is" for informational purposes. While we strive for accuracy, we make no guarantees. Content is AI-assisted and should not be used as professional advice.

Last updated: April 4, 2026

Quick Answer: JWT decoding involves taking a JWT (JSON Web Token) and parsing its three base64-encoded parts: the header, the payload, and the signature. The header and payload are typically JSON objects that can be read directly once decoded. The signature is used for verification, not direct decoding into human-readable data.

Key Facts

What is a JWT?

A JSON Web Token (JWT) is a compact, URL-safe means of representing claims to be transferred between two parties. It is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs are commonly used for authentication and information exchange in web applications, particularly in APIs and single sign-on (SSO) systems. They allow a server to communicate information about a user or an application to another party without needing to be re-queried.

Understanding JWT Structure

A JWT consists of three parts, separated by dots (.):

  1. Header: This part contains metadata about the token, such as the type of token (JWT) and the signing algorithm being used (e.g., HMAC SHA256 or RSA). The header is itself a JSON object and is base64url encoded.
  2. Payload: This part contains the claims. Claims are statements about an entity (typically, the user) and additional data. Common claims include user ID, roles, expiration time, issuer, and audience. Like the header, the payload is a JSON object and is base64url encoded.
  3. Signature: This part is used to verify that the sender of the JWT is who it says it is and to ensure that the message wasn't changed along the way. It is created by taking the encoded header, the encoded payload, a secret (for symmetric algorithms) or a private key (for asymmetric algorithms), and signing them using the algorithm specified in the header.

How to Decode a JWT

Decoding a JWT involves separating its three components and then decoding the header and payload. The signature is not decoded in the same way; it's used for verification.

Step 1: Split the Token

The first step is to split the JWT string by the dot (.) character. This will give you three parts: the encoded header, the encoded payload, and the encoded signature.

Step 2: Decode the Header

The header is base64url encoded. You can use any base64url decoding tool or library available in your programming language to decode this part. Once decoded, you will get a JSON string representing the header object. You can then parse this JSON string to access its contents.

Step 3: Decode the Payload

Similarly, the payload is also base64url encoded. Decode this part using a base64url decoder. The result will be a JSON string containing the claims. Parse this JSON string to read the claims, such as user ID, roles, and expiration dates.

Step 4: Verify the Signature (Crucial for Security)

While you can decode the header and payload to read their contents, you should never trust the data from a JWT without verifying its signature. The signature verification process ensures that the token has not been tampered with and was indeed issued by the expected party. This process involves:

Important Security Note: Decoding the header and payload is straightforward and can be done by anyone. However, the security of JWTs relies entirely on the signature verification. Always verify the signature using the correct secret or public key before trusting the claims within the payload. Failure to do so can lead to serious security vulnerabilities, allowing attackers to forge tokens and gain unauthorized access.

Tools and Libraries for JWT Decoding

There are numerous tools and libraries available to help you decode and verify JWTs:

When using libraries, you typically provide the JWT string and the secret or public key to a verification function. The library will then decode the token, verify the signature, and return the claims if the token is valid, or throw an error if it's invalid.

When to Decode a JWT

You might need to decode a JWT in several scenarios:

In summary, decoding a JWT involves base64url decoding the header and payload components to reveal their JSON structure. However, the critical step for security is always to verify the token's signature using the appropriate secret or public key.

Sources

  1. JSON Web Tokensfair-use
  2. RFC 7519: JSON Web Token (JWT)CC0-1.0

Missing an answer?

Suggest a question and we'll generate an answer for it.