URL encoding
| What URL encoding is | |
| Which characters to encode | |
| %20 or + | |
| Encode in code and in the terminal | |
| Table: Windows-1252 and UTF-8 |
What URL encoding is
A URL may contain only a small set of ASCII characters, and some of them have a job: / separates folders, ? starts the query, & separates parameters. Any other character, and a special one used as plain text, is written as % followed by the two hexadecimal digits of each of its bytes. This is called URL encoding or percent-encoding.
Today the bytes are those of UTF-8, so é (two bytes in UTF-8) becomes %C3%A9. Old sites sometimes used the bytes of a one-byte code page such as Windows-1252, where é is %E9; the table below shows both.
Which characters to encode
- Never encoded: letters A–Z a–z, digits and - . _ ~.
- Encoded when they are data, left as they are when they do their job: : / ? # [ ] @ ! $ & ' ( ) * + , ; =. A & inside a parameter value must become %26, or it starts a new parameter.
- Always encoded: the space, % itself (%25), control characters, quotes, < > and every non-ASCII character.
%20 or +
In a path a space is %20. HTML forms send their fields as application/x-www-form-urlencoded, where a space in the query is a +, and a real plus sign has to be %2B. Servers decode + as a space only in the query string. When in doubt, %20 works everywhere.
Encode in code and in the terminal
The same text, café & co/1, encoded by several tools on 26 October 2026. Python:
python3 -c "from urllib.parse import quote; print(quote('café & co/1'))"
caf%C3%A9%20%26%20co/1
quote leaves / alone, because it expects a path. For a single value pass safe='':
python3 -c "from urllib.parse import quote; print(quote('café & co/1', safe=''))"
caf%C3%A9%20%26%20co%2F1
PHP has two functions: rawurlencode writes spaces as %20, urlencode as +, like a form:
php -r 'echo rawurlencode("café & co/1"), PHP_EOL, urlencode("café & co/1"), PHP_EOL;'
caf%C3%A9%20%26%20co%2F1 caf%C3%A9+%26+co%2F1
JavaScript, here in Node.js: encodeURIComponent encodes one value, encodeURI a whole address and leaves its : / ? & alone:
node -e 'console.log(encodeURIComponent("café & co/1")); console.log(encodeURI("https://example.com/a b?q=café"))'
caf%C3%A9%20%26%20co%2F1 https://example.com/a%20b?q=caf%C3%A9
curl encodes query parameters with --data-urlencode; -G puts them into the URL of a GET request:
curl -s -o /dev/null -G --data-urlencode "q=café & co" -w '%{url_effective}\n' http://127.0.0.1:8080/search/
http://127.0.0.1:8080/search/?q=caf%c3%a9+%26+co
Upper or lower case hex digits mean the same. Decoding is the reverse; in Python unquote('caf%C3%A9%20%26%20co') gives back café & co.
Table: Windows-1252 and UTF-8
Every printable character of Windows-1252, with its encoding from that code page and from UTF-8. ASCII characters are the same in both. Windows-1252 leaves the bytes 81, 8D, 8F, 90 and 9D undefined, so they are missing. The table was generated from the encodings themselves.
| Character | Windows-1252 | UTF-8 |
|---|---|---|
| space | %20 | %20 |
| ! | %21 | %21 |
| " | %22 | %22 |
| # | %23 | %23 |
| $ | %24 | %24 |
| % | %25 | %25 |
| & | %26 | %26 |
| ' | %27 | %27 |
| ( | %28 | %28 |
| ) | %29 | %29 |
| * | %2A | %2A |
| + | %2B | %2B |
| , | %2C | %2C |
| - | %2D | %2D |
| . | %2E | %2E |
| / | %2F | %2F |
| 0 | %30 | %30 |
| 1 | %31 | %31 |
| 2 | %32 | %32 |
| 3 | %33 | %33 |
| 4 | %34 | %34 |
| 5 | %35 | %35 |
| 6 | %36 | %36 |
| 7 | %37 | %37 |
| 8 | %38 | %38 |
| 9 | %39 | %39 |
| : | %3A | %3A |
| ; | %3B | %3B |
| < | %3C | %3C |
| = | %3D | %3D |
| > | %3E | %3E |
| ? | %3F | %3F |
| @ | %40 | %40 |
| A | %41 | %41 |
| B | %42 | %42 |
| C | %43 | %43 |
| D | %44 | %44 |
| E | %45 | %45 |
| F | %46 | %46 |
| G | %47 | %47 |
| H | %48 | %48 |
| I | %49 | %49 |
| J | %4A | %4A |
| K | %4B | %4B |
| L | %4C | %4C |
| M | %4D | %4D |
| N | %4E | %4E |
| O | %4F | %4F |
| P | %50 | %50 |
| Q | %51 | %51 |
| R | %52 | %52 |
| S | %53 | %53 |
| T | %54 | %54 |
| U | %55 | %55 |
| V | %56 | %56 |
| W | %57 | %57 |
| X | %58 | %58 |
| Y | %59 | %59 |
| Z | %5A | %5A |
| [ | %5B | %5B |
| \ | %5C | %5C |
| ] | %5D | %5D |
| ^ | %5E | %5E |
| _ | %5F | %5F |
| ` | %60 | %60 |
| a | %61 | %61 |
| b | %62 | %62 |
| c | %63 | %63 |
| d | %64 | %64 |
| e | %65 | %65 |
| f | %66 | %66 |
| g | %67 | %67 |
| h | %68 | %68 |
| i | %69 | %69 |
| j | %6A | %6A |
| k | %6B | %6B |
| l | %6C | %6C |
| m | %6D | %6D |
| n | %6E | %6E |
| o | %6F | %6F |
| p | %70 | %70 |
| q | %71 | %71 |
| r | %72 | %72 |
| s | %73 | %73 |
| t | %74 | %74 |
| u | %75 | %75 |
| v | %76 | %76 |
| w | %77 | %77 |
| x | %78 | %78 |
| y | %79 | %79 |
| z | %7A | %7A |
| { | %7B | %7B |
| | | %7C | %7C |
| } | %7D | %7D |
| ~ | %7E | %7E |
| € | %80 | %E2%82%AC |
| ‚ | %82 | %E2%80%9A |
| ƒ | %83 | %C6%92 |
| „ | %84 | %E2%80%9E |
| … | %85 | %E2%80%A6 |
| † | %86 | %E2%80%A0 |
| ‡ | %87 | %E2%80%A1 |
| ˆ | %88 | %CB%86 |
| ‰ | %89 | %E2%80%B0 |
| Š | %8A | %C5%A0 |
| ‹ | %8B | %E2%80%B9 |
| Œ | %8C | %C5%92 |
| Ž | %8E | %C5%BD |
| ‘ | %91 | %E2%80%98 |
| ’ | %92 | %E2%80%99 |
| “ | %93 | %E2%80%9C |
| ” | %94 | %E2%80%9D |
| • | %95 | %E2%80%A2 |
| – | %96 | %E2%80%93 |
| — | %97 | %E2%80%94 |
| ˜ | %98 | %CB%9C |
| ™ | %99 | %E2%84%A2 |
| š | %9A | %C5%A1 |
| › | %9B | %E2%80%BA |
| œ | %9C | %C5%93 |
| ž | %9E | %C5%BE |
| Ÿ | %9F | %C5%B8 |
| no-break space | %A0 | %C2%A0 |
| ¡ | %A1 | %C2%A1 |
| ¢ | %A2 | %C2%A2 |
| £ | %A3 | %C2%A3 |
| ¤ | %A4 | %C2%A4 |
| ¥ | %A5 | %C2%A5 |
| ¦ | %A6 | %C2%A6 |
| § | %A7 | %C2%A7 |
| ¨ | %A8 | %C2%A8 |
| © | %A9 | %C2%A9 |
| ª | %AA | %C2%AA |
| « | %AB | %C2%AB |
| ¬ | %AC | %C2%AC |
| soft hyphen | %AD | %C2%AD |
| ® | %AE | %C2%AE |
| ¯ | %AF | %C2%AF |
| ° | %B0 | %C2%B0 |
| ± | %B1 | %C2%B1 |
| ² | %B2 | %C2%B2 |
| ³ | %B3 | %C2%B3 |
| ´ | %B4 | %C2%B4 |
| µ | %B5 | %C2%B5 |
| ¶ | %B6 | %C2%B6 |
| · | %B7 | %C2%B7 |
| ¸ | %B8 | %C2%B8 |
| ¹ | %B9 | %C2%B9 |
| º | %BA | %C2%BA |
| » | %BB | %C2%BB |
| ¼ | %BC | %C2%BC |
| ½ | %BD | %C2%BD |
| ¾ | %BE | %C2%BE |
| ¿ | %BF | %C2%BF |
| À | %C0 | %C3%80 |
| Á | %C1 | %C3%81 |
| Â | %C2 | %C3%82 |
| Ã | %C3 | %C3%83 |
| Ä | %C4 | %C3%84 |
| Å | %C5 | %C3%85 |
| Æ | %C6 | %C3%86 |
| Ç | %C7 | %C3%87 |
| È | %C8 | %C3%88 |
| É | %C9 | %C3%89 |
| Ê | %CA | %C3%8A |
| Ë | %CB | %C3%8B |
| Ì | %CC | %C3%8C |
| Í | %CD | %C3%8D |
| Î | %CE | %C3%8E |
| Ï | %CF | %C3%8F |
| Ð | %D0 | %C3%90 |
| Ñ | %D1 | %C3%91 |
| Ò | %D2 | %C3%92 |
| Ó | %D3 | %C3%93 |
| Ô | %D4 | %C3%94 |
| Õ | %D5 | %C3%95 |
| Ö | %D6 | %C3%96 |
| × | %D7 | %C3%97 |
| Ø | %D8 | %C3%98 |
| Ù | %D9 | %C3%99 |
| Ú | %DA | %C3%9A |
| Û | %DB | %C3%9B |
| Ü | %DC | %C3%9C |
| Ý | %DD | %C3%9D |
| Þ | %DE | %C3%9E |
| ß | %DF | %C3%9F |
| à | %E0 | %C3%A0 |
| á | %E1 | %C3%A1 |
| â | %E2 | %C3%A2 |
| ã | %E3 | %C3%A3 |
| ä | %E4 | %C3%A4 |
| å | %E5 | %C3%A5 |
| æ | %E6 | %C3%A6 |
| ç | %E7 | %C3%A7 |
| è | %E8 | %C3%A8 |
| é | %E9 | %C3%A9 |
| ê | %EA | %C3%AA |
| ë | %EB | %C3%AB |
| ì | %EC | %C3%AC |
| í | %ED | %C3%AD |
| î | %EE | %C3%AE |
| ï | %EF | %C3%AF |
| ð | %F0 | %C3%B0 |
| ñ | %F1 | %C3%B1 |
| ò | %F2 | %C3%B2 |
| ó | %F3 | %C3%B3 |
| ô | %F4 | %C3%B4 |
| õ | %F5 | %C3%B5 |
| ö | %F6 | %C3%B6 |
| ÷ | %F7 | %C3%B7 |
| ø | %F8 | %C3%B8 |
| ù | %F9 | %C3%B9 |
| ú | %FA | %C3%BA |
| û | %FB | %C3%BB |
| ü | %FC | %C3%BC |
| ý | %FD | %C3%BD |
| þ | %FE | %C3%BE |
| ÿ | %FF | %C3%BF |
Article authors: Andrei Olegovich, Klavdiya Kondakova