Skip to content

URL encoder and decoder

Percent-encode text for a URL parameter, or decode an encoded URL and read its query parameters.

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

Input

A sample authorization URL for auth.example.com is filled in. Paste your own.

Output

Decoded
https://auth.example.com/realms/acme/protocol/openid-connect/auth?client_id=web-app&response_type=code&scope=openid profile&redirect_uri=https://app.example.com/callback?next=/reports

Query parameters

client_id
web-app
response_type
code
scope
openid profile
redirect_uri
https://app.example.com/callback?next=/reports
A redirect_uri inside another URL must be encoded as a parameter value, so its own ? and & do not end up as parameters of the outer URL.

How to use it

  1. Choose Decode or Encode.
  2. When encoding, choose a parameter value, a whole URL or form data.
  3. Paste the text.
  4. Copy the result, and read the decoded query parameters of a full URL.

What to know

Percent-encoding writes characters that have a meaning in URLs, such as ? & = and /, as % and two hex digits. A value placed inside a URL must be encoded so these characters stay part of the value.

A redirect_uri inside an OAuth authorization URL is the classic case: if its own ? and & are not encoded, they become parameters of the outer URL.

Keycloak compares the decoded redirect_uri with the client’s valid redirect URIs. Decoding the URL here shows the exact value it will compare.

What URL encoding is

URLs use certain characters to mark their structure: / separates path segments, ? starts the query, & separates parameters, = joins a name to its value and # starts the fragment. When a value contains one of those characters, it has to be written differently, or it will be read as structure.

Percent-encoding, defined in RFC 3986, writes a byte as % followed by two hex digits. A space becomes %20, a slash %2F, an ampersand %26. Characters outside ASCII are first turned into UTF-8 bytes, then each byte is percent-encoded, so é becomes %C3%A9.

Decoding reverses it. This tool does both, in the ways browsers and servers actually need.

Reserved and unreserved characters

GroupCharactersRule
UnreservedA–Z a–z 0–9 - . _ ~Never need encoding
Reserved: general delimiters: / ? # [ ] @Encode when inside a value
Reserved: sub-delimiters! $ & ' ( ) * + , ; =Encode when inside a value
Everything elseSpaces, %, quotes, non-ASCIIAlways encode

The rule of thumb: when you build a URL, encode each value on its own, then put the encoded values into the URL’s structure. Never encode a whole finished URL as one value unless it is itself going inside another URL.

The three ways to encode

This tool offers three encodings because there are three different jobs.

ModeSame asLeaves aloneUse it for
A parameter valueencodeURIComponent, plus ! ' ( ) *Only unreserved charactersA single query value or path segment
A whole URLencodeURIReserved characters such as / ? & = : #Cleaning up spaces and non-ASCII in a URL you already built
Form dataapplication/x-www-form-urlencodedUnreserved characters; space becomes +Request bodies such as OAuth token requests
The same text, encoded two ways
value:               https://app.example.com/cb?x=1&y=2
as a parameter value: https%3A%2F%2Fapp.example.com%2Fcb%3Fx%3D1%26y%3D2
as a whole URL:       https://app.example.com/cb?x=1&y=2   (unchanged)

Space: %20 or +

In URLs generally, a space is %20. Only in form data (application/x-www-form-urlencoded), the format of HTML form submissions and OAuth token request bodies, does + mean a space. A literal plus sign in form data must be written %2B. When decoding, choose whether + means a space based on where the text came from.

URL encoding in OAuth and OpenID Connect

Identity protocols move a lot of data through URLs, and encoding mistakes are a frequent source of errors.

redirect_uri inside the authorization URL

The authorization request is a URL whose parameters include redirect_uri, itself a URL. It must be encoded as a parameter value. If it is not, its own ? and & break the outer URL, and its query parameters become parameters of the authorization request.

An authorization URL with sample values (line breaks added for reading)
https://auth.example.com/realms/acme/protocol/openid-connect/auth
  ?client_id=web-app
  &response_type=code
  &scope=openid%20profile
  &redirect_uri=https%3A%2F%2Fapp.example.com%2Fcallback

Keycloak compares the decoded redirect_uri with the client’s valid redirect URIs. Decoding the URL here shows exactly what it compares, which makes "invalid redirect_uri" errors much quicker to explain.

Scopes

Scopes are separated by spaces, so openid profile email is sent as openid%20profile%20email in a URL, or openid+profile+email in a form body. Both decode to the same value.

Token requests

The token endpoint takes form data. Values such as the authorization code, the redirect_uri and the PKCE code_verifier are form-encoded in the body.

Client credentials in a Basic header

RFC 6749 says the client id and secret are form-encoded before they are joined with a colon and Base64-encoded into the Basic Authorization header. A secret containing +, % or : that skips this step fails to authenticate in strict servers. The client auth header builder applies it for you.

What this tool does and does not do

  • It encodes text as a parameter value, a whole URL or form data.
  • It decodes percent-encoding, optionally reading + as a space.
  • When the text is a full URL, it lists the query parameters, decoded.
  • Switching between encode and decode carries the result across, for quick round trips.
  • It explains malformed input, such as a % not followed by two hex digits, instead of failing silently.
  • It does not fetch URLs or follow redirects. Everything happens in your browser.

How to use it

  1. To read a URL, choose Decode and paste it. A sample authorization URL is filled in.
  2. Read the decoded text and the list of query parameters.
  3. To build a value, choose Encode, pick "A parameter value", and paste the value alone.
  4. Paste the encoded value into your URL after the = of its parameter.

Common mistakes

  • Double encoding: encoding a value that was already encoded, so %20 becomes %2520. Decode once and see whether more % sequences remain.
  • Not encoding at all: building a URL with string concatenation and a raw value that contains & or #.
  • Using encodeURI for a parameter value. It leaves &, = and ? alone, which is exactly what a value must not contain raw.
  • Treating + as a space in a path or in a non-form query, or the reverse.
  • Encoding with something other than UTF-8, so non-ASCII characters decode as the wrong text.

In code, prefer a URL builder over string concatenation: URLSearchParams in JavaScript, urllib.parse.urlencode in Python. They encode each value correctly.

Security notes

  • URLs end up in logs, browser history and Referer headers. Never put secrets, passwords or tokens in a query string when a request body or header can carry them.
  • Decode once before validating. Attackers use double encoding to slip ../ or <script> past a check that looks only at the encoded form.
  • Validate a decoded redirect_uri against an exact allow list. Keycloak does this with the client’s valid redirect URIs; keep those as specific as possible and avoid broad wildcards.

Building URLs safely in code

Hand-built URLs are where encoding bugs come from. Standard libraries encode each part correctly if you give them the parts separately.

Letting the standard library encode (sample values)
// JavaScript: URL and URLSearchParams encode each value
const url = new URL('https://auth.example.com/realms/acme/protocol/openid-connect/auth');
url.searchParams.set('client_id', 'web-app');
url.searchParams.set('redirect_uri', 'https://app.example.com/callback?next=/reports');
url.searchParams.set('scope', 'openid profile');
url.toString();

# Python: urlencode does the same for a query string
from urllib.parse import urlencode
urlencode({'scope': 'openid profile', 'redirect_uri': 'https://app.example.com/cb'})

Note that URLSearchParams writes spaces as +, the form-encoding convention. Servers that follow the form-encoding rules for query strings, as OAuth servers do, read it as a space.

Best practices

  • Encode each value once, at the moment you put it into a URL.
  • Use a URL builder rather than string concatenation.
  • Decode once, then validate the decoded value.
  • Keep secrets out of URLs; use headers or request bodies.
  • Register exact redirect URIs with your identity provider, so encoding variations cannot slip past a pattern.
Questions

Frequently asked questions

What is the difference between encodeURI and encodeURIComponent?

encodeURI encodes a whole URL and keeps the characters that give it structure, such as / ? & = and #. encodeURIComponent encodes those too, which is what a single parameter value needs.

Should a space be %20 or + in a URL?

%20 works everywhere. A + means a space only in form-encoded data, such as HTML form posts and OAuth token request bodies. In a path, + is a literal plus.

What is double URL encoding?

Encoding text that is already encoded, so % becomes %25 and %20 becomes %2520. It usually means a value passed through two encoding steps. Decode until no % sequences remain to see the original.

How do I encode a redirect_uri?

Encode it as a parameter value, with encodeURIComponent or this tool’s parameter mode. That turns its : / ? & and = into percent-escapes so it stays one value inside the authorization URL.

Why do I get "URI malformed" when decoding?

There is a % that is not followed by two hex digits, or the decoded bytes are not valid UTF-8. Look for a stray % or text cut off in the middle of an escape.

Which characters never need URL encoding?

The unreserved characters: letters, digits, hyphen, period, underscore and tilde. Everything else should be encoded when it appears inside a value.

How are non-English characters encoded in URLs?

They are converted to UTF-8 bytes, and each byte is percent-encoded. For example, é is the two bytes C3 A9, written %C3%A9.

Is URL encoding the same as Base64 encoding?

No. URL encoding replaces only the characters that are unsafe in a URL and leaves the rest readable. Base64 turns any bytes into a new string of letters, digits and two symbols. Base64url exists so Base64 output can itself sit in a URL.

Why does my redirect_uri not match in Keycloak?

Keycloak compares the decoded redirect_uri with the client’s valid redirect URIs. Decode the authorization URL here to see the exact value, then check scheme, host, port, path and trailing slash against the registered entries.

Do I need to encode the path of a URL too?

Yes, each path segment that contains reserved or non-ASCII characters must be encoded, but the slashes between segments must not be. Encode each segment on its own, the same way as a parameter value.

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.