Skip to content
ToolkitHub

URL Encode/Decode

URL encoder and decoder

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é becomes caf%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 value a&b=c becomes a%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 %20 into %2520, because the percent sign itself is encoded as %25. If you see %25 in a URL, something probably encoded twice.
  • Malformed sequences. A lone % or an invalid UTF-8 byte sequence such as %E9 on 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.

Frequently asked questions

Should a space be %20 or +?

In paths and in RFC 3986 encoding, a space is %20. The + form comes from HTML form encoding and is only interpreted as a space by servers that expect form data. Enable Treat + as space when decoding such values.

What is the difference between component and full-URL mode?

Component mode encodes reserved characters such as /, ?, &, and = so a value cannot break the URL structure. Full-URL mode keeps them so a complete URL stays usable.

Why do I see %2520 in my URL?

The string was encoded twice. %20 was encoded again, and its % became %25. Decode once and encode only once at the point where the URL is built.

Why does decoding fail with an error?

The input contains a % not followed by two hex digits, or byte sequences that are not valid UTF-8. Check for stray percent signs in the text.