How to Encode and Decode URLs

· 7 min read

If you have ever seen %20 in a URL where a space should be, or %C3%A9 where an accented character belongs, you have encountered URL encoding. It is a fundamental part of how the web works, and understanding it helps you debug broken links, API issues, and form submissions. A browser-based encoder handles the entire job locally without uploading your data to a server.

What URL encoding does

URLs can only contain a limited set of characters safely: letters (A-Z, a-z), digits (0-9), and a few special characters (-, _, ., ~). Everything else (spaces, accented characters, emoji, and symbols like &, =, #, ?) must be converted to a safe format.

URL encoding (also called percent-encoding) replaces unsafe characters with a % followed by their hexadecimal byte values:

Character Encoded
Space %20
& %26
= %3D
# %23
? %3F
/ %2F
@ %40
: %3A
+ %2B
, %2C
; %3B
(newline) %0A
(tab) %09

When you need URL encoding

How to encode and decode

  1. Choose encode or decode: select the direction. Pick encodeURIComponent for query parameters or encodeURI for full URLs.
  2. Paste your input: enter the text or URL. The result updates instantly.
  3. Copy the output: use the result in your code, API request, or browser.

A brief history of URL encoding

URL encoding was defined by RFC 1738 in December 1994, alongside the original URL specification. The RFC was written by Tim Berners-Lee (inventor of the web) with input from the IETF URI Working Group. The original encoding scheme used ASCII byte values: every reserved or unsafe character was encoded as % followed by two hex digits.

The encoding was updated several times:

The biggest change was the move to UTF-8 in RFC 3986. Before that, encoded URLs were ASCII-only, and non-Latin characters required workarounds (Punycode for domains, IDN for international addresses). Today, an accented "é" in a URL encodes to %C3%A9 (its two UTF-8 bytes), not the Latin-1 byte %E9 that older systems would produce.

encodeURI vs encodeURIComponent vs encodeURIFull

JavaScript has three encoding functions with subtly different behavior:

Function What it encodes What it preserves Use for
encodeURI() All unsafe chars URL syntax: : / ? & = # Encoding whole URLs
encodeURIComponent() All unsafe chars including URL syntax Only A-Z a-z 0-9 - _ . ~ ! * ' ( ) Query parameter values
escape() (deprecated) Most unsafe chars Latin-1 only Do not use

In Python:

In other languages:

Language Component encoding Full URI encoding
Java URLEncoder.encode() (with caveats around +) URI.toASCIIString()
C# Uri.EscapeDataString Uri.EscapeUriString
Ruby CGI.escape() URI.encode_www_form_component
PHP rawurlencode() urlencode() (note: %2B vs +)
Go url.QueryEscape() url.PathEscape()
Rust percent_encoding crate percent_encoding crate

Common pitfalls

Worked examples

Input encodeURI encodeURIComponent
hello world hello%20world hello%20world
q=test&page=1 q=test&page=1 q%3Dtest%26page%3D1
https://x.com/path https://x.com/path https%3A%2F%2Fx.com%2Fpath
caf é caf%20%C3%A9 caf%20%C3%A9
中文 %E4%B8%AD%E6%96%87 %E4%B8%AD%E6%96%87
100% 100%25 100%25
email@test.com email@test.com email%40test.com

Tips

Privacy and confidential URLs

The URL encoder and decoder run entirely in your browser. The URLs you paste, intermediate processing, and the encoded/decoded output all stay on your device. Nothing is uploaded to a server, logged, or shared with anyone.

This matters because URLs frequently contain extremely sensitive data: API keys and tokens in query parameters, OAuth authorization codes that grant account access, session IDs, signed URLs for private S3 buckets with embedded credentials, magic-link login tokens, password reset URLs, internal admin URLs that reveal product structure, customer email addresses in unsubscribe links, personal data in form submissions. Cloud URL encoders log every paste, sometimes retain them for "service improvement," and have been involved in real leaks where pasted authentication tokens were extracted by attackers monitoring the logs. A browser-based encoder has zero exposure: the URL never leaves your machine.

Browser-based encoding also works offline once the page is loaded, useful for encoding URLs on airplanes, in secure environments without internet access, or anywhere you cannot or should not paste authentication-bearing URLs into a third-party service.

Frequently Asked Questions

What is the difference between encodeURI and encodeURIComponent?

encodeURI preserves characters that are valid in a URL structure (slashes, colons, question marks). encodeURIComponent encodes everything except letters, digits, and a few safe characters. Use encodeURIComponent for query parameter values, encodeURI for complete URLs.

Why do spaces become %20 or +?

In URL encoding, spaces become %20. In form data (application/x-www-form-urlencoded), spaces become +. Both are valid in their respective contexts, but %20 is the universal standard for URLs.

Do I need to encode my URLs manually?

In most cases, your programming language or framework handles encoding automatically. Manual encoding is needed when building URLs by hand, debugging API requests, or working with query strings that contain special characters.

Is my data sent to a server?

No. All encoding and decoding happens in your browser.