Quick Answer

URL encoding, officially called percent-encoding, replaces unsafe characters in a URL with a percent sign followed by two hexadecimal digits. A space becomes %20. It matters because URLs reserve certain characters for structure, so any user data containing those characters must be encoded or the URL breaks.

URL encoding is the process of replacing characters that aren't safe in a URL with a percent sign followed by two hexadecimal digits, which is why the official name is percent-encoding. A space becomes %20, an ampersand becomes %26, and a question mark becomes %3F. It matters because a URL isn't just a string. It's a structured address where characters like ?, &, / and # carry meaning, and the moment user data contains one of them, something breaks. The rules come from RFC 3986, published by the IETF in January 2005 as Internet Standard 66.

Encode or Decode a URL Now

Our free URL encoder and decoder handles both directions in your browser. Nothing is uploaded, so query strings with real data stay on your device.

Open URL Encoder →

Why does URL encoding exist at all?

Because a URL has to be parsed, and parsing needs delimiters. In https://example.com/search?q=cats&page=2, the ? marks where the query starts and the & splits parameters apart. Those characters are structure, not content.

Now imagine someone searches for cats & dogs. Drop that raw into the URL and you get ?q=cats & dogs&page=2. The parser sees q with the value cats , then a parameter called dogs with no value, then page=2. Encode it to ?q=cats%20%26%20dogs&page=2 and it works, because the encoded ampersand is data rather than a delimiter.

If you build campaign links, our UTM parameters guide covers the same trap from the marketing side.

Which characters actually need encoding?

Unreserved characters never need encoding. Section 2.3 of RFC 3986 defines them as ALPHA / DIGIT / "-" / "." / "_" / "~", which works out to 66 characters: 26 uppercase letters, 26 lowercase letters, 10 digits, and 4 punctuation marks.

Reserved characters are the delimiters, listed in Section 2.2:

SetCharactersCount
gen-delims: / ? # [ ] @7
sub-delims! $ & ' ( ) * + , ; =11

That's 18 reserved characters. Each one needs encoding when it appears as data rather than as structure. A slash separating path segments stays a slash. A slash inside a filename becomes %2F. Everything outside both groups gets encoded too: spaces, quotes, angle brackets, control characters, and every non-ASCII character.

The mechanism: convert the character to UTF-8 bytes, write each byte as two uppercase hex digits, and prefix each with a percent sign. That's why é becomes %C3%A9 and an emoji becomes four escapes. It's fully reversible and public, the same relationship Base64 has with encryption, which is to say none at all.

Which JavaScript function should you use?

JavaScript ships two encoders and picking the wrong one is a very common URL bug. According to MDN, encodeURI() leaves 82 characters unescaped: the 62 alphanumerics, the 9 marks - _ . ! ~ * ' ( ), and the 11 reserved characters ; / ? : @ & = + $ , #. encodeURIComponent() leaves only 71, because it encodes those 11 too.

FunctionLeaves unescapedUse it for
encodeURI()82 charactersA complete URL that still needs its structure intact
encodeURIComponent()71 charactersA single query value, path segment, or fragment

The failure mode: build a redirect as ?next= plus a target URL, use encodeURI() on the target, and its ? and & survive unescaped, fusing two query strings together. encodeURIComponent() turns the target into one opaque value that round-trips cleanly.

Modern code can skip the decision. The URLSearchParams API encodes values for you, and it's part of the WHATWG URL Standard, the living spec browsers actually implement. The IETF documents define the format; WHATWG defines what your browser really does with it.

Does the right encoding depend on where in the URL you are?

Yes. RFC 3986 doesn't define one allowed character set for a whole URL. It defines a separate grammar for each component:

ComponentGrammar
userinfo*( unreserved / pct-encoded / sub-delims / ":" )
path segment (pchar)unreserved / pct-encoded / sub-delims / ":" / "@"
query*( pchar / "/" / "?" )
fragment*( pchar / "/" / "?" )

The path is stricter than the query. A literal slash in a query value is legal, but a path segment doesn't allow /, so a slash inside a filename has to become %2F.

Under-encoding is what hurts. A raw & or = splits one parameter into two, and a raw # truncates everything after it, because the fragment is never sent to the server. Encode per value, not per URL.

userinfo has a credentials trap. It doesn't allow @ or /, so a password containing @ in a connection string breaks the URL unless encoded. Section 3.2.1 also states that "use of the format 'user:password' in the userinfo field is deprecated." Put credentials in a header or config file. Our URL encoder is the quickest way to check a value before production.

Why does a space sometimes become a plus sign?

Because there are two encoding contexts and they disagree. In a URL, RFC 3986 says a space is %20. HTML form submissions use the older application/x-www-form-urlencoded format, where a space becomes +. The WHATWG URL Standard keeps this alive with a spaceAsPlus flag that is set true only for the form-urlencoded percent-encode set.

Rule of thumb: decode with the same convention the data was encoded with. If it came from a form post or a URLSearchParams serialisation, treat + as a space. If it came from a path or a hand-built URL, treat + as a literal plus sign.

Get it wrong and a password containing + turns into a password containing a space, and the login fails.

Do you need to percent-encode Base64 in a URL?

Usually not. The standard alphabet includes + and /: the + can arrive as a space and the / reads as a path separator. RFC 4648 Section 5 defines a "URL and Filename Safe Alphabet" that swaps them for - and _, both unreserved. Every JWT uses it: RFC 7519 says each part "contains a base64url-encoded value." Python has urlsafe_b64encode.

One trap: RFC 7515 omits the trailing = padding, and many standard decoders reject input whose length isn't a multiple of four. Pad it back with = before decoding.

Convert Base64 Now

Our Base64 encoder and decoder handles both alphabets, and the URL encoder is there when percent-encoding really is the right tool.

Does URL encoding work the same in other languages?

No. Most languages ship an RFC 3986 encoder and a form encoder. Oracle's Javadoc for java.net.URLEncoder calls it a "Utility class for HTML form encoding", so use it on a path segment and you get plus signs where you needed %20.

LanguageFunctionSpace becomesFollows
JavaScriptencodeURIComponent()%20RFC 3986
Pythonurllib.parse.quote()%20RFC 3986, but safe='/' by default
Pythonurllib.parse.quote_plus()+Form encoding
PHPrawurlencode()%20RFC 3986
PHPurlencode()+Form encoding
JavaURLEncoder.encode()+Form encoding only

Python's default won't encode a slash. The Python documentation says the safe parameter's "default value is '/'". Pass safe='' when quoting a single segment. The PHP manual and the Javadoc also differ on the tilde and asterisk:

Quick test for any language: encode the string a~b c*d and read the answer.
a~b%20c%2Ad is Python's quote() or PHP's rawurlencode().
a~b%20c*d is JavaScript's encodeURIComponent(), which leaves the asterisk alone.
a%7Eb+c*d is Java's URLEncoder.
a%7Eb+c%2Ad is PHP's urlencode().
The space tells you whether you're holding a form encoder.

Between services in different languages, encode and decode with the same convention.

How do you encode a URL for a signed API request?

Exactly as that API's spec says, because the signature is computed over the encoded string. Change one byte and you get a 403.

OAuth 1.0a spells out its own rules in RFC 5849, section 3.6: unreserved characters are not encoded, "All other characters MUST be encoded," and "The two hexadecimal characters used to represent encoded characters MUST be uppercase." So %2f fails where %2F passes, even though RFC 3986 treats them as equivalent.

AWS Signature Version 4 defines its own UriEncode() in the AWS documentation for creating a signed request: encode every byte except A-Z, a-z, 0-9, hyphen, period, underscore and tilde; space is %20; hex letters are uppercase; and the forward slash is encoded everywhere except in an S3 object key name. AWS warns that "The standard UriEncode functions provided by your development platform might not work," which is the spread from the test above.

Use the official SDK if you can, as AWS recommends. Otherwise log the canonical string and compare it with a known-good client's in a text diff. The mismatch is nearly always a single character.

How do you percent-encode a filename in a download header?

With the filename* parameter of Content-Disposition, one of the few places percent-encoding turns up outside a URL. RFC 6266, section 4.3 defines plain filename and filename*; the starred one allows characters outside ISO-8859-1, so Résumé.pdf or 季度报告.xlsx needs it.

The syntax lives in RFC 8187, which replaced RFC 5987 in 2017. It says "Producers MUST use the 'UTF-8' character encoding," so every value starts with UTF-8''. RFC 6266's own example:

Content-Disposition: attachment; filename*= UTF-8''%e2%82%ac%20rates

That's € rates: three escapes for the euro sign and %20 for the space, never a plus sign.

encodeURIComponent() nearly does the job, but RFC 8187's attr-char set doesn't allow ' ( ) *, which encodeURIComponent() leaves untouched. MDN gives a helper, encodeRFC5987ValueChars, that escapes them to %27, %28, %29 and %2A.

Try it: paste your filename into our URL encoder to see the UTF-8 escapes, then swap any ' ( ) * for %27 %28 %29 %2A by hand. Send an ASCII fallback too, since RFC 6266 says recipients "SHOULD pick 'filename*' and ignore 'filename'" when both are present: attachment; filename="Resume.pdf"; filename*=UTF-8''R%C3%A9sum%C3%A9.pdf.

What happens to non-English characters in a URL?

Percent-encoding handles non-ASCII text in the path, query and fragment. It does not handle the hostname. In the path, café becomes caf%C3%A9 and a rocket emoji becomes %F0%9F%9A%80.

Domains use Punycode, specified in RFC 3492. RFC 5891 spells out the conversion: "The A-label is the encoding of the U-label according to the Punycode algorithm with the ACE prefix 'xn--' added at the beginning of the string."

What you typeWhat actually resolves
münchen.dexn--mnchen-3ya.de
café.frxn--caf-dma.fr
日本.jpxn--wgv71a.jp

You can't percent-encode your way around the host rules either. The WHATWG URL Standard percent-decodes the host before checking it against 17 forbidden host code points, so %2F in a hostname just gets you a slash and a parse failure.

Practical version: lookalike characters let a Punycode domain render as something it isn't. gmaıl.com, with a Turkish dotless i, travels as xn--gmal-nza.com. If you're logging, comparing, or allowlisting domains, normalise to the xn-- form first.

How long can a URL be after encoding?

RFC 9112, section 3 sets no maximum, but recommends that senders and recipients support "at a minimum, request-line lengths of 8000 octets." Past what a server will parse, it returns 414 (URI Too Long). Encoding is usually what pushes you over, because every encoded byte becomes three characters:

CharacterUTF-8 bytesEncodedLength
space1%203x
e with acute accent2%C3%A96 chars
a CJK character3%E6%96%879 chars
an emoji4%F0%9F%98%8012 chars

A 200-character phrase in Japanese or Chinese becomes about 1800 characters on the wire, and double encoding multiplies again.

Rule of thumb: if a value is user-generated, unbounded, or non-Latin, send it in a POST body. Query parameters are for short, known-shape values like ids, flags, and pagination.

Are two differently encoded URLs the same?

Sometimes. RFC 3986, section 6.2.2.1 says hex digits in a percent-encoding "are case-insensitive and therefore should be normalized to use uppercase letters." Section 2.3 says encoded unreserved characters "should be decoded to their corresponding unreserved characters by URI normalizers," so %7E and ~ are the same URL. But an encoded slash is not a slash, because decoding it would change how the path splits.

PairSame resource?Why
%3a and %3AYesHex digits are case-insensitive
%7E and ~YesTilde is unreserved
%2F and /NoSlash is reserved and structural
%20 and +DependsOnly equivalent in form-encoded data

Anything that keys off a URL string still treats these as different: caches, deduplication jobs, allow-lists and search engines. Google's URL structure documentation says Search supports URLs as defined by IETF STD 66 and that "Characters defined by the standard as reserved must be percent encoded." Encode inconsistently and one page becomes several URLs to a crawler, so keep internal links, canonical tags and your sitemap in the identical spelling. Our slug generator guide covers building clean URLs from the start.

Rule of thumb: normalise before you compare or store. Uppercase the hex digits, decode any encoded unreserved characters, and leave every reserved character exactly as you found it.

Why does a correctly encoded %2F still 404?

Because the server gets a vote, and by default Apache votes no. Its AllowEncodedSlashes directive has three settings:

SettingWhat happens to a request containing %2F
Off (default)Refused with a 404, and the same applies to %5C on systems that treat backslash as a separator
OnAccepted, and the encoded slash is decoded like any other encoded character
NoDecodeAccepted, but the encoded slash is left in its encoded state

Apache strongly recommends NoDecode as a security measure if you need encoded slashes, because decoding them could allow unsafe paths. Better still, move the value into the query string, and test on the real stack.

What happens if the same parameter appears twice?

Nobody agrees. Send ?id=1&id=2 and the value you get depends on your stack. Marco Balduzzi, Carmen Torrano Gimenez, Davide Balzarotti and Engin Kirda measured this in "Automated Discovery of Parameter Pollution Vulnerabilities in Web Applications" (NDSS 2011):

Technology and serverMethod testedWhich value you get
ASP / IISRequest.QueryString("par")All of them, joined into one comma-delimited string
PHP / Apache$_GET["par"]Last
JSP / TomcatRequest.getParameter("par")First
Perl CGI / ApacheParam("par")First
Python / Apachegetvalue("par")All of them, as a list

The danger is an attacker injecting an encoded delimiter into a value you echo into a link, appending a parameter of their own. Scanning more than 5,000 popular websites, the researchers found 1,499 (29.88 percent) with at least one page vulnerable to HTTP Parameter Injection. Ask for parameters explicitly as lists where your language allows it, and encode every value before you build a URL from it.

What mistakes break URLs most often?

Double encoding. Some middleware encodes an already encoded value, so %20 turns into %2520 and your space arrives as the literal text %20. Encode exactly once, at the point you build the URL. It's also an attack: OWASP notes that "By using double encoding it's possible to bypass security filters that only decode user input once." Block ../ and an attacker sends %252E%252E%252F, which a single decode turns into the harmless-looking %2E%2E%2F and a backend decodes again into ../. Decode fully first, then validate.

Encoding the whole URL instead of the parts. encodeURIComponent() over an entire URL escapes the :// and every slash, leaving a string that's no longer a URL.

Assuming encoding is security. Percent-encoding stops a value from breaking URL structure. It does not stop SQL injection. Validate on the server after decoding, every time.

Can bad encoding turn into a security hole?

Yes, because two libraries in your stack can read the same URL differently. Claroty's Team82 and Snyk published joint research on 10 January 2022, Exploiting URL Parsing Confusion, testing 16 URL parsing libraries and sorting the disagreements into five categories, one of them URL-encoded data confusion. The work produced eight vulnerabilities, with the CVEs listed in Snyk's write-up.

The usual pattern: an application validates a URL with one parser, then hands the original string to a component that parses it differently and fetches somewhere else. That gap is how open redirects and server-side request forgery happen. Parse once, use the same parser for checking and fetching, pass the parsed object onward, and never hand-roll URL parsing with a regex.

What do developers ask about URL encoding?

What is URL encoding used for?

URL encoding lets you put arbitrary data inside a URL without breaking its structure. It is what makes search queries, form submissions, API parameters, redirect targets, and non-English text work in a link. Without it, a single ampersand or question mark in user input would split the URL into the wrong pieces and the request would fail or go somewhere unintended.

Which characters need to be URL encoded?

RFC 3986 defines 66 unreserved characters that never need encoding: A to Z, a to z, 0 to 9, plus hyphen, period, underscore and tilde. Everything else should be encoded when it appears as data rather than structure. That includes the 18 reserved characters, spaces, and every non-ASCII character such as accented letters or emoji.

What is the difference between encodeURI and encodeURIComponent?

encodeURI leaves 82 characters untouched because it assumes you are handing it a whole URL that still needs its structure. encodeURIComponent leaves only 71 untouched and encodes the 11 reserved characters that encodeURI preserves. Use encodeURIComponent for individual query values and path segments. Use encodeURI only for a complete URL you already trust.

Why is a space encoded as %20 sometimes and + other times?

Both are correct in their own context. %20 is the percent-encoding of a space defined by RFC 3986 and works anywhere in a URL. The plus sign comes from the older application/x-www-form-urlencoded format used by HTML form submissions, where the WHATWG URL Standard converts spaces to plus. Decode with the same rules the data was encoded with.

Is URL encoding the same as encryption?

No. URL encoding is a public, reversible transformation with no key involved. Anyone can decode a percent-encoded string instantly, and browsers do it automatically. It hides nothing. Encoding exists to keep data intact in transit, not to keep it secret. If you need confidentiality, use HTTPS and real encryption instead.

Try It Yourself

Paste any string into our URL encoder and decoder to see the percent-escapes, or run a query string back the other way to find out what a link is really carrying.

Open URL Encoder →

Sources: cited inline throughout. The core specifications are IETF RFC 3986, January 2005, STD 66 (ietf.org) and the WHATWG URL Standard (url.spec.whatwg.org).