Tech

How URL Encoding Works (Percent-Encoding Explained)

URL encoding writes unsafe characters as a % and two hex digits. A space is %20, & is %26 and é is %C3%A9. "a b&c" becomes a%20b%26c. Safe characters (letters, digits and - _ . ~) stay as they are.

By CalculatorHub Editorial TeamPublished December 2, 2026Updated December 2, 20266 min read
Run the numbers yourself. Try our free URL Encode and Decode and see the result with your own figures.

Why encoding is needed

Web addresses can contain only a limited set of characters. Spaces and symbols such as ? & = # have special meanings or are not allowed, so they are replaced with percent codes.

How a character is encoded

Find the character's UTF-8 bytes and write each as % plus two hexadecimal digits. A space is byte 32, which is hex 20, so %20. The letter é is two bytes (C3 A9), so %C3%A9.

CharacterCode
space%20
&%26
=%3D
?%3F
#%23
/%2F

Component or whole URL

When you encode a single value that will sit inside a query string, encode everything unsafe, including / ? & = #. When you encode a whole address, keep those characters so the structure stays. The two JavaScript functions are encodeURIComponent and encodeURI.

Plus signs and spaces

In HTML form data a + stands for a space, but in a path only %20 works. When in doubt use %20.

Avoid double encoding

Encoding an already encoded string turns %20 into %2520. Encode raw text only once, at the end.

Decoding

Decoding reverses the process. A % not followed by two hex digits is invalid and will cause an error.

Use the URL encoder and decoder, and see how Base64 works for data inside text.

Key terms

  • Percent-encoding: Writing a character as % and two hex digits.
  • Reserved character: A character with a special meaning in URLs, such as ? or &.
  • Query string: The part after ? holding parameters.
  • Hexadecimal: Base 16 numbering.
  • Fragment: The part after # in a URL.

Practice questions

Try each one before you read the answer.

  1. Encode "50% off".
    Answer: 50%25%20off.
  2. Decode %E2%9C%93.
    Answer: ✓ (check mark).
  3. Why is & encoded in a value?
    Answer: Otherwise it would start a new query parameter.

Worked examples

TextEncoded value
hello worldhello%20world
cats & dogscats%20%26%20dogs
price=5+5price%3D5%2B5
cafécaf%C3%A9

Common problems

  • A link that works in the address bar but fails in code usually has an unencoded & or # in a value.
  • Garbled letters after decoding usually mean the text was not UTF-8.
  • Do not encode the https:// at the start of a URL when you encode a whole address.

Security note

Encoding is not a security feature. Attackers also use encoding to hide harmful input, so websites must validate and decode input safely. As a user, be careful with links that contain many % codes from unknown senders.

URLs in everyday life

Every search you type, link you share and form you submit relies on URL encoding. When you search for 'best cafés near me', your browser sends best%20caf%C3%A9s%20near%20me. Developers must encode values whenever they build addresses in code, and linking tools do this for you automatically. Understanding it helps you debug broken links and read long addresses.

Short reference

Letters, digits and the symbols - _ . ~ are never encoded. Everything else in a value should be. If you are unsure, encode it. The decoder will bring it back unchanged, so over-encoding a value is much safer than leaving a special character in a query string. Spaces, quotation marks, angle brackets and non-English letters are the characters that most often cause trouble.

Frequently asked questions

Why is a space %20?

The space character has the byte value 32, which is 20 in hexadecimal.

Do I need to encode letters and numbers?

No. Letters, digits and - _ . ~ are safe.

What causes %2520 in a URL?

Double encoding: the % of %20 was encoded again as %25.

Try the calculators

Keep reading