{ } DevToolCore Free Online Developer Tools Tools Blog
Development

URL Encoding Explained: Why %20 Exists and When to Use It

2026-07-20 · 4 min read

URLs can only contain a limited set of characters: letters, digits, and a handful of special characters like -, _, ., ~. Everything else — spaces, Chinese characters, emoji, reserved symbols like & and = — must be percent-encoded before it goes into a URL.

How Percent-Encoding Works

Each "unsafe" character is replaced by % followed by its two-digit hexadecimal byte value in UTF-8. A space (ASCII 32) becomes %20. An ampersand (ASCII 38) becomes %26. A Chinese character like 中 (UTF-8 bytes E4 B8 AD) becomes %E4%B8%AD.

Reserved vs Unreserved Characters

Some characters have special meaning in URLs and must be encoded when they appear as data rather than as syntax. For example, ? starts the query string, & separates parameters, and # starts the fragment. If your search query contains the word "rock&roll", the & must become %26, otherwise the browser thinks a new parameter is starting.

Common Gotchas

  • Double encoding — Encoding an already-encoded string turns %20 into %2520. This happens when a framework encodes automatically and you encode manually on top.
  • Plus sign ambiguity — In query strings, + means space (a legacy from HTML forms). In the path component, + is a literal plus. This inconsistency causes bugs.
  • Encoding the whole URL — Only encode the parts that need it (path segments, query values). Do not encode the ://, /, or ? that form the URL structure.

encodeURI vs encodeURIComponent

In JavaScript, encodeURI() encodes a full URL but leaves structural characters alone. encodeURIComponent() encodes everything, including / and ? — use it for individual parameter values. Mixing them up is the most common URL encoding bug.

Try It

Use the URL Encoder to encode or decode any string. Paste a URL with Chinese characters or special symbols and see the percent-encoded result instantly.