Skip to content

URL Encode and Decode: Percent-Encoding Explained

Percent-encode text for safe use in URLs and query strings, or decode encoded URLs back to readable text, with UTF-8 support and clear rules for reserved characters.

3 min read

URLs can only contain a limited set of characters. Spaces, accented letters and symbols like & or = must be encoded, or they break links and corrupt query parameters. Percent-encoding, usually called URL encoding, solves this by replacing unsafe characters with a % sign and two hex digits. Our URL encoder and decoder converts text in both directions. This guide explains the rules.

How to use the tool

  1. Mode: encode or decode.
  2. Text: the text to encode, or the encoded string to decode.

With the defaults, encoding a b&c=d/é gives:

a%20b%26c%3Dd%2F%C3%A9

Decoding caf%C3%A9%20au%20lait gives café au lait.

How percent-encoding works

Each unsafe character is converted to its UTF-8 bytes, and each byte is written as % followed by two hexadecimal digits.

CharacterEncoded
Space%20
&%26
=%3D
/%2F
?%3F
#%23
+%2B
%%25
é%C3%A9

The letter é takes two bytes in UTF-8 (C3 and A9), so it becomes two percent codes. Emoji use four bytes and become four codes. The hex calculator and binary and hex converter explain the hex values.

Which characters are safe?

Unreserved characters never need encoding:

  • Letters A–Z and a–z
  • Digits 0–9
  • Hyphen, full stop, underscore and tilde: - . _ ~

Reserved characters have special meanings in URLs, such as / separating paths, ? starting a query, & separating parameters and = linking names to values. When you want one of these as data, inside a parameter value, it must be encoded.

Why it matters: query strings

Imagine a search for rock & roll. Without encoding:

/search?q=rock & roll

The & would be read as the start of a new parameter, and the search would only see "rock ". Encoded correctly:

/search?q=rock%20%26%20roll

Now the whole phrase arrives as one value.

Encoding a value versus a whole URL

This tool encodes components: it encodes reserved characters like / and ?, which is right for a single parameter value. If you encode a complete URL this way, the slashes and colons are encoded too and the link will not work. Encode each value separately, then assemble the URL.

Spaces: %20 or +?

In the path part of a URL, a space is always %20. In HTML form submissions (application/x-www-form-urlencoded), spaces in query strings are often written as +. Many servers accept both in query strings, but %20 is the safe choice everywhere.

Common uses

  • Building API requests with user input in query parameters.
  • Sharing links with special characters, such as search results or file names.
  • Reading log files and analytics, where URLs appear encoded.
  • Debugging redirects and tracking parameters such as utm_source.
  • Email links: mailto: links with subjects and bodies need encoding.

URL encoding versus Base64

URL encoding keeps text mostly readable and only changes unsafe characters. Base64 transforms everything into a compact text-safe form, and is used for binary data. To encode data with Base64, use the Base64 encoder and decoder.

Troubleshooting

  • Double encoding: if you see %2520, a % was encoded twice (%25 is the code for %). Decode twice, or fix the code that encoded it twice.
  • Garbled accented letters: the text may have been encoded in a legacy character set rather than UTF-8.
  • Plus signs turning into spaces: a form decoder treated + as a space. Encode literal plus signs as %2B.

Encoding in code

Most languages have built-in functions. In JavaScript, encodeURIComponent encodes a single value, including reserved characters, while encodeURI leaves the structure of a full URL intact. Python offers urllib.parse.quote and urlencode, and PHP has rawurlencode. Using these functions, or a URL builder in your HTTP library, is safer than adding percent codes by hand, and it avoids double encoding.

Frequently asked questions

What does %20 mean in a URL?

It is an encoded space. 20 is the hexadecimal value of the space character.

Why do accented letters become several codes?

UTF-8 stores characters like é as more than one byte, and each byte gets its own percent code.

Should I encode the whole URL?

No. Encode individual values such as query parameters, then build the URL, so its structural characters keep their meaning.

Is URL encoding a form of security?

No. It only makes text safe to transmit in URLs. Anyone can decode it.

Share

Try it yourself

Run your own numbers with our free tool: URL encode / decode. No sign-up, and it works on any device.

Open the calculator