Number Convert
Back to Blog

URL Encoding Explained: When and Why to Encode URLs

β€’NumberConvert Teamβ€’3 min read

Learn when to use URL encoding, which characters need encoding, and how to avoid common mistakes in web development.

Listen to this article

Browser text-to-speech

What Is URL Encoding?

URL encoding (also called percent-encoding) converts characters into a format safe for URLs. Since URLs can only contain a limited set of ASCII characters, special characters must be encoded as %XX where XX is the hexadecimal value.

For example:

  • Space β†’ %20 or +
  • Ampersand β†’ %26
  • Question mark β†’ %3F
  • Equals sign β†’ %3D

Why URL Encoding Exists

URLs have special characters with specific meanings:

  • ? separates the path from query parameters
  • & separates query parameters
  • = separates parameter names from values
  • / separates path segments
  • # indicates a fragment

If your data contains these characters, they must be encoded to avoid being misinterpreted.

Characters That Must Be Encoded

Always Encode

  • Space: %20 (or + in query strings)
  • Ampersand: %26
  • Plus sign: %2B
  • Percent: %25
  • Question mark: %3F
  • Hash: %23
  • Non-ASCII characters: UTF-8 bytes as %XX

Safe Without Encoding

  • Letters: A-Z, a-z
  • Numbers: 0-9
  • Unreserved: - _ . ~

Reserved (Context-Dependent)

  • : / ? # [ ] @ ! $ & ( ) * + , ; =

Common Mistakes

1. Double Encoding

2. Not Encoding User Input

3. Using encodeURI vs encodeURIComponent

When to Encode vs Decode

Encode When:

  • Building URLs with dynamic content
  • Passing user input in query strings
  • Including special characters in URL parameters
  • Creating data URIs

Decode When:

  • Reading query parameters from a URL
  • Displaying URLs to users
  • Processing form submissions
  • Parsing URL-encoded data

URL Encoding in Different Languages

JavaScript

Python

PHP

Note: PHP urlencode uses + for spaces (form encoding), while rawurlencode uses %20 (standard URL encoding).

Space: + vs %20

There are two valid ways to encode spaces:

  • %20: Standard URL encoding (RFC 3986)
  • +: Form encoding (application/x-www-form-urlencoded)

Both are valid in query strings, but + is specific to form data. When in doubt, use %20 as its more universally supported.

International Characters

Non-ASCII characters (like ΓΌ, δΈ­, or πŸŽ‰) are encoded as their UTF-8 bytes:

  • ΓΌ (U+00FC) β†’ %C3%BC
  • δΈ­ (U+4E2D) β†’ %E4%B8%AD
  • πŸŽ‰ (U+1F389) β†’ %F0%9F%8E%89

This ensures URLs work correctly regardless of character encoding.

Testing Your URLs

Use our URL Encoder to test encoding and decoding. Common issues to check:

  • Are all special characters properly encoded?
  • Is the URL not double-encoded?
  • Do international characters display correctly after decoding?

See what our calculators can do for you

Ready to take control of your finances?

Explore our free financial calculators and tools to start making informed decisions today.

Explore Our Tools
URL Encoding Explained: When and Why to Enco... | FinToolset