Skip to content

JWT size calculator

Measure a token in bytes, as a header and as a cookie, and see how it fits the default header and cookie limits of common servers.

Runs in your browser. Nothing you paste is sent to us.

Token

A sample access token for the made-up realm acme is filled in.

Used to measure the token as a cookie.

Token
1434 bytes (1.4 KB)1434 characters
Header part
71 bytes
Payload part
1019 bytes
Signature part
342 bytes
As a header
1456 bytes (1.4 KB)Authorization: Bearer …
As a cookie
1487 bytes (1.5 KB)With Path, Secure, HttpOnly and SameSite

Limits

WhereLimitThis token
One browser cookie
Name, value and attributes together; RFC 6265 asks browsers to allow at least this
409636%fits
nginx, one header line
large_client_header_buffers, default 4 8k
819218%fits
Apache httpd, one header
LimitRequestFieldSize, default 8190
819018%fits
Tomcat, all headers
maxHttpHeaderSize, default 8 KB
819218%fits
Node.js, all headers
max-http-header-size, default 16 KB
163849%fits

The Tomcat and Node.js limits count all request headers together, so cookies and other headers share that room. Each limit can be raised in the software’s settings.

Largest claims

ClaimJSON bytesIn the token, about
resource_access151202
realm_access101135
jti4763
sub4763
sid4763
allowed-origins4662
iss4560
aud3142

How to use it

  1. Paste the token.
  2. Read its size and the size of each part.
  3. Compare it with the limits in the table.
  4. Look at the largest claims to see what to trim.

What to know

Browsers keep a cookie only up to about 4096 bytes, and servers and proxies cap request headers. A token that grows past a limit fails, often with status 400 or 431.

Tokens grow with roles, groups and custom claims. In Keycloak, the usual culprits are many client roles in resource_access and large group lists.

To shrink a Keycloak token, remove unneeded client scopes from the client, turn off Full scope allowed so only needed roles are included, or drop claims from the access token in the mappers.

Why token size matters

A JWT travels with every request: in an Authorization header or in a cookie. Each claim you add makes every request a little larger, and past certain sizes requests start to fail. Browsers drop cookies that are too large, and servers and proxies reject requests whose headers exceed their limits.

The failures are confusing because they depend on the user. A user with three roles works; a user with three hundred groups gets an error page. Measuring the token tells you how close you are to a limit and which claims to trim.

How a token’s size adds up

A signed JWT is three Base64url parts joined by dots. Base64url writes every 3 bytes as 4 characters, so the header and payload grow by about a third compared with their JSON. The signature has a fixed size for each algorithm.

AlgorithmSignature bytesBase64url characters
HS2563243
ES2566486
RS256 with a 2048-bit key256342
RS256 with a 4096-bit key512683

The payload is usually the largest part, and within it a few claims dominate: role lists, group lists, and user attributes added by mappers.

What this calculator shows

  • The token’s size in bytes, and the size of each of its three parts.
  • Its size as an Authorization: Bearer header line.
  • Its size as a cookie with the usual attributes, using the cookie name you enter.
  • A comparison with the default limits of common software.
  • The largest claims, with their share of the token, so you know what to trim.

Common limits

These are documented defaults. Each can be changed in the software’s configuration.

WhereDefault limitCounts
Browser cookieAbout 4096 bytesOne cookie: name, value and attributes (RFC 6265 asks browsers to allow at least this)
nginx8 KBOne request header line (large_client_header_buffers 4 8k)
Apache httpd8190 bytesOne request header field (LimitRequestFieldSize)
Tomcat8 KBAll request headers together (maxHttpHeaderSize)
Node.js16 KBAll request headers together (--max-http-header-size)

Where the limit covers all headers, the token shares the space with cookies, the user agent and everything else in the request. When a limit is exceeded, servers typically answer with status 400 or 431.

How to measure a token

  1. Paste the token, ideally for the user with the most roles and groups.
  2. Enter the cookie name your app uses, if it stores the token in a cookie.
  3. Read the sizes and the limits table.
  4. Look at the largest claims to decide what to remove or move.

What makes Keycloak tokens grow

A Keycloak access token’s size depends on the user, the client and the client scopes.

Roles from every client

When Full scope allowed is on for a client, the token lists every realm role and every client role the user has, for every client. In a realm with many clients, resource_access becomes the biggest claim.

Groups

A group membership mapper writes every group path the user belongs to. Users in many groups produce long lists, especially with full paths.

User attributes and custom mappers

Each mapper that copies an attribute into the access token adds to every request, even when only one API needs the value.

How to make a Keycloak token smaller

  • Turn off Full scope allowed on the client’s dedicated scope, and map only the roles the client needs.
  • Remove client scopes the client does not use, or move them from default to optional so they apply only when requested.
  • On mappers, turn off “Add to access token” for claims that only the client app needs in the ID token or userinfo.
  • Use the group membership mapper without full paths if names are unique.
  • Consider lightweight access tokens, available in recent Keycloak versions as a client setting, which leave most claims out; resource servers then read the full claims through introspection.

After each change, get a new token and measure again. The admin console can generate an example token for a user under the client’s Client scopes, Evaluate tab.

Use cases

Users who get “400 Bad Request” or “431”

If only some users see these errors, measure their tokens. Large group or role memberships are the usual cause.

Storing tokens in cookies

Before moving tokens into cookies, measure the largest one. If it does not fit in 4096 bytes with the cookie attributes, it needs trimming or a server-side session instead.

Choosing a signature algorithm

Switching from RS256 with a 4096-bit key to ES256 removes several hundred characters from every token.

A worked example

The sample token on this page, made up for the realm acme, is about 1.4 KB. It holds four realm roles and two clients’ roles. Here is what happens as a realm grows.

  • Each extra realm role adds its name plus a few characters of JSON, times about 4/3 after encoding.
  • Each client in resource_access adds its id, the roles key and its role names.
  • A group membership mapper with full paths adds every path, such as /departments/sales/emea.

A user with roles on many clients and dozens of groups can push a token past 4 KB without any single claim looking large. The largest-claims table shows where the bytes go, so you can fix the biggest contributor first.

Header limits along the way

A request passes several layers before it reaches your API, and each can have its own limit.

  1. The browser, which drops cookies larger than it allows.
  2. A CDN or load balancer, with its own header size limit.
  3. A reverse proxy such as nginx or Apache in front of the app.
  4. The application server or runtime, such as Tomcat or Node.js.

The smallest limit along the path is the one that counts. When you raise a limit, check every layer, and check the error each layer returns so you can tell which one rejected the request.

Choosing what to keep in the token

A useful test for each claim: does every API that receives this token need it on every request? Identity (sub), audience, scopes and the roles the API checks pass the test. Display names, addresses and long group lists usually do not. Move them to the ID token, the userinfo endpoint, or a lookup in your own database.

Limits of this calculator

The limits table lists defaults. Your proxy, load balancer or framework may be configured differently, and several layers may each apply their own limit. When in doubt, test with a large token through your real stack.

Claim sizes are estimated from their JSON and the Base64url growth; the exact share can differ by a few bytes.

Best practices

  • Keep access tokens about authorization: identity, audience, scopes and the roles the API needs.
  • Put profile data in the ID token or userinfo, not the access token.
  • Measure tokens for your heaviest users, not your test user.
  • Raise server header limits only after trimming what you can.
Questions

Frequently asked questions

What is the maximum size of a JWT?

The JWT standards set no limit. The limits come from where you carry the token: about 4 KB in a cookie, and 8 KB to 16 KB for request headers in common servers by default.

Why is the token bigger than the JSON?

Base64url turns every 3 bytes into 4 characters, so the header and payload grow by about a third. The signature adds from 43 characters for HS256 to 342 for RS256 with a 2048-bit key.

Why do some users get “431 Request Header Fields Too Large”?

Their requests carry more header data than the server allows, often because their tokens list many roles or groups. Measure their token, then trim the claims or raise the limit.

How do I make Keycloak tokens smaller?

Turn off Full scope allowed and map only needed roles, remove unused client scopes, and stop adding claims to the access token that only the client app needs.

Does a smaller token improve performance?

Every request carries the token, so a smaller one saves bandwidth and parsing on each call. The bigger benefit is staying clear of header and cookie limits.

Can I split a large token across several cookies?

Some frameworks do this, but it adds complexity and still hits total header limits. Trimming the token or keeping it server-side is usually better.

Is my token sent anywhere?

No. It is measured in your browser.

Does the size of the signature depend on the key size?

For RSA, yes: the signature is as long as the modulus, 256 bytes for 2048 bits and 512 bytes for 4096 bits. For HMAC and ECDSA it depends only on the algorithm.

Should I put tokens in cookies or in the Authorization header?

Both work. Cookies have the tighter size limit and need protection against cross-site requests; headers need the token stored where the client can read it. Measure your largest token either way.

Why is a 4 KB token a problem if the header limit is 8 KB?

In a cookie, about 4 KB is the limit for one cookie. In a header, the token shares space with cookies and other headers, and several layers may each apply their own limit.

Rather not run Keycloak yourself?

We run it for you on a cluster of your own, with backups, upgrades and written support. Starter and Premium begin with a 7-day trial.