URL Encoding Explained - Percent-Encoding, %20 vs + and Common Bugs

Learn what percent-encoding is, which characters must be escaped in a URL, when %20 or + means a space, and how to avoid double-encoding bugs in links.

Updated September 29, 2026 6 min read

Use the free URL Encode / DecodePercent-encode or decode URLs and query strings

A search link breaks because the product name contains an ampersand. A redirect sends visitors to a page that does not exist because the return URL was pasted into another URL without escaping. A report shows %2520 where there should be a space. These are all URL encoding problems, and they are easy to fix once you understand the rules.

This guide explains what percent-encoding is, which characters need it, the long-running confusion between %20 and +, the difference between JavaScript's encodeURI and encodeURIComponent, and how to encode or decode values quickly without writing code.

Why URLs need encoding

A URL is made of parts, and several characters act as separators between them:

https://shop.example.com/search/results?q=red%20shoes&page=2#reviews
scheme   host             path           query              fragment

/ separates path segments, ? starts the query string, & separates parameters, = separates a name from its value, and # starts the fragment. If one of those characters appears inside a value, the browser or server cannot tell whether it is data or structure. A search for Fish & Chips sent as ?q=Fish & Chips is read as a parameter q=Fish followed by an unnamed parameter Chips.

The standard for URLs (RFC 3986) therefore divides characters into groups:

  • Unreserved characters are always safe: A-Z a-z 0-9 - . _ ~.
  • Reserved characters have a structural meaning: : / ? # [ ] @ ! $ & ' ( ) * + , ; =.
  • Everything else, including spaces, quotes, and all non-ASCII letters, must be encoded.

How percent-encoding works

To encode a character, convert it to bytes using UTF-8, then write each byte as % followed by two hexadecimal digits. A space is byte 0x20, so it becomes %20. An ampersand is 0x26, so it becomes %26. Non-English text uses several bytes per character: é is two bytes in UTF-8, so café becomes caf%C3%A9.

Character Encoded
space %20
& %26
= %3D
/ %2F
? %3F
# %23
+ %2B
é %C3%A9

Decoding reverses the process: every %XX sequence becomes a byte, and the bytes are read back as UTF-8 text.

%20 or +? Both, depending on where

This is the most confusing part of URL encoding. In the path of a URL, a space is always %20, and a + is just a plus sign. In a query string produced by an HTML form (the application/x-www-form-urlencoded format), a space is written as +. Many server frameworks follow the form convention and turn + into a space when they read query parameters.

The practical consequences:

  • If you write a query value, %20 is always safe. Servers that expect form encoding also decode %20 as a space.
  • A literal plus sign in a value, such as a phone number +44 20 7946 0000 or C++, must be encoded as %2B, otherwise it may arrive as a space.
  • A generic URL decoder that does not know about form encoding will leave + as a plus. If you are decoding values copied from a form submission, replace + with a space first.

Encode or decode a value with our tool

The URL Encode / Decode tool uses the browser's component-level encoder, the right choice for query values and path segments. Everything runs locally.

  1. Open URL Encode / Decode and pick Encode or Decode.
  2. Paste the text into the Input box. To encode, paste the raw value (for example Q3 report & notes.pdf); to decode, paste the percent-encoded text.
  3. Click the Encode or Decode button. The result appears under Output, for example Q3%20report%20%26%20notes.pdf.
  4. Click Copy Result. The arrow button between the modes swaps the output back into the input, useful for confirming that decoding returns what you started with.

Because the tool encodes every reserved character, paste only the value you want to insert, not a whole URL. Encoding https://example.com/?a=1 produces https%3A%2F%2Fexample.com%2F%3Fa%3D1, which is exactly what you want when that URL is itself a parameter (a redirect= or url= value) but wrong if you meant to keep it as a working link. If decoding fails with Invalid input for decoding, the text contains a % that is not followed by two valid hex digits.

To take an existing URL apart into scheme, host, path and parameters, use the URL Parser; to read or edit many parameters at once, the Query String Parser is quicker.

encodeURI vs encodeURIComponent in JavaScript

JavaScript has two encoders, and choosing the wrong one is a classic bug.

encodeURIComponent("Q3 report & notes.pdf");
// "Q3%20report%20%26%20notes.pdf"

encodeURI("https://example.com/search?q=red shoes&page=2");
// "https://example.com/search?q=red%20shoes&page=2"
  • encodeURIComponent escapes everything except unreserved characters and ! ' ( ) *. Use it for a single value you are placing inside a URL.
  • encodeURI leaves : / ? & = # alone because it assumes you are passing a complete URL. It will not protect an & inside a value.

The safest approach in modern code is to let the platform build the query string:

const url = new URL("https://example.com/search");
url.searchParams.set("q", "red shoes & bags");
url.toString(); // "https://example.com/search?q=red+shoes+%26+bags"

Note that URLSearchParams uses the form convention, so spaces become +.

In other languages the equivalents are urllib.parse.quote and quote_plus in Python, rawurlencode and urlencode in PHP, and URLEncoder.encode in Java (which follows the form convention). In a spreadsheet, Excel's ENCODEURL function encodes a cell value.

Common problems and how to fix them

Double encoding

If a value is encoded twice, % itself gets encoded as %25, so a space turns into %2520. It usually happens when one layer of code encodes a value and a library encodes it again. Decode once and look at the result: if it still contains %20, it was double-encoded. Fix it at the source by encoding exactly once, as late as possible.

Campaign parameters with spaces or ampersands in the campaign name often break analytics. Build the links with a tool that encodes each value for you, such as the UTM Builder.

Encoding a URL inside HTML

Percent-encoding and HTML escaping are different layers. In an HTML attribute, an & between parameters should be written as &. The HTML Entity Encoder handles that layer; the URL encoder handles the values inside the link.

Frequently asked questions

What does %20 mean in a URL?

It is an encoded space. 20 is the hexadecimal code of the space character, and % marks the start of an encoded byte.

Should I encode the whole URL or only parts?

Only the parts you insert: individual path segments and parameter values. Encoding an entire URL with a component encoder escapes the slashes and colon, and the result is no longer a working link.

The value was encoded twice. The % from the first %20 was encoded again as %25. Remove one of the encoding steps.

Are URLs case sensitive when encoded?

The hex digits are not: %2f and %2F mean the same byte, though uppercase is recommended. The rest of the path can be case sensitive depending on the server.

Is URL encoding the same as Base64?

No. URL encoding keeps safe characters readable and escapes only the rest. Base64 rewrites all data into a 64-character alphabet and is used for binary content.

Try it now: URL Encode / Decode

Loading tool…