URL Encoding Guide: Complete Guide to Percent Encoding

From %20 to RFC 3986 โ€” everything developers need to know about URL encoding in 2026

๐Ÿ“… June 16, 2026 โฑ 10 min read ๐Ÿ“‚ Web Development

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.

๐ŸŽฏ Quick Answer โ€” What is %20?

%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.

๐Ÿ“‘ Table of Contents
  1. What is URL Encoding?
  2. Why URL Encoding Matters in 2026
  3. How Percent Encoding Works
  4. Common Character Encodings Reference
  5. %20 vs +: The Space Encoding Confusion
  6. JavaScript: encodeURI vs encodeURIComponent
  7. Language-Specific Examples
  8. Top 5 URL Encoding Bugs
  9. Best Practices
  10. Try Our URL Encoder Tool

What is URL Encoding?

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 CharacterEncodedWhy
Space%20Not allowed in URLs
&%26Reserved โ€” query parameter separator
=%3DReserved โ€” key-value separator
#%23Reserved โ€” fragment identifier
@%40Reserved โ€” auth info
รฉ%C3%A9Non-ASCII (UTF-8 bytes)
๐Ÿš€%F0%9F%9A%80Emoji (UTF-8 bytes)

Why URL Encoding Matters in 2026

URL encoding isn't just a theoretical concept โ€” it directly affects your application's reliability:

How Percent Encoding Works

The algorithm is straightforward:

  1. Check if the character needs encoding (anything outside A-Z a-z 0-9 - _ . ~)
  2. Convert the character to its UTF-8 byte sequence
  3. Express each byte as %XX where XX is the two-digit hexadecimal value

Example: Encoding "cafรฉ"

c โ†’ 63 (ASCII) โ†’ c (unreserved โ€” no encoding needed) a โ†’ 61 (ASCII) โ†’ a f โ†’ 66 (ASCII) โ†’ f รฉ โ†’ C3 A9 (UTF-8) โ†’ %C3%A9 โ†“ Result: caf%C3%A9

Character Categories (RFC 3986)

CategoryCharactersRule
UnreservedA-Z a-z 0-9 - _ . ~Never need encoding
Reserved: / ? # [ ] @ ! $ & ' ( ) * + , ; =Encode when used as data, not as delimiters
OtherSpaces, non-ASCII, control charactersAlways encode

Common Character Encodings Reference

RawEncodedNotes
Space%20Most commonly encountered encoding
!%21
"%22
#%23Fragment identifier โ€” always encode in query params
%%25Must encode % โ€” otherwise interpreted as encoding start
&%26Parameter separator โ€” one of the most common bugs
'%27
( )%28 %29
+%2BLiteral plus sign (not a space!)
,%2C
/%2FPath separator โ€” careful encoding this
:%3A
;%3B
< >%3C %3E
=%3DKey-value separator
?%3FQuery string start
@%40
[ \ ]%5B %5C %5D
{ | }%7B %7C %7D
๐Ÿ’ก Quick Reference

The most important ones to remember: Space โ†’ %20, & โ†’ %26, = โ†’ %3D, # โ†’ %23, % โ†’ %25. If you encode nothing else, encode &, =, and # in query parameters.

%20 vs +: The Space Encoding Confusion

One of the most common points of confusion: should a space be %20 or +?

ContextEncodingWhy
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)
โš ๏ธ Watch Out

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.

JavaScript: encodeURI vs encodeURIComponent

This is the most common URL encoding mistake in JavaScript. The two functions behave very differently:

FunctionEncodesBest 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
// CORRECT for parameter values โ€” encodes EVERYTHING unsafe encodeURIComponent("rock & roll") // โ†’ "rock%20%26%20roll" // CORRECT for a complete URL โ€” preserves structural chars encodeURI("https://example.com/path?q=hello world") // โ†’ "https://example.com/path?q=hello%20world" // WRONG โ€” using encodeURI for a parameter value encodeURI("key=value&foo=bar") // โ†’ "key=value&foo=bar" โ† unchanged! Breaks URL! // RIGHT encodeURIComponent("key=value&foo=bar") // โ†’ "key%3Dvalue%26foo%3Dbar"
๐Ÿ’ก In 2026, the modern approach is URLSearchParams
// Automatic encoding โ€” recommended for new code const params = new URLSearchParams({ email: "user@example.com", q: "hello world" }); const url = "https://api.example.com/search?" + params.toString(); // โ†’ "?email=user%40example.com&q=hello+world"

Language-Specific Examples

Python

from urllib.parse import quote, quote_plus, urlencode quote("my file.txt") # โ†’ "my%20file.txt" (paths) quote_plus("rock & roll") # โ†’ "rock+%26+roll" (query, spaces โ†’ +) urlencode({"q": "rock & roll", "page": "1"}) # โ†’ "q=rock+%26+roll&page=1"

PHP

urlencode("rock & roll"); // โ†’ "rock+%26+roll" rawurlencode("rock & roll"); // โ†’ "rock%20%26%20roll" (RFC 3986) http_build_query(["q" => "rock & roll"]); // โ†’ "q=rock+%26+roll"

Java

URLEncoder.encode(str, "UTF-8") // Spaces โ†’ + URLDecoder.decode(str, "UTF-8")

Go

url.QueryEscape(str) // Spaces โ†’ %20 url.QueryUnescape(str)

Top 5 URL Encoding Bugs (and How to Fix Them)

1. ๐Ÿ”ด Double Encoding

Original: hello world First encode: hello%20world Double encode: hello%2520world โ† BROKEN (%25 = %)

Fix: Always decode before re-encoding. Never encode an already-encoded string.

2. ๐Ÿ”ด Using 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.

3. ๐Ÿ”ด Not Encoding at All (Template Literal Injection)

// WRONG const url = `https://api.com/search?q=${userInput}`; // RIGHT const url = `https://api.com/search?q=${encodeURIComponent(userInput)}`;

4. ๐Ÿ”ด Confusing %20 and + in Paths

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.

5. ๐Ÿ”ด Forgetting Non-ASCII Characters

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.

Best Practices (2026)

  1. Always encode user input before inserting it into a URL โ€” never trust raw data.
  2. Use encodeURIComponent() for parameter values, never encodeURI().
  3. Use URLSearchParams (JavaScript) or equivalent in modern code for automatic encoding.
  4. Never double-encode โ€” track whether a string is already encoded.
  5. Use %20 for spaces, not +, unless handling legacy form submissions.
  6. Use UTF-8 consistently โ€” modern browsers and servers default to UTF-8, but legacy systems may not.
  7. When embedding a URL in HTML (e.g., href attribute), apply both URL encoding (for URL data) and HTML encoding (for the attribute value).
โš ๏ธ URL Encoding vs HTML Encoding โ€” Don't Confuse Them
FeatureURL EncodingHTML Encoding
PurposeSafe URLsSafe HTML
Format%XX (hex bytes)&entity; or &#number;
Space%20&nbsp;
&%26&amp;
<%3C&lt;
StandardRFC 3986HTML Spec

Try Our URL Encoder Tool

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.