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
| Group | Characters | Rule |
|---|---|---|
| Unreserved | A–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 else | Spaces, %, quotes, non-ASCII | Always 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.
| Mode | Same as | Leaves alone | Use it for |
|---|---|---|---|
| A parameter value | encodeURIComponent, plus ! ' ( ) * | Only unreserved characters | A single query value or path segment |
| A whole URL | encodeURI | Reserved characters such as / ? & = : # | Cleaning up spaces and non-ASCII in a URL you already built |
| Form data | application/x-www-form-urlencoded | Unreserved characters; space becomes + | Request bodies such as OAuth token requests |
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.
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%2FcallbackKeycloak 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
- To read a URL, choose Decode and paste it. A sample authorization URL is filled in.
- Read the decoded text and the list of query parameters.
- To build a value, choose Encode, pick "A parameter value", and paste the value alone.
- Paste the encoded value into your URL after the
=of its parameter.
Common mistakes
- Double encoding: encoding a value that was already encoded, so
%20becomes%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
encodeURIfor 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_uriagainst 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.
// 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.