Skip to content

URL Encoder and Decoder

This URL encoder and decoder converts text into percent-encoded form, so it can sit safely inside a web address, and turns %XX escapes back into readable text. Use the query value method for one parameter, and the full URL method for a whole address.

What do you want to do?

Query value escapes everything except letters, digits and - _ . ! ~ * ' ( ). Full URL also keeps / ? & = # : @ + $ , ; (and encodes % as %25).

Encoded text

https%3A%2F%2Fexample.com%2Fsearch%3Fq%3Dcaf%C3%A9%20menu%20%26%20tea

Encoded with encodeURIComponent. Reserved characters such as / ? & = are escaped, so the value stays in one piece.

Input characters
44
Input bytes (UTF-8)
45
Output characters
69
Escape sequences (%XX)
12

How to use this calculator

  1. 1 Choose Encode or Decode.
  2. 2 Pick Query value to encode a single parameter, or Full URL to keep a whole address working.
  3. 3 Paste your text and read the result. Letters outside basic English become several %XX bytes in UTF-8.
  4. 4 Check the escape count in the metrics to see how many characters changed.

What is URL encoding?

A URL can only contain a limited set of characters. Letters, digits and a few symbols are allowed, but spaces, accents and some punctuation are not. Percent-encoding, also called URL encoding, replaces each unsafe character with a percent sign and its code.

For example, a space becomes %20, and an ampersand becomes %26. The code is written in hexadecimal, a base-16 number system, so each byte uses two digits from 0 to 9 and A to F.

RFC 3986 defines the generic syntax of URIs, including percent-encoding. Browsers and servers apply the same rules, so an encoded address means the same thing everywhere.

Reserved and unreserved characters

Unreserved characters are letters, digits, hyphen, dot, underscore and tilde. They never need encoding. Reserved characters, such as / ? & = # and :, have a job inside a URL, so they must be encoded when they appear as data.

That difference explains the two methods in the calculator. The query value method escapes almost everything, so a value such as “tea & cake” cannot break the link. The full URL method keeps the structural characters, so the address still works after encoding.

Non-English letters are handled through UTF-8. A letter such as é takes two bytes, C3 and A9, so it becomes %C3%A9. Each byte gets its own escape, which is why accented text makes longer output.

Common characters and their escapes
CharacterQuery valueEscape
SpaceEncoded%20
&Encoded%26
/Encoded%2F
éEncoded%C3%A9
- _ . ~Not encodedKept as they are

Encoding forms and the plus sign

HTML forms are a special case. When a form is sent with the GET or POST method and the default content type, spaces are often written as + rather than %20. That form encoding is described in the WHATWG URL standard, and it is not the same as the percent-encoding in RFC 3986.

So a plus sign in a URL can mean a space or a literal plus, depending on where it appears. If you are unsure, encode a literal plus as %2B, which is unambiguous. This tool decodes + as a plus sign.

Be careful when you decode user input. Decoding can produce characters such as < or quotes, so never insert decoded text into a web page without proper escaping. The base64 encoder and decoder follows a similar idea for binary data.

Tips for building URLs safely

Most URL bugs come from encoding the wrong part. These habits prevent them:

  • Encode each value separately. Encode every parameter on its own, then join them with & and =.
  • Do not encode the whole address. That would escape the : and / that keep the URL working.
  • Encode once. Encoding a value twice turns %20 into %2520, which breaks the link.
  • Check the escapes. Every % must be followed by exactly two hex digits.
  • Explore related tools. The developer tools section has calculators for other encodings, and the hex calculator explains the digits used in each escape.

The formula

Percent encoding

character → UTF-8 bytes → each byte written as %HH

%HH
a byte written as a percent sign and two hexadecimal digits
é
encodes to two bytes, C3 and A9, so it becomes %C3%A9

Output length

escaped length = unreserved characters + 3 × escaped bytes

3
each escaped byte takes three characters: the %, and two hex digits

Worked example

Encoding a search phrase as a query value

  1. 1.Input: café menu & tea (é is two UTF-8 bytes).
  2. 2.Space becomes %20, & becomes %26, and é becomes %C3%A9.
  3. 3.Count the escapes: %C3, %A9, %20, %20, %26 and %20 make 6 sequences.

caf%C3%A9%20menu%20%26%20tea

Frequently asked questions

What is the difference between encodeURI and encodeURIComponent?

encodeURIComponent escapes everything except a few safe letters and symbols, so it suits one query value. encodeURI leaves structural characters such as / ? & = # alone, so it suits a complete URL.

Why does a space become %20 and sometimes +?

%20 is the standard escape for a space. Some HTML form submissions use + for spaces instead. This tool keeps + as a literal plus sign when decoding, so check which convention your system uses.

Why did my decode fail?

A % must be followed by exactly two hex digits. Multi-byte characters also need all their bytes, so %C3 on its own is invalid. Fix the escape and try again.

Should I encode a whole URL?

Usually not. Encode each value on its own with the query value method, then join them into the URL. Encoding the whole URL would also escape the : and / that keep it working.

Is URL encoding the same as encryption?

No. Anyone can decode percent-encoded text, so it hides nothing. It only makes characters safe to place in a URL.

Sources

Last reviewed by the GridCalculators team.