URL Encoding Explained — What is %20 and Why URLs Look Like That
URL encoding (percent encoding) replaces characters that are not allowed in URLs with a % followed by two hex digits. Learn why it exists, which characters need encoding, and how to encode and decode URLs correctly.
Why %20 exists
A URL can only contain a limited set of characters defined by RFC 3986. Spaces, accented letters, and punctuation like &, =, and # are not allowed — or they carry special meaning that would confuse the parser.
URL encoding (also called percent encoding) solves this by replacing each forbidden character with a % followed by its two-digit hexadecimal ASCII code. A space is ASCII 32, which is 20 in hex — hence %20.
Safe vs unsafe characters
These characters are always safe in a URL and never need encoding:
Everything else should be percent-encoded when used as data — especially when passing values in a query string.
Common encoded characters
| Character | Encoded | Notes |
|---|---|---|
| %20 | Space — most common one you will see | |
| ! | %21 | Exclamation mark |
| # | %23 | Hash — reserved as fragment identifier |
| $ | %24 | Dollar sign |
| & | %26 | Ampersand — reserved as query param separator |
| ' | %27 | Single quote / apostrophe |
| ( | %28 | Open parenthesis |
| ) | %29 | Close parenthesis |
| + | %2B | Plus sign (sometimes used for space in query strings) |
| , | %2C | Comma |
| / | %2F | Forward slash — reserved as path separator |
| : | %3A | Colon — reserved in scheme (https:) |
| = | %3D | Equals — reserved as key=value separator |
| ? | %3F | Question mark — reserved as query start |
| @ | %40 | At sign — reserved in authority section |
| [ | %5B | Open bracket |
| ] | %5D | Close bracket |
encodeURI vs encodeURIComponent
JavaScript has two built-in encoding functions — and choosing the wrong one is a common mistake:
encodeURI(url)Encodes a complete URL. Leaves reserved characters like /, ?, &, =, and # untouched because they are structural parts of the URL.
encodeURIComponent(value)Encodes a value to embed inside a URL — a query string parameter, a path segment. Encodes reserved characters too, including & and =. Use this when encoding user input going into a URL.
+ vs %20 in query strings
In the query string portion of a URL, a + is traditionally interpreted as a space by HTML form encoding (application/x-www-form-urlencoded). This is why Google search URLs use q=hello+world. %20 is the stricter, unambiguous form and is preferred in modern APIs. When in doubt, use encodeURIComponent which always produces %20.
Encode and decode URLs instantly
Paste any URL or string and get the encoded or decoded result
Open URL Encoder →