DevNexus LogoDevNexus
ToolsBlogAbout
K
Browse Tools
HomeBlogJWT Structure Explained Header Payload Signature
DevNexus LogoDevNexus

A free, open-source toolkit of developer utilities. Built by developers, for developers.

Tools

  • All Tools
  • Text Utilities
  • Encoders
  • Formatters

Resources

  • Blog
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

ยฉ 2026 MyDevToolHub

Built with Next.js 16 + MongoDB ยท Crafted for developers

jwt structurejwt header payload signatureauthenticationweb developmentnodejs

JWT Structure Explained: Header, Payload, Signature with Real Examples

Learn how JWT works internally by understanding its structure: header, payload, and signature with real-world examples and code.

DT
MyDevToolHub Team
Mar 18, 20265 min read

Related tools

Browse all tools
Jwt DecoderOpen jwt-decoder tool

Introduction

JSON Web Tokens (JWT) are one of the most important concepts in modern authentication systems. But many developers use JWT without fully understanding how it actually works internally.

If you truly want to master JWT, you must understand its structure:

  • Header
  • Payload
  • Signature

In this guide, we will break down each part in detail with real examples and code.

๐Ÿ‘‰ You can instantly decode and inspect JWT tokens here: https://www.mydevtoolhub.com/tools/jwt-decoder


What is JWT Structure?

A JWT token looks like this:

Code
xxxxx.yyyyy.zzzzz

It consists of three parts separated by dots:

Code
Header.Payload.Signature

Each part is Base64URL encoded.


1. JWT Header (First Part)

The header contains metadata about the token.

Example Header:

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

Explanation:

  • alg โ†’ Algorithm used for signing (e.g., HS256, RS256)
  • typ โ†’ Token type (JWT)

Encoded Header:

Code
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9

2. JWT Payload (Second Part)

The payload contains the actual data (claims).

Example Payload:

Code
{
  "userId": "123",
  "email": "user@example.com",
  "role": "admin",
  "exp": 1710000000
}

Types of Claims:

1. Registered Claims

  • iss (issuer)
  • sub (subject)
  • exp (expiration)
  • iat (issued at)

2. Public Claims

  • Custom but standardized fields

3. Private Claims

  • Custom app-specific data

Important Note:

โš ๏ธ Payload is NOT encrypted โ€” anyone can decode it.


3. JWT Signature (Third Part)

The signature ensures the token has not been tampered with.

How Signature is Created:

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

Example Code:

Code
const jwt = require('jsonwebtoken');

const token = jwt.sign({ userId: 123 }, 'secret', {
  algorithm: 'HS256'
});

Visual Breakdown of JWT

Code
HEADER        PAYLOAD        SIGNATURE
-----         -------        ---------
eyJhbGci...   eyJ1c2Vy...    SflKxwR...

Step-by-Step JWT Creation Flow

Step 1: Create Header

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

Step 2: Create Payload

Code
{ "userId": "123" }

Step 3: Encode Both

Step 4: Generate Signature

Step 5: Combine All

Code
header.payload.signature

Decoding JWT (Manual Method)

You can manually decode JWT:

Code
const base64 = token.split('.')[1];
const decoded = JSON.parse(Buffer.from(base64, 'base64').toString());
console.log(decoded);

Or use: https://www.mydevtoolhub.com/tools/jwt-decoder


Common Mistakes Developers Make

โŒ Thinking JWT is encrypted

It is only encoded.

โŒ Storing sensitive data

Never store passwords or secrets.

โŒ Ignoring signature validation

Always verify JWT before trusting it.


Real Example Token Breakdown

Token:

Code
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9
.
eyJ1c2VySWQiOiIxMjMiLCJleHAiOjE3MDAwMDAwMDB9
.
abc123signature

Decoded:

Header:

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

Payload:

Code
{ "userId": "123", "exp": 1700000000 }

Why Understanding JWT Structure is Important

  • Helps debug authentication issues
  • Prevents security mistakes
  • Improves backend architecture
  • Essential for interviews

Advanced Topics

HS256 vs RS256

AlgorithmTypeKey
HS256SymmetricSame secret
RS256AsymmetricPublic/Private

JWT vs JWE

  • JWT โ†’ Signed
  • JWE โ†’ Encrypted

FAQs

Q1: Can I modify payload?

Yes, but signature will break.

Q2: Why 3 parts?

To separate metadata, data, and verification.

Q3: Is signature mandatory?

Yes, for secure JWT.

Q4: Can I trust decoded data?

Only after verification.


Conclusion

Understanding JWT structure is the foundation of secure authentication.

Once you know how header, payload, and signature work, debugging and securing your app becomes much easier.

๐Ÿ‘‰ Try decoding your own token here: https://www.mydevtoolhub.com/tools/jwt-decoder

Master the structure โ€” and you master JWT.

On This Page

  • Introduction
  • What is JWT Structure?
  • 1. JWT Header (First Part)
  • Example Header:
  • Explanation:
  • Encoded Header:
  • 2. JWT Payload (Second Part)
  • Example Payload:
  • Types of Claims:
  • Important Note:
  • 3. JWT Signature (Third Part)
  • How Signature is Created:
  • Example Code:
  • Visual Breakdown of JWT
  • Step-by-Step JWT Creation Flow
  • Step 1: Create Header
  • Step 2: Create Payload
  • Step 3: Encode Both
  • Step 4: Generate Signature
  • Step 5: Combine All
  • Decoding JWT (Manual Method)
  • Common Mistakes Developers Make
  • โŒ Thinking JWT is encrypted
  • โŒ Storing sensitive data
  • โŒ Ignoring signature validation
  • Real Example Token Breakdown
  • Token:
  • Decoded:
  • Why Understanding JWT Structure is Important
  • Advanced Topics
  • HS256 vs RS256
  • JWT vs JWE
  • FAQs
  • Q1: Can I modify payload?
  • Q2: Why 3 parts?
  • Q3: Is signature mandatory?
  • Q4: Can I trust decoded data?
  • Conclusion

You Might Also Like

All posts

Real-World URL Encoding Examples Every Developer Should Know (Practical Guide)

Master URL encoding with real-world examples including forms, search queries, APIs, and redirects. A practical guide for developers.

Mar 18, 20267 min read

How URL Encoding Helps Prevent Injection Attacks in Web Applications (XSS & SQL Explained)

Learn how URL encoding protects your web apps from XSS and SQL injection attacks. A practical security guide for developers.

Mar 18, 20267 min read

URL Encoding in JavaScript, Node.js, and Python (With Practical Code Examples)

Learn how to implement URL encoding in JavaScript, Node.js, and Python with real-world examples, best practices, and developer-focused insights.

Mar 18, 20266 min read