Skip to content
UtiliaTools

URL Encoding Explained: Everything You Need to Know

Learn how URL encoding works, why it matters for web development, and encode or decode URLs instantly with our free tool.

URL Encoding Explained: Everything You Need to Know

Every time you search Google, share a link with query parameters, or build a REST API, URL encoding is working behind the scenes. Yet many developers treat it as a mystery β€” or worse, ignore it until something breaks.

This guide explains URL encoding (also called percent-encoding) from scratch: what it is, why it exists, how it works, and how to handle it correctly in your projects.

What Is URL Encoding?

URL encoding is a mechanism that replaces certain characters with a % sign followed by two hexadecimal digits. It ensures that URLs contain only characters from the safe ASCII set, making them valid and transmissible across the internet.

For example, a space character becomes %20, and an ampersand becomes %26.

The formal specification is defined in RFC 3986, which outlines which characters are allowed in URLs and which must be encoded.

Why Is URL Encoding Necessary?

URLs can only contain a limited set of characters:

  • Letters: A–Z, a–z
  • Digits: 0–9
  • Unreserved characters: -, _, ., ~

Everything else β€” spaces, accented characters, symbols like &, =, ?, # β€” must be encoded if they appear in a URL. Without encoding, the server can't reliably distinguish between the actual data and the URL's structural characters.

Consider this URL:

https://example.com/search?q=hello world&lang=en

The space in "hello world" creates ambiguity. Is it part of the query, or does it signal something else? URL encoding removes that ambiguity:

https://example.com/search?q=hello%20world&lang=en

How URL Encoding Works

The encoding process is straightforward:

  1. Take a character that isn't in the safe set.
  2. Convert it to its byte value (in UTF-8 for non-ASCII characters).
  3. Represent each byte as % followed by two hex digits.

Examples

Character UTF-8 Bytes Encoded
Space 0x20 %20
& 0x26 %26
Γ© 0xC3 0xA9 %C3%A9
Γ± 0xC3 0xB1 %C3%B1
δΈ­ 0xE4 0xB8 0xAD %E4%B8%AD

Notice that non-ASCII characters like Γ© produce multiple encoded bytes because UTF-8 uses multi-byte sequences for characters outside the basic ASCII range.

URL Encoding vs. Form Encoding

There's an important distinction between URL encoding (percent-encoding per RFC 3986) and form encoding (application/x-www-form-urlencoded):

Aspect URL Encoding Form Encoding
Space β†’ %20 +
Standard RFC 3986 HTML spec
Used in Path, query string Form submissions

In form encoding, spaces become + instead of %20. This is a common source of bugs when developers mix up the two formats.

When Do You Need to URL Encode?

You need URL encoding in several common scenarios:

  • Query parameters: Values containing special characters (&, =, ?, spaces) must be encoded.
  • URL paths with spaces or Unicode: File names like my file.pdf or cafΓ©.md need encoding.
  • Building URLs dynamically: When concatenating user input into URLs, always encode the input.
  • Redirect URLs: Parameters like ?redirect=https://other.com/page?a=1&b=2 need the inner URL encoded.

How to URL Encode in Code

JavaScript

// encodeURI: encodes a full URL (preserves ://, ?, &, =)
encodeURI("https://example.com/hello world");
// β†’ "https://example.com/hello%20world"

// encodeURIComponent: encodes a single value (encodes everything special)
encodeURIComponent("hello world&more");
// β†’ "hello%20world%26more"

Python

from urllib.parse import quote, quote_plus

quote("hello world")      # β†’ "hello%20world"
quote_plus("hello world") # β†’ "hello+world"

PHP

urlencode("hello world");    // β†’ "hello+world"
rawurlencode("hello world"); // β†’ "hello%20world"

Common URL Encoding Mistakes

  1. Double encoding: Encoding a string that's already encoded produces %2520 instead of %20. Always check if your framework already encodes values.
  2. Using the wrong function: In JavaScript, encodeURI vs. encodeURIComponent behave differently. Use encodeURIComponent for query parameter values.
  3. Forgetting to decode on the server: If you encode on the client, the server framework usually decodes automatically β€” but not always. Verify your backend handles it.
  4. Encoding the entire URL: Using encodeURIComponent on a full URL will encode the ://, ?, and & characters, breaking the URL structure.

Try Our Free URL Encoder & Decoder

Our URL Encoder & Decoder makes URL encoding instant and hassle-free. Simply paste your text or URL, choose encode or decode, and get the result immediately.

Features:

  • Instant encoding and decoding with one click
  • Supports Unicode characters from any language
  • Works in your browser β€” no data sent to any server
  • Shows both formats β€” percent-encoded and form-encoded

Whether you're debugging a broken URL, building query strings, or testing API endpoints, having a reliable URL encoding tool saves time and prevents frustrating bugs.

Decoding URLs

Decoding is the reverse process: replace %XX sequences with their original characters. Most web frameworks handle this automatically for incoming requests, but you may need to decode manually when:

  • Parsing URLs from logs or databases
  • Working with raw HTTP requests
  • Processing user-submitted URLs

Conclusion

URL encoding is a small but critical piece of web infrastructure. Understanding when and how to encode (and decode) URLs prevents bugs, improves security, and ensures your applications handle international characters correctly.

Bookmark our URL Encoder & Decoder for quick encoding and decoding tasks β€” it's fast, free, and works entirely in your browser.

Last updated on 2026-09-27