Toolvana
Developer Tools & Programming

What Is URL Encoding? A Complete Beginner’s Guide to Percent-Encoding

Why do spaces turn into %20 and ampersands break query parameters? Learn the mechanics of URL percent-encoding (RFC 3986) with practical developer examples.

Updated: 17 November, 2026•7 min read
What Is URL Encoding? A Complete Beginner’s Guide to Percent-Encoding

Introduction#

Have you ever clicked a link or submitted a search form and noticed that the URL turned into a bizarre string of percent signs and hexadecimal numbers?

text
https://example.com/search?q=shoes%20%26%20socks%21

What happened to the spaces, the ampersand (&), and the exclamation mark (!)?

This process is known as URL Encoding (officially termed Percent-Encoding in IETF RFC 3986). It is the mechanism that ensures web browsers and HTTP web servers agree unambiguously on where a URL path ends, where query parameters begin, and which characters represent raw textual data.

In this guide, we demystify how URL encoding functions, examine the difference between reserved and unreserved characters, and demonstrate how to handle encoding in modern JavaScript.

Why Do URLs Need Special Encoding?#

A Uniform Resource Identifier (URI) must use a strictly defined set of US-ASCII characters. Furthermore, certain characters have predefined structural meanings within a URL:

  • The question mark (?) separates the path from query parameters.
  • The ampersand (&) separates individual key-value pairs.
  • The equals sign (=) assigns a value to a parameter key.
  • The hash (#) marks the beginning of an internal document anchor.
  • If a user searches for the company "Barnes & Noble", submitting the raw string ?company=Barnes & Noble breaks the URL parser: the server interprets Barnes as the company name, and thinks Noble is a brand new parameter key without a value!

    To pass literal symbols safely, those characters must be percent-encoded.

    The Anatomy of Percent-Encoding#

    Percent-encoding replaces unsafe, non-ASCII, or reserved characters with a percent sign (%) followed by the two-digit hexadecimal representation of the character's UTF-8 byte value.

    Practical Conversion Example#

  • The space character has a decimal ASCII code of 32.
  • Converting decimal 32 to hexadecimal yields 20.
  • Therefore, a space becomes %20.
  • Common URL Encoding Reference Table#

    CharacterLiteral SymbolPercent-Encoded Hex CodeReason for Encoding
    Space %20 (or +)Invalid in raw URI paths
    Exclamation Mark!%21Sub-delimiter
    Double Quote"%22Unsafe delimiter
    Hash / Pound#%23Fragment identifier reserved
    Ampersand&%26Query parameter separator reserved
    Forward Slash/%2FPath segment separator reserved
    Colon:%3AScheme & port separator reserved
    Equals=%3DKey-value separator reserved
    Question Mark?%3FQuery string initiator reserved

    Difference Between %20 and '+' for Spaces#

    Developers frequently ask why spaces are sometimes encoded as %20 and other times as +:

  • %20 (Standard RFC 3986): The universal standard for all URI paths, filenames, and modern API query strings.
  • + (HTML Form Spec / application/x-www-form-urlencoded): A legacy convention used specifically when submitting standard HTML <form> POST bodies or GET query parameters.
  • encodeURI vs encodeURIComponent in JavaScript#

    JavaScript provides two native global encoding functions that serve completely different purposes:

    javascript
    const fullUrl = "https://example.com/search?q=fish & chips";
    
    // 1. encodeURI: Preserves URL structural characters (?, =, &, /)
    encodeURI(fullUrl);
    // Returns: "https://example.com/search?q=fish%20&%20chips" (ampersand NOT encoded!)
    
    // 2. encodeURIComponent: Encodes EVERYTHING (use for query parameter values)
    const queryParam = "fish & chips";
    const safeUrl = "https://example.com/search?q=" + encodeURIComponent(queryParam);
    // Returns: "https://example.com/search?q=fish%20%26%20chips" (ampersand safely encoded!)

    Helpful In-Browser Developer Utilities#

  • URL Encoder / Decoder – Encode and decode strings with instant toggle between standard and form encoding.
  • URL Parser – Inspect query string parameters and protocol structures.
  • Slug Generator – Generate SEO-clean, hyphenated slugs without awkward percent codes.
  • cURL Command Builder – Generate API requests with properly encoded URL parameters.
  • Frequently Asked Questions#

    What happens if I double-encode a URL?#

    If %20 is encoded a second time, the % sign becomes %25, resulting in %2520. Double-encoding is a common cause of broken links and database query bugs.

    Does URL encoding support emojis and non-English characters?#

    Yes! Emojis (like 🚀) and non-Latin scripts (like Japanese or Arabic) are first converted to their multi-byte UTF-8 representations, and each byte is percent-encoded (e.g., 🚀 becomes %F0%9F%9A%80).

    Summary#

    URL encoding ensures that complex data travels safely through the internet's routing infrastructure without confusing web servers. Using encodeURIComponent for query parameter values prevents syntax breaking and protects application stability.

    Tags:URL EncodingPercent EncodingWeb DevelopmentHTTP ProtocolQuery Parameters