URLs can only contain a small subset of ASCII characters. Spaces, ampersands, question marks, non-English letters, and many symbols must be percent-encoded — written as % followed by two uppercase hexadecimal digits — or they split query parameters, truncate links, and confuse servers and proxies. This guide explains RFC 3986 percent-encoding, the critical difference between encoding a whole URL and a single value, how query strings encode arrays and nested objects, why double encoding happens, and how HTML entities serve a completely different security purpose.

How percent-encoding works under the hood

Percent-encoding operates on UTF-8 bytes, not raw characters. Any character outside the unreserved set is first encoded to one or more UTF-8 bytes, and each byte becomes %XX:

CharacterMeaning / noteUTF-8 bytesPercent-encoded
SpaceBreaks URLs in plain text & HTTP request lines20%20 (or + in form queries)
&Separates query parameters26%26
=Separates parameter key from value3D%3D
/Separates path segments2F%2F
+Read as space by form decoders2B%2B
#Starts client-side fragment (never sent to server)23%23
é2-byte UTF-8 accented Latin letterC3 A9%C3%A9
₹3-byte UTF-8 Indian Rupee signE2 82 B9%E2%82%B9
🚀4-byte UTF-8 emojiF0 9F 9A 80%F0%9F%9A%80

RFC 3986 defines exactly 66 unreserved characters that never need encoding anywhere in a URL: ASCII letters A–Z and a–z, digits 0–9, and the four symbols - _ . ~. Every reserved character (: / ? # [ ] @ ! $ & ' ( ) * + , ; =) carries structural meaning — it must stay unencoded when acting as a delimiter and must be encoded when acting as data inside a value.

Whole URL vs single component: the #1 encoding bug

Most URL bugs come from calling the wrong function. In JavaScript (and similar helpers in Python, Go, and Java):

  • encodeURI() assumes you passed a complete URL and intentionally leaves structural delimiters (: / ? # & = +) unencoded.
  • encodeURIComponent() assumes you passed a single parameter value or path segment and encodes every reserved character so it cannot alter the surrounding URL structure.
const q = "Ali & Sons / ₹500 + tax";

// WRONG: & starts a fake parameter named " Sons / ₹500 "
"https://shop.example/search?q=" + encodeURI(q)
// → https://shop.example/search?q=Ali%20&%20Sons%20/%20%E2%82%B9500%20+%20tax

// RIGHT: encode the value with encodeURIComponent or URLSearchParams
"https://shop.example/search?q=" + encodeURIComponent(q)
// → https://shop.example/search?q=Ali%20%26%20Sons%20%2F%20%E2%82%B9500%20%2B%20tax

In production code, avoid manual string concatenation altogether — let the standard library build the URL for you:

// JavaScript / Node.js
const url = new URL("https://shop.example/search");
url.searchParams.set("q", "Ali & Sons / ₹500 + tax");

// Python
from urllib.parse import urlencode
"https://shop.example/search?" + urlencode({"q": "Ali & Sons / ₹500 + tax"})

To inspect or test encoded strings interactively, SnipFerry’s URL Encoder / Decoder supports both full-URL and component modes, plus + space handling, completely offline in your browser.

The plus sign (+) vs %20 trap

Why do some URLs encode spaces as + while others use %20? Two different standards collided historically:

  • RFC 3986 (URLs and paths) always encodes spaces as %20. In a URL path like /files/my+file.pdf, + is a literal plus sign, not a space.
  • HTML forms (application/x-www-form-urlencoded) encode spaces as + inside query strings and POST bodies. JavaScript’s URLSearchParams follows this convention.

The bug strikes with phone numbers (+919876543210), timestamps with timezone offsets (2026-10-29T09:00:00+05:30), and Base64 tokens in query strings: if the caller forgets to encode + as %2B, the server silently turns every + into a space, breaking verification and parsing. Always encode literal plus signs as %2B, and use Base64URL (which replaces + and /) for tokens in URLs.

Query strings: arrays, nested objects, and framework styles

After the ?, query parameters are key=value pairs joined by &. RFC 3986 never defined how to represent arrays or nested objects, so backend ecosystems invented four competing conventions:

tags[]=js&tags[]=sql            PHP, Ruby on Rails, Express (qs)
tags=js&tags=sql                Node URLSearchParams, Go, Django, FastAPI
tags[0]=js&tags[1]=sql          Indexed arrays (qs, Laravel)
tags=js,sql                     Comma-separated (OpenAPI simple style)
filter[price][max]=500          Nested objects (PHP, qs library)

When debugging third-party webhooks, OAuth callbacks, or UTM-tagged marketing links, paste the entire URL into Query String to JSON to unpack every parameter into structured JSON — or build properly encoded parameters in your target array style with JSON to Query String.

Spotting and fixing double encoding

Double encoding happens when an already-encoded string passes through a second encoder — turning % into %25:

Original:        "hello world"
Encoded once:    "hello%20world"
Encoded twice:   "hello%2520world"    ← %25 is the red flag

Common culprits: passing an already-encoded redirect URL into URLSearchParams.set(), proxy rewrite rules that re-encode paths without the noescape flag, or encoding an entire pre-built query string before appending it. When debugging a broken link, decode once in the URL Decoder: if readable text suddenly shows %20 or %2F, you have a double-encoding bug in your pipeline.

URL fragments (#) never reach your server

Everything from # onward (for example #section-2) is a client-side fragment handled solely by the browser. Browsers never send the fragment in HTTP requests. If a user passes a product code like SKU#42 or a hex colour #0b8457 inside a query parameter without encoding # as %23, the server receives SKU and silently loses everything after the hash.

HTML entities are a different layer

Percent-encoding protects URL syntax. HTML entities protect HTML markup from breaking or executing injected scripts (XSS): < becomes &lt;, > becomes &gt;, & becomes &amp;, " becomes &quot;, and ' becomes &#39;. Use the HTML Entity Encoder / Decoder to inspect entities, and in application code rely on your template engine’s automatic escaping or DOM textContent.

When a URL appears inside an HTML attribute, both layers apply in order: first percent-encode the query parameter values, then HTML-escape the full attribute value so & between parameters becomes &amp; in HTML source (<a href="/search?a=1&amp;b=2">). To understand the UTF-8 bytes underneath percent-encoding and Base64, read Character Encoding Explained and Base64 Explained.