Skip to content
Back to all articles
Developer4 min readNovember 20, 2026

URL Encoding Explained: %20, Plus Signs and encodeURIComponent

Why URLs need percent-encoding, which characters are safe, versus +, encodeURI versus encodeURIComponent, and how to encode in JavaScript, Python and PHP.

URL Encoding Explained: %20, Plus Signs and encodeURIComponent article
In this guide
  1. Why URLs need encoding
  2. How percent-encoding works
  3. %20 or +?
  4. encodeURI vs encodeURIComponent
  5. In Python and PHP
  6. Double encoding
  7. Practical examples
  8. Not the same as Base64 or HTML entities

If you have ever seen %20 in a link or had a URL break because of an & in a search term, you have met URL encoding. It is simple once you know the rules, and getting it wrong causes some of the most confusing bugs on the web. This guide covers the rules and the common mistakes. To encode or decode something right now, use the free URL Encode / Decode tool.

Why URLs need encoding

A URL can only contain a limited set of characters, and some of those have special jobs:

CharacterJob in a URL
/Separates path segments
?Starts the query string
&Separates query parameters
=Separates a parameter name from its value
#Starts the fragment
:Separates the scheme (https) and port

So if a search term contains & — say “chai & samosa” — and you put it in a URL unencoded, ?q=chai & samosa is read as a parameter q=chai plus a second, broken parameter. Encoding turns the special characters into harmless codes.

How percent-encoding works

Each character that is not allowed is replaced by % followed by two hexadecimal digits — the value of the byte. A space is byte 32, which is 20 in hex, so it becomes %20.

Characters outside basic English are first converted to UTF-8 bytes, then each byte is encoded:

CharacterUTF-8 bytesEncoded
space20%20
&26%26
éC3 A9%C3%A9
₹E2 82 B9%E2%82%B9
न (Hindi “na”)E0 A4 A8%E0%A4%A8

The characters that never need encoding are the unreserved ones: letters A–Z and a–z, digits 0–9, and - . _ ~.

%20 or +?

Both are used for a space, in different places:

  • In a URL path and in modern encoding functions, a space is %20.
  • In HTML form submissions (application/x-www-form-urlencoded), a space is +, and a real plus sign is sent as %2B.

Most servers accept both in a query string, which is why the mix-up often goes unnoticed — until a phone number like “+91 98765 43210” arrives as “ 91 98765 43210” because a + was read as a space. When decoding form data, convert + to a space first; when sending a plus sign, make sure it is encoded as %2B.

encodeURI vs encodeURIComponent

JavaScript has two functions, and choosing the wrong one is the most common mistake:

  • encodeURIComponent is for one piece of a URL — a single query value, a path segment, a URL passed as a parameter. It encodes & = ? / # : and more, so the piece cannot break the URL.
  • encodeURI is for a whole URL. It leaves : / ? # & = alone so the URL keeps its structure, and encodes only characters that are never allowed, such as spaces and non-English letters.
const q = 'chai & samosa';
'https://example.com/search?q=' + encodeURIComponent(q);
// https://example.com/search?q=chai%20%26%20samosa

encodeURI('https://example.com/my page?q=café');
// https://example.com/my%20page?q=caf%C3%A9

The URL Encode / Decode tool offers both as Component and Full URL modes and gives the same output as these functions.

Better still, let the language build the query for you:

const params = new URLSearchParams({ q: 'chai & samosa', page: 2 });

Note that URLSearchParams follows the form rules and writes spaces as +.

In Python and PHP

from urllib.parse import quote, quote_plus, urlencode
quote('chai & samosa', safe='')    # chai%20%26%20samosa
quote_plus('chai & samosa')         # chai+%26+samosa
urlencode({'q': 'chai & samosa'})   # q=chai+%26+samosa
rawurlencode('chai & samosa');  // chai%20%26%20samosa
urlencode('chai & samosa');     // chai+%26+samosa
http_build_query(['q' => 'chai & samosa']);

Double encoding

If you see %2520 in a URL, the text was encoded twice: the first pass turned a space into %20, and the second turned the % into %25. The server then receives the literal text “%20” instead of a space. It usually happens when code encodes a value and a library encodes it again. Encode once, at the point where you build the URL. To repair a double-encoded value, decode it twice.

Practical examples

  • WhatsApp click-to-chat: https://wa.me/919876543210?text= followed by the message encoded as a component.
  • Redirect after login: /login?next= followed by the full return URL encoded as a component, so its own ? and & do not leak into the outer URL.
  • Campaign tracking: UTM values with spaces or & must be encoded; the UTM Builder does this for you.

Not the same as Base64 or HTML entities

  • URL encoding makes text safe inside a URL.
  • Base64 turns any data, including binary, into text — see Base64 Encode / Decode.
  • HTML entities like & make characters safe inside HTML — see our guide to HTML entities.
Was this article helpful?

Found this guide useful?

Share it with someone who is struggling with the same problem.

Free tool · No sign-up

URL Encode / Decode

Percent-encode text for URLs or decode %20-style links. Component, Full URL and Form data modes, line by line, with URL parts and editable parameters.

Open tool

Written by

Hemant Adhikari HemantInsights

Senior Software Engineer · Developer of Toolyconvert

I’m a senior software engineer from Dehradun, India, building websites since 2014. I designed and developed Toolyconvert, from the Next.js front end and headless WordPress back end to the tools themselves, and I review every guide before it goes live.