Guide
How URL encoding (percent-encoding) works
By Logappradeep · ServiceNow developer
URLs can contain only a limited set of ASCII characters, and several of those have structural meaning. Percent-encoding, defined in RFC 3986, lets you include any other character, or a structural character used as plain data, by replacing it with % followed by two hexadecimal digits for each byte. A space becomes %20, so hello world becomes hello%20world.
Which characters need encoding
- Unreserved characters never need encoding: letters, digits, and
-._~. - Reserved characters such as
:/?#[]@!$&'()*+,;=delimit parts of a URL. They must be encoded when they appear inside a value. - Everything else, including spaces, quotes, and all non-ASCII characters, must be encoded. Non-ASCII text is first converted to UTF-8 bytes, so
cafébecomescaf%C3%A9.
Component mode versus full-URL mode
The tool offers two modes that mirror JavaScript's two built-in functions:
- Component mode (
encodeURIComponent) encodes reserved characters too. Use it for a single query parameter value, path segment, or fragment. The valuea&b=cbecomesa%26b%3Dc, so it cannot be mistaken for a second parameter. - Full-URL mode (
encodeURI) leaves the URL's structure intact, keeping:,/,?,&,=, and#, and encodes only characters that are illegal anywhere, like spaces and non-ASCII letters. Use it to clean up a complete URL that someone typed with spaces in it.
Choosing the wrong mode is a classic bug: full-URL encoding a parameter value lets an embedded & split it in two, while component-encoding an entire URL turns https:// into https%3A%2F%2F.
Gotchas developers actually hit
- Plus versus %20. HTML form submissions (
application/x-www-form-urlencoded) encode spaces as+. RFC 3986 percent-decoding does not treat+as a space, so a decoded form value may keep literal plus signs. Turn on Treat + as space when decoding form data; a real plus sign in form data arrives as%2B. - Double encoding. Encoding an already encoded string turns
%20into%2520, because the percent sign itself is encoded as%25. If you see%25in a URL, something probably encoded twice. - Malformed sequences. A lone
%or an invalid UTF-8 byte sequence such as%E9on its own cannot be decoded and produces an error. - Not every character is encoded. Component mode leaves
!'()*unchanged, which some strict OAuth signature schemes require you to encode manually.
Common uses include building query strings and redirect URLs, encoding OAuth redirect_uri values, reading encoded URLs from server logs, and preparing mailto: links. Everything runs locally in your browser as you type.