1. Home
  2. Blog
  3. Software Development

Software Development

URL Encoding Explained: %20, Plus Signs, UTF-8 and the Double Encoding Bug

URL encoding, also called percent encoding, turns characters that are unsafe in a URL into a percent sign and two hex digits. Learn which characters need it, why a space can become %20 or a plus, how emoji become UTF-8 bytes, and which Python and JavaScript functions to use.

9 min read
URL encoding explained: percent encoding, plus signs, UTF-8 and double encoding

Key takeaways

  • URL encoding replaces a byte with % plus two hex digits. A space is byte 0x20, so it becomes %20.
  • Non-ASCII text is first converted to UTF-8 bytes: é becomes %C3%A9 and the coffee emoji becomes %E2%98%95.
  • A plus sign means a space only in form-style query strings. In a path, + is a literal plus.
  • Encoding twice turns %20 into %2520. That double encoding bug is the most common URL encoding mistake.

You search for “QA & Dev” on a site and the results page shows only “QA”. You share a link to a file called “report 2026.pdf” and it 404s. You pass an email address with a plus sign to an API and the plus turns into a space. All three are URL encoding problems. A URL is only allowed to contain a small set of characters, and everything else must be encoded in a way both sides agree on.

This guide explains the rules and shows them with code. Every output below came from real runs with Python 3.13.6 and Node.js 24.22.1. For background on how text becomes bytes, see our UTF-8 encoding guide.

What is URL encoding?

URL encoding, formally called percent encoding in RFC 3986, represents a byte as a percent sign followed by its value in two hexadecimal digits. The space character has byte value 32, which is 20 in hex, so it becomes %20. An ampersand is 0x26, so it becomes %26. Decoding reverses the process.

The percent sign itself is the escape character, so a literal percent must also be encoded, as %25. That one rule is behind the double encoding bug later in this guide.

Why URLs need encoding

Some characters have a job inside a URL. Look at this one:

https://example.com/search?q=tea&page=2#top

The ? starts the query, & separates parameters, = splits names from values, # starts the fragment and / separates path segments. If a search term contains &, the server reads it as the start of a new parameter. That is exactly why “QA & Dev” became “QA” in the example above. Encoding the value turns & into %26, which the server treats as data. Our guide to HTTP methods shows where query strings fit into a request.

Which characters must be encoded?

Group Characters Rule
Unreserved A-Z a-z 0-9 - . _ ~ Never need encoding
Reserved : / ? # [ ] @ ! $ & ' ( ) * + , ; = Encode when used as data inside a component
Everything else Space, ", <, %, non-ASCII letters, emoji Always encode

The key phrase is “used as data”. A slash that separates path segments must stay a slash, but a slash inside a single value, such as a file name, must become %2F. That is why you encode each piece of a URL separately rather than encoding a whole URL at the end.

Non-ASCII characters and UTF-8

Percent encoding works on bytes, not characters. Text outside ASCII is first converted to UTF-8, then each byte is encoded:

>>> "café ☕".encode("utf-8")
b'caf\xc3\xa9 \xe2\x98\x95'
>>> quote("café ☕")
'caf%C3%A9%20%E2%98%95'

The letter é takes two bytes, C3 A9, and the coffee emoji takes three, E2 98 95. Browsers often display the decoded characters in the address bar, but what travels over the network is the encoded form.

A space: %20 or plus?

Both are correct, in different places:

  • %20 is the standard percent encoding and works everywhere in a URL.
  • + means a space only in the application/x-www-form-urlencoded format, used by HTML forms and most query strings.

The trap is decoding. Python’s two decoders show the difference clearly:

>>> unquote("a+b%20c"), unquote_plus("a+b%20c")
('a+b c', 'a b c')

If your data can contain a real plus sign, such as a phone number or an email alias like name+tag@example.com, it must be sent as %2B in a query string, or the server will read a space.

URL encoding in Python

The urllib.parse module has everything you need:

from urllib.parse import quote, quote_plus, unquote
s = "QA & Dev/Ops 100%"
print(quote(s))
print(quote(s, safe=""))
print(quote_plus(s))
QA%20%26%20Dev/Ops%20100%25
QA%20%26%20Dev%2FOps%20100%25
QA+%26+Dev%2FOps+100%25

Notice the slash. quote keeps / by default, because it was designed for paths. That is wrong for a single value such as a file name or an ID, so pass safe="" to encode it. quote_plus uses plus for spaces and encodes slashes, which suits form values. The requests library encodes query parameters for you when you pass a params dictionary, as our Python requests guide shows.

URL encoding in JavaScript

JavaScript has two built-in functions with very different jobs:

encodeURIComponent("QA & Dev/Ops 100%")
// 'QA%20%26%20Dev%2FOps%20100%25'

encodeURI("https://example.com/a b?x=1&y=café")
// 'https://example.com/a%20b?x=1&y=caf%C3%A9'

encodeURIComponent is for a single value: it encodes /, ?, & and =. encodeURI is for a whole URL: it leaves those structural characters alone, so it cannot protect a value that contains &. In practice, use encodeURIComponent for every value you insert into a URL. Both leave ! ' ( ) * ~ - . _ unencoded. Avoid the old escape() function; it produced caf%E9 for “café”, a Latin-1 encoding that modern servers will not decode as UTF-8.

Building query strings safely

Better than encoding by hand is letting a library build the whole query string:

# Python
urlencode({"q": "a+b c", "tag": ["x", "y"]}, doseq=True)
# 'q=a%2Bb+c&tag=x&tag=y'

// JavaScript
const u = new URL("https://example.com/search");
u.searchParams.set("q", "tea & ☕");
u.href
// 'https://example.com/search?q=tea+%26+%E2%98%95'

Both encoded the real plus as %2B and the space as +, so the round trip is safe. When reading, use the matching parser: Python’s parse_qs("q=a+b%2Bc") returned {'q': ['a b+c']}, and JavaScript’s new URLSearchParams("q=a+b%2Bc").get("q") returned 'a b+c'. The same advice applies to the fetch API: build the URL with URL and searchParams rather than string concatenation.

Tip: never build URLs by joining strings with user input. Use URLSearchParams, urlencode or your HTTP client’s params option, and encode each path segment on its own.

The double encoding bug

If you encode a value that is already encoded, the percent signs get encoded too:

once  = quote("report 2026.pdf")   # 'report%202026.pdf'
twice = quote(once)                # 'report%25202026.pdf'
unquote(twice)                     # 'report%202026.pdf'

%20 became %2520, because % was encoded as %25. After one decode, the server sees the literal text report%202026.pdf and returns a 404. This usually happens when one layer of code encodes a value and another layer, such as an HTTP client, encodes it again. The rule is simple: encode exactly once, at the point where you build the URL, and pass raw values everywhere else. If you see %25 followed by two hex digits in your logs, you almost certainly have double encoding.

What happens with broken input

Malformed percent sequences behave differently by language. We decoded %E2%98, which is an incomplete emoji, and %zz, which is not hex at all:

# Python
unquote("%E2%98")   # '�'  (replacement character)
unquote("%zz")      # '%zz'     (left as is)
unquote("%E2%98", errors="strict")
# UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 0-1: unexpected end of data

// JavaScript
decodeURIComponent("%E2%98")
// URIError: URI malformed

Python quietly replaces bad bytes with the replacement character, while JavaScript throws. Neither is wrong, but your code must handle it: wrap decodeURIComponent in try and catch for any value that comes from users. JavaScript also threw URIError when we tried to encode a lone surrogate character, which can appear when a string is cut in the middle of an emoji.

Encoding is not security

Percent encoding makes data travel safely through a URL. It does not make the data safe to use. An attacker can encode ../ as %2E%2E%2F to try path traversal, or encode a script tag to get past a naive filter. Always decode first, then validate, then use the value. Escape it again for the place it lands: HTML escaping for pages and parameterised queries for SQL. Encoding is also not encryption: Base64 and percent encoding are both reversible by anyone.

Testing tips

  • Test inputs with a space, &, +, %, /, #, an accented letter and an emoji. Most encoding bugs show up with that one list.
  • Check the round trip: what you send should equal what the server stores and returns.
  • Search API logs for %25 to catch double encoding.
  • Send malformed sequences such as %zz and %E2 and check the API returns a clear 400 rather than a 500. Our what is an API guide covers status codes in context.

Cheat sheet

Character Encoded Character Encoded
space %20 or + & %26
+ %2B = %3D
/ %2F ? %3F
# %23 % %25
: %3A @ %40
é %C3%A9 ☕ %E2%98%95

Final thoughts

URL encoding comes down to a few rules: encode each value once, at the moment you build the URL; use component-level functions such as encodeURIComponent or quote(value, safe=""); remember that plus means space only in form-style query strings; and treat decoded input as untrusted. Follow those and spaces, ampersands, plus signs and emoji will all survive the trip intact.

Frequently asked questions

What does %20 mean in a URL?

It is an encoded space. The space character has byte value 32, which is 20 in hexadecimal, and percent encoding writes a byte as a percent sign followed by two hex digits.

Should a space be encoded as %20 or a plus sign?

Use %20 anywhere in a URL. A plus sign means a space only in form-style query strings, so a path or a value that may contain a real plus should use %20 and %2B.

What is the difference between encodeURI and encodeURIComponent?

encodeURI is for a whole URL and leaves characters such as slash, question mark and ampersand alone. encodeURIComponent is for a single value and encodes them, so use it for anything you insert into a URL.

Why does %2520 appear in my URL?

The value was encoded twice. The first pass turned a space into %20, and the second pass encoded the percent sign as %25. Encode only once, where the URL is built.

Is URL encoding the same as encryption?

No. It only makes characters safe to place in a URL and anyone can decode it. Always validate decoded values and use HTTPS to protect data in transit.

Keep learning

Work with Stack Quora

Need help with testing, WordPress or SEO?

We help teams ship better software and grow their sites. Tell us what you are working on and we will suggest a clear next step.

Keep reading

More guides on testing, AI & modern development

Enjoyed this article? Pick a topic and jump straight into our newest tutorials.

Artificial Intelligence

Levenshtein Distance: Formula, Worked Table and Python Code

Levenshtein distance explained: the edit operations, the dynamic programming table for kitten and sitting, Python code with two-row memory, normalised…

Read article →
Software Development

URL Encoding Explained: Spaces, Plus Signs and UTF-8

URL encoding explained with tested Python and JavaScript code: percent encoding, reserved characters, %20 vs plus, UTF-8 bytes, encodeURI vs…

Read article →
DevOps

Gitignore: Patterns, Negation and Fixing Tracked Files

A tested gitignore guide: pattern rules, leading and trailing slashes, negation with !, the ignored parent folder trap, git check-ignore…

Read article →
Software Testing

Acceptance Criteria: Given When Then Examples and Checklist

How to write acceptance criteria testers can run: rule-based and Given When Then formats, a worked discount code example turned…

Read article →
Software Testing

State Transition Testing: Diagram, Table and Example

State transition testing explained with a login lockout example: states, events, the diagram, the state table, valid and invalid transitions,…

Read article →
Databases & SQL

Second Highest Salary in SQL: 5 Tested Ways and the Tie Trap

Find the second highest salary in SQL five ways: MAX subquery, LIMIT OFFSET, DENSE_RANK, a correlated subquery and per department,…

Read article →
Databases & SQL

SQL ROW_NUMBER: Top N per Group, Dedupe and Pagination

SQL ROW_NUMBER explained with tested queries: PARTITION BY, top N per group, deleting duplicates, pagination, the tie trap and how…

Read article →
Software Development

JavaScript Set: Union, Intersection and Removing Duplicates

JavaScript Set explained with tested examples: add, has, delete, deduplicating arrays, the new union and intersection methods, equality rules and…

Read article →
Test Automation

Python Unittest: Assert Methods, setUp and Mocks With Examples

A practical Python unittest tutorial: TestCase, assert methods, setUp and tearDown, subTest, skips, expected failures and mock, with a test…

Read article →
Software Development

Python Map and Filter: Examples vs List Comprehensions

Python map and filter explained with tested examples: lazy map objects, multiple iterables, filter(None), chaining, and a timed comparison with…

Read article →
Artificial Intelligence

Jaccard Similarity: Formula, Python, MinHash

Jaccard similarity measures overlap between two sets as intersection over union. Work the formula, compute it in Python for words…

Read article →
Software Development

Unix Timestamp Explained: Seconds vs ms

A Unix timestamp counts seconds since 1 January 1970 UTC. Learn seconds vs milliseconds, converting in Python, JavaScript and SQL,…

Read article →
DevOps

Git Hooks: Pre-commit and Commit-msg Examples

Git hooks run scripts at key moments such as commit and push. See tested pre-commit, commit-msg and prepare-commit-msg hooks, sharing…

Read article →
Test Automation

API Testing in Python: Pytest + Requests Suite

Build an API testing suite in Python with pytest and requests: fixtures, status codes, headers, JSON schema validation, CRUD flows,…

Read article →
Software Testing

Test Design Techniques: 9 Methods + Examples

Test design techniques help you write fewer tests that catch more bugs. Learn 9 black-box, white-box and experience-based methods with…

Read article →
Databases & SQL

SQL Temporary Table: Create, Use and Drop It

SQL temporary tables store interim results for one session. Learn syntax for SQL Server, PostgreSQL, MySQL, Oracle and SQLite, session…

Read article →
Databases & SQL

SQL CROSS JOIN: Every Combination + Examples

SQL CROSS JOIN returns every combination of rows from two tables. See the row math, product variants, calendar grids that…

Read article →
Software Development

JavaScript Date: Format, Parse, Timezone Bugs

JavaScript Date explained with tested Node.js code: zero-based months, the date-only UTC parsing trap, toISOString, getTimezoneOffset, Intl formatting, date math…

Read article →
Software Development

Python Requests: GET, POST, Timeouts, Retries

Python requests explained with code tested against a local API: GET with params, POST json vs data, headers and auth,…

Read article →
Artificial Intelligence

TF-IDF Explained: Formula and Worked Example

TF-IDF scores a word by how often it appears in a document and how rare it is across all documents….

Read article →
DevOps

Git Tag: Create, Push and Delete Release Tags

Git tag explained with tested commands: annotated vs lightweight tags, listing and sorting, pushing with follow-tags, deleting local and remote…

Read article →
Test Automation

Pytest Coverage: pytest-cov and Branch Gaps

Measure pytest coverage with pytest-cov: term-missing reports, branch coverage, HTML reports, pyproject settings and a fail-under gate for CI, with…

Read article →
Software Testing

Error Guessing in Testing: Checklist + Demo

Error guessing uses tester experience to predict where code breaks. Get a ready checklist of risky inputs, a step by…

Read article →
Databases & SQL

SQL LAG and LEAD: Compare Rows, 5 Examples

SQL LAG and LEAD read values from the previous or next row without a self join. Five tested examples: change,…

Read article →
Databases & SQL

SQL STRING_AGG: Combine Rows Into One String

SQL STRING_AGG joins values from many rows into one string per group. See syntax for PostgreSQL, SQL Server, MySQL GROUP_CONCAT,…

Read article →
Artificial Intelligence

BM25 Explained: How Keyword Search Ranks Results, With Python Code and Hybrid Search

BM25 explained with a pure Python implementation we ran: the formula, IDF, term saturation, the k1 and b parameters, why…

Read article →
DevOps

Git Bisect Explained: Find the Commit That Broke Your Code, Manually or Automatically

Git bisect explained with a tested repository: find the one bad commit among 41 in 5 test runs, automate it…

Read article →
Test Automation

pytest Markers Explained: Custom Marks, skip, skipif, xfail and -m Filters

pytest markers explained with a tested suite: register custom marks, run only smoke tests with -m, combine filters with and,…

Read article →
Software Testing

Positive vs Negative Testing: Differences, 24 Real Test Cases and a Checklist

Positive vs negative testing explained with a real signup form: 6 positive and 18 negative test cases run in pytest,…

Read article →
Artificial Intelligence

Cosine Similarity Explained: Formula, Worked Example and Python Code

Cosine similarity explained simply: the formula, a worked example by hand, pure Python and NumPy code, cosine vs Euclidean distance…

Read article →
DevOps

Git Squash Commits: 4 Easy Ways, Tested Step by Step (rebase -i, reset, merge)

Git squash commits explained with 4 tested methods: interactive rebase, reset –soft, merge –squash and fixup with autosquash. Before-and-after logs,…

Read article →
Test Automation

pytest parametrize Explained: 7 Patterns with Tested Examples

pytest parametrize explained with 7 tested patterns: basic cases, readable ids, stacked decorators, pytest.param with xfail and skip, indirect fixtures…

Read article →
Software Testing

Retesting vs Regression Testing: 8 Key Differences with a Real Bug Fix Example

Retesting vs regression testing explained with a real bug fix run in pytest: retesting confirmed the fix, the regression run…

Read article →
Artificial Intelligence

RAG Chunking Strategies Explained: Fixed, Overlap, Sentence, Recursive and Headings, Measured

RAG chunking strategies compared on one document with tiktoken 0.14: fixed-size, overlap, sentence packing, recursive splitting and heading-based chunks, measuring…

Read article →
DevOps

Git Stash Explained: Save, Apply, Pop and Untracked Files, Tested

Git stash explained with commands we ran on Git 2.56: push with a message, untracked files, list and show, apply…

Read article →
Test Automation

Test Doubles Explained: Dummy, Stub, Spy, Mock and Fake, with Tested Python Code

Test doubles explained with one Python example run in pytest 9.2: dummy, stub, spy, mock and fake, when to use…

Read article →