Skip to content

FIELD NOTES / A DECISION GUIDE

URL Spaces: When to Use %20 and When to Use +

On this page
AI-generated illustration; not taken on location · Conceptual comparison of a space represented by %20 in percent-encoding and + in form encoding.
AI-generated illustration; not taken on location · The encoding convention determines how a space is represented.AI-generated illustration

Use %20 to represent a space with percent-encoding. Use + as a space substitution when the applicable form-encoding convention calls for it. A query string does not, by itself, tell you which interpretation the receiving system expects.

The practical decision is therefore larger than choosing a replacement character. Identify the part of the URL that contains your text, establish the receiver’s encoding convention, and preserve characters that belong to the original value. Text such as C++ notes needs particular care because its plus signs are part of the content, while its space needs an encoding representation.

This guide explains the supported character mappings and gives a practical way to select and verify an encoding contract. Examples illustrate intended representations; they do not establish the behavior of every library, framework, or server. Where decoding details depend on the receiver, use a small test with a known expected value before relying on the result.

Why spaces appear as %20 or +

The two representations come from different conventions. Percent-encoding represents a space as %20. Form encoding adds substitutions, including representing a space with +. That distinction explains why the same original words can have different encoded spellings.

For example, consider the original text blue notebook:

Original text Convention being illustrated Representation of the space
blue notebook Percent-encoding blue%20notebook
blue notebook Form space substitution blue+notebook

These examples isolate the space. They are not a complete specification for transforming every character that could appear in a value. In particular, do not extend the second example into a rule that every plus sign means a space everywhere.

Choose a convention before comparing strings

If two encoded strings look different, first ask whether they were produced under the same contract. Comparing their spelling alone does not establish whether the intended original text differs. Equally, replacing %20 with + for appearance alone is a poor editing step unless the receiver expects that convention.

For a developer workflow, label the operation precisely: “percent-encode this value” or “encode this value using the receiver’s form convention.” A generic instruction such as “make this URL safe” leaves the central choice unresolved.

The useful question is not which representation looks cleaner. It is which representation the next component agrees to interpret as the original space.

Choose the convention for the URL component

Start by locating the text you are encoding. Is it intended for a path segment, a query value, or form data? Treat that answer as context for selecting the appropriate operation, rather than running an unspecified encoder over a complete URL.

The character ? indicates the beginning of a query string. It helps identify structure, but its presence does not establish the encoding contract for the values that follow. You still need to know whether the receiving system specifies form encoding or another agreed treatment.

Intended destination Decision to make before encoding
A path segment Confirm the component encoder expected by the URL builder. Do not import a form space substitution without checking.
A query value Check whether the receiver specifies form encoding for that value.
Form data Select the form encoder required by the receiving interface and verify its character handling.

Make the interface agreement explicit

For a query value containing blue notebook, record whether the producer should submit the percent-encoded spelling or the form-style spelling shown earlier. Then verify that the receiver recovers the intended text.

If documentation merely says “URL encoded,” ask for a concrete example containing both a space and a literal plus sign. That example makes the unresolved convention visible without requiring assumptions about the implementation.

When integrating several components, keep the agreement close to the boundary where the value is handed over. A clearly named encoder at that boundary is easier to review than scattered character replacements whose purpose must be reconstructed later.

Preserve a literal plus sign

A plus sign can belong to the original text. In C++, both plus signs are content; in a+b, the plus sign is also content. Preserve that distinction when selecting an encoding convention that uses + to stand for a space.

The supported percent-encoded representation of a literal plus sign is %2B. Applying the stated space and plus mappings gives these illustrative spellings:

Original value Using %20 for spaces Using + for spaces, with literal plus signs represented as %2B
C++ C%2B%2B C%2B%2B
a+b a%2Bb a%2Bb
C++ notes C%2B%2B%20notes C%2B%2B+notes
a+b notes a%2Bb%20notes a%2Bb+notes

These are character-mapping examples, not proof of a particular receiver’s decoding behavior. Confirm that the chosen encoder and receiver implement the intended agreement before adopting the strings as integration fixtures.

Test the meaning, not just the appearance

Use C++ notes as a practical test input because it contains both kinds of character. The expected recovered value should contain two literal plus signs and one space, exactly as entered.

A test using only blue notebook checks space handling but leaves literal-plus handling unexamined. Conversely, testing only C++ leaves the space convention unresolved. Keep both cases, plus the combined case, when reviewing an integration.

Avoid an unqualified instruction to “replace plus signs with spaces.” First establish whether those characters are encoded space substitutions or literal input.

Encode values while preserving URL structure

Construct the URL from its parts and treat user input as literal characters. This gives each piece a clear role: some characters belong to the URL structure, while others belong to a value supplied by the user.

Consider a search value of bread & butter. The ampersand is part of the requested text. If your URL builder also uses an ampersand between query fields, distinguish that structural use from the character inside the search value. The intended search must remain the complete phrase.

A practical construction sequence

  1. Keep bread & butter as the original search value.
  2. Identify the query field that will contain it.
  3. Confirm the receiver’s encoding convention for that field.
  4. Pass the value through the appropriate component-building operation.
  5. Check that the receiver obtains the complete original phrase and that other intended fields remain separate.

This example deliberately does not supply an ampersand escape sequence. Select that treatment through the component encoder’s documented contract rather than inferring a complete character table from the space examples.

The same separation helps during review. Ask which characters were supplied by the URL-building code and which arrived as user input. A structural ? marks the beginning of the query; a character appearing inside the original search text needs to remain part of that text through the agreed transformation.

Keep the original value available while constructing the URL. It provides a clear comparison target when checking whether the receiver interpreted the value as intended.

Decode with the matching convention

Choose a decoder from the producer’s encoding contract. If the producer uses a form convention, verify the decoder’s form-substitution behavior. If the producer specifies percent-encoding, verify the corresponding percent-decoding behavior. Do not infer either choice solely from seeing a query string.

The supported mappings identify %20 as an encoded space and %2B as an encoded literal plus sign. They do not provide a complete normative decoding algorithm. In particular, the exact handling of raw + and the order of transformations should be checked against the selected decoder’s documentation and observed output.

Use a small decoder test matrix

Input to investigate What to establish
blue+notebook Does the selected mode interpret the raw plus as a space substitution or retain it?
blue%20notebook Does the mode recover the intended space under the agreed contract?
a%2Bb Does the mode preserve the intended literal plus in the recovered value?
C%2B%2B+notes Does the full form-style example recover C++ notes?

Write down the expected result before running each test. Otherwise, an output that merely looks readable can conceal a change in meaning.

Avoid assembling a decoder from ad hoc replacements without an established algorithm. Ask whether the chosen operation already performs every required substitution and whether another layer also decodes the value.

If a case fails, inspect the producer, decoder mode, and transformation boundaries. Changing the input until one example passes does not resolve an unclear agreement between those components.

Avoid repeated encoding and ambiguous input

Before encoding a value, establish what the input represents. It might be original text, a previously encoded component, or text copied from a complete URL. Assign responsibility for the next transformation instead of guessing from its appearance.

The distinction matters for percent signs. The encoded representation of a literal percent character is %25. But seeing %20 in an input does not tell you whether the user intended the three visible characters or supplied an encoded space. That is an input-contract question.

Record intent before transformation

Example input Clarification to record
blue notebook This is original text containing a space. Which encoding convention applies next?
blue%20notebook Is this already encoded, or is %20 part of the literal text?
50% complete The percent sign belongs to the original value. Which component encoder will handle it?
Text containing Unicode characters Which character-encoding agreement and component operation do the producer and receiver require?

For Unicode text, obtain a documented example from the receiving interface and verify recovery of the original characters. The space and plus mappings alone do not establish a complete Unicode conversion procedure.

Check each handoff once

Maintain a short record of the original value, the operation applied, and the value handed to the next component. Check whether a URL builder expects raw text or an already encoded component, and whether a receiving layer has already decoded it before your code runs.

Include literal percent signs, spaces, plus signs, and Unicode text in your verification set. Establish expected results from the agreed contract rather than inventing transformations for uncertain cases.

A reliable workflow makes three decisions explicit: what the input means, which component receives it, and which layer owns the next encoding or decoding step.