What does jwt decode do

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: Decoding a JWT (JSON Web Token) involves parsing the token's three parts (header, payload, and signature) to extract the information contained within. This process typically involves base64 decoding the header and payload, and then verifying the signature using the secret key or public key to ensure the token's integrity and authenticity.

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 authorization in web applications and APIs.

Structure of a JWT

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

  1. Header: The header is a JSON object that typically contains metadata about the token, such as the type of token (JWT) and the cryptographic algorithm used for signing (e.g., HMAC SHA256 or RSA). This header is Base64Url encoded.

    Example Header:

    {
    "alg": "HS256",
    "typ": "JWT"
    }
  2. Payload: The payload is a JSON object that contains the claims. Claims are statements about an entity (typically, the user) and additional data. Common claims include user ID, roles, permissions, and expiration time. The payload is also Base64Url encoded.

    Example Payload:

    {
    "sub": "1234567890",
    "name": "John Doe",
    "iat": 1516239022
    }
  3. Signature: The signature is created by taking the encoded header, the encoded payload, a secret (or a private key), and the algorithm specified in the header, and signing them. The signature is used to verify that the sender of the JWT is who it says it is and to ensure that the message was not changed along the way. The signature is NOT encoded.

    Example Signature generation:

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

What Does JWT Decode Do?

Decoding a JWT involves several steps to extract and verify the information it contains. The primary purpose of decoding is to access the claims (data) within the payload and to ensure that the token has not been tampered with.

1. Splitting the Token:

The first step is to split the JWT string into its three component parts using the dot ('.') as a delimiter: header, payload, and signature.

2. Base64Url Decoding:

The header and payload parts, which are Base64Url encoded, are then decoded. This process converts the encoded strings back into their original JSON string representations.

3. Signature Verification:

This is the most critical step for security. The signature is verified to ensure the token's integrity and authenticity. The process typically involves:

If the signatures match, it means the token was issued by the expected party and has not been altered since it was issued. If they do not match, the token is considered invalid or compromised.

Why Decode a JWT?

Decoding a JWT is essential for several reasons:

Many libraries and tools are available in various programming languages (e.g., `jwt.decode` in Python's `PyJWT`, `jwt.verify` in Node.js's `jsonwebtoken`) that abstract away the complexities of decoding and verification, making it easier for developers to work with JWTs securely.

Sources

  1. JSON Web TokensCC-BY-4.0
  2. JSON Web Token - WikipediaCC-BY-SA-3.0
  3. RFC 7519 - JSON Web Token (JWT)BCP 78

Missing an answer?

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