From %20 to RFC 3986 โ everything developers need to know about URL encoding in 2026
If you've ever seen %20 in a URL and wondered what it means โ or worse, had a URL break because of a special character โ this guide is for you. URL encoding (also called percent encoding) is one of those fundamental web technologies that every developer encounters, but few fully understand.
By the end of this guide, you'll know exactly how URL encoding works, when to use encodeURIComponent() vs encodeURI(), how to avoid the top 5 URL encoding bugs, and how to handle encoding in JavaScript, Python, PHP, Java, and Go.
%20 is the URL-encoded representation of a space character. In URL encoding, spaces are not allowed, so they're replaced with %20 (the hexadecimal value of space in ASCII is 20). Some older systems also use + for spaces in query strings, but %20 is the standard.
URL encoding (officially called percent-encoding per RFC 3986) is a mechanism for converting characters into a format that can be safely transmitted in URLs. Since URLs can only contain a limited set of ASCII characters, anything outside that set must be "encoded" using a % followed by two hexadecimal digits.
Example conversions:
| Raw Character | Encoded | Why |
|---|---|---|
| Space | %20 | Not allowed in URLs |
& | %26 | Reserved โ query parameter separator |
= | %3D | Reserved โ key-value separator |
# | %23 | Reserved โ fragment identifier |
@ | %40 | Reserved โ auth info |
รฉ | %C3%A9 | Non-ASCII (UTF-8 bytes) |
๐ | %F0%9F%9A%80 | Emoji (UTF-8 bytes) |
URL encoding isn't just a theoretical concept โ it directly affects your application's reliability:
"rock & roll" breaks the URL without encoding the & because the browser interprets & as a parameter separator.The algorithm is straightforward:
A-Z a-z 0-9 - _ . ~)%XX where XX is the two-digit hexadecimal valueExample: Encoding "cafรฉ"
| Category | Characters | Rule |
|---|---|---|
| Unreserved | A-Z a-z 0-9 - _ . ~ | Never need encoding |
| Reserved | : / ? # [ ] @ ! $ & ' ( ) * + , ; = | Encode when used as data, not as delimiters |
| Other | Spaces, non-ASCII, control characters | Always encode |
| Raw | Encoded | Notes |
|---|---|---|
| Space | %20 | Most commonly encountered encoding |
| ! | %21 | |
| " | %22 | |
| # | %23 | Fragment identifier โ always encode in query params |
| % | %25 | Must encode % โ otherwise interpreted as encoding start |
| & | %26 | Parameter separator โ one of the most common bugs |
| ' | %27 | |
| ( ) | %28 %29 | |
| + | %2B | Literal plus sign (not a space!) |
| , | %2C | |
| / | %2F | Path separator โ careful encoding this |
| : | %3A | |
| ; | %3B | |
| < > | %3C %3E | |
| = | %3D | Key-value separator |
| ? | %3F | Query string start |
| @ | %40 | |
| [ \ ] | %5B %5C %5D | |
| { | } | %7B %7C %7D |
The most important ones to remember: Space โ %20, & โ %26, = โ %3D, # โ %23, % โ %25. If you encode nothing else, encode &, =, and # in query parameters.
One of the most common points of confusion: should a space be %20 or +?
| Context | Encoding | Why |
|---|---|---|
URL paths (/my file.txt) | %20 | + is a literal plus sign in paths |
Query strings (?q=hello world) | %20 or + | + comes from HTML form encoding (application/x-www-form-urlencoded) |
In URL paths, + is treated as a literal plus sign. So https://example.com/files/hello+world.txt refers to a file named hello+world.txt, NOT hello world.txt. For that, you'd use hello%20world.txt.
Best practice: Use %20 universally in modern applications. Only use + if you're specifically handling legacy HTML form submissions.
This is the most common URL encoding mistake in JavaScript. The two functions behave very differently:
| Function | Encodes | Best For |
|---|---|---|
encodeURI() | Everything except : // ? # & = + $ , / : @ | Complete URLs โ preserves structure |
encodeURIComponent() | Everything except A-Z a-z 0-9 - _ . ! ~ * ' ( ) | Parameter values & path segments โ encodes ALL special chars |
Fix: Always decode before re-encoding. Never encode an already-encoded string.
encodeURI() Instead of encodeURIComponent()This is the #1 JavaScript URL encoding mistake. encodeURI() does NOT encode &, =, or ?, which breaks query parameters.
Fix: Use encodeURIComponent() for parameter values โ always.
In URL paths, + is a literal plus sign โ NOT a space. This causes file-not-found errors.
Fix: Use %20 everywhere. Reserve + for legacy form data only.
Modern browsers display decoded characters in the address bar (you see cafรฉ not caf%C3%A9), but the actual HTTP request still uses percent encoding. Always encode in your code โ never assume the browser will handle it.
encodeURIComponent() for parameter values, never encodeURI().URLSearchParams (JavaScript) or equivalent in modern code for automatic encoding.%20 for spaces, not +, unless handling legacy form submissions.href attribute), apply both URL encoding (for URL data) and HTML encoding (for the attribute value).| Feature | URL Encoding | HTML Encoding |
|---|---|---|
| Purpose | Safe URLs | Safe HTML |
| Format | %XX (hex bytes) | &entity; or &#number; |
| Space | %20 | |
| & | %26 | & |
| < | %3C | < |
| Standard | RFC 3986 | HTML Spec |
Need to quickly encode or decode a URL? Use our free online tool โ no signup required, all processing happens in your browser.
๐ Free Online URL Encoder / Decoder
Encode and decode URLs instantly in your browser.
Try URL Encoder โIf you found this guide helpful, check out our other developer tutorials or use our free online text tools.