The structure of a URL
Every address on the web is a packed little instruction set — decode it once and read it forever.
A URL is a structured string, not just a name: scheme, optional userinfo, host, port, path, query and fragment each carry a distinct instruction. The browser and server split it apart and use the pieces at different stages — some never leave the browser at all.
Scheme / protocol
The part before :// (like https, http, ftp, mailto) tells the browser which protocol to speak and, implicitly, which default port to use. It is the first thing parsed because it decides everything downstream — https, for example, means run a TLS handshake before any request. Get the scheme wrong and nothing else in the URL can be interpreted.
Userinfo (optional)
Between the scheme and the host you can embed credentials as user:password@, a legacy way to pass HTTP basic-auth details inline. Modern browsers largely strip or warn on this because it is a phishing vector and leaks secrets into logs and history. It is rare in practice but part of the formal syntax, so it helps to recognise it.
Host (domain)
The host is the human-readable name of the machine you want to reach, such as example.com or an IP literal. The browser hands this to DNS, which resolves it to an IP address the network can actually route to. Everything about naming, subdomains and virtual hosting lives here.
Port
After a colon the port selects which listening process on that host should receive the connection — 80 for http and 443 for https by default, so it is usually omitted. You only write it explicitly for non-standard services, like :8080 for a dev server. The port is what lets one machine run many independent servers side by side.
Path
The path, everything after the host/port up to a ? or #, names the specific resource on the server, like /blog/2026/urls. Historically it mapped to files on disk; today a router on the server maps it to code that produces the response. It is the main thing the server uses to decide what to return.
Query string
After a ? comes the query string: a set of key=value pairs joined by &, such as ?sort=asc&page=2. It passes parameters to the server without changing which resource you asked for — filters, search terms, pagination, tracking tags. The server parses it to customise the response for that specific request.
Fragment (#anchor)
The fragment after a # points at a location inside the returned document, like #installation for a heading on the page. Crucially it is handled entirely by the browser and is never sent to the server, which is why single-page apps historically used it for client-side routing. It is the one part of the URL the network never sees.
A URL is an instruction, not just a name
A URL (Uniform Resource Locator) looks like a single opaque string, but it is really a structured little instruction set that tells software exactly how to find and fetch one specific resource. Every character between the https at the front and the #top at the end is placed according to a grammar defined in the URI standard, and both the browser and the server rely on that grammar to split the string into parts and act on each one.
The reason this matters is that the pieces are used at different times, by different actors, for different purposes. Some of the URL never touches the network at all; some of it decides how the connection is even opened. Reading a URL fluently — knowing at a glance which part is the host and which is a query parameter — is one of those small skills that quietly pays off every day, from debugging a broken link to spotting a phishing domain to understanding why a page scrolled somewhere on load.
The canonical full shape is scheme://userinfo@host:port/path?query#fragment. In everyday use most of those parts are optional, which is why a real address like https://example.com/pricing looks so much simpler — the userinfo, port and fragment are just left out and sensible defaults fill in.
Scheme, userinfo, host and port — opening the connection
The first four parts are what the browser needs before it can even send a request; they are about establishing *where* and *how* to connect.
- Scheme (
https://) is parsed first and decides the protocol.httpmeans plain requests,httpsmeans run a TLS handshake first, and other schemes likemailto:orftp:hand off to entirely different machinery. The scheme also implies a default port. - Userinfo (
user:password@) is an optional, largely legacy way to embed HTTP basic-auth credentials directly in the URL. It is discouraged and often stripped by browsers because it leaks secrets into history and logs and is a classic phishing trick (https://paypal.com@evil.examplereally goes toevil.example). - Host is the domain name (
example.com) or IP literal identifying the machine. The browser sends the host to DNS, which returns an IP address the network can route to. - Port (
:443) selects which listening process on that host should answer. Because the scheme implies a default — 80 for http, 443 for https — the port is usually omitted and only written for non-standard services like a:3000dev server.
Together these four answer a single question: which process, on which machine, spoken to in which protocol.
Path, query and fragment — naming what you want
Once a connection is open, the remaining parts describe *what* to fetch and how to present it.
The path (/blog/2026/urls) is everything after the host and port up to a ? or #. It names the specific resource. In the early web it mapped directly to a file on disk, but on a modern server a router matches the path against patterns and dispatches to the code that builds the response. The path is the primary input the server uses to decide what to return.
The query string starts at the ? and is a list of key=value pairs joined by &, for example ?sort=asc&page=2&q=urls. It passes parameters *about* the request without changing which resource you asked for: search terms, filters, pagination, sorting, and tracking tags all live here. Values are percent-encoded so that spaces and special characters survive transport (a b becomes a%20b). The server parses these pairs to customise the response.
The fragment starts at the # (#installation) and is unique: it is handled entirely by the browser and is never sent to the server. Traditionally it points at an element id to scroll to, and single-page applications historically abused it for client-side routing precisely because changing it does not trigger a new server request.
Who uses which part, and when
The single most clarifying idea about URLs is that the parts are consumed at different stages by different actors, and tracing that timeline removes most of the confusion.
- The browser parses the whole string first, then uses the scheme to choose a protocol, the host to run a DNS lookup, and the port (real or default) to open the connection.
- Only the host + path + query are actually placed into the outgoing HTTP request line and
Hostheader — this is what the server receives and routes on. - The fragment stays behind in the browser and is applied *after* the response arrives, to scroll or to drive client-side routing.
- The userinfo, if present, is converted by the browser into an
Authorizationheader rather than being sent as part of the address.
This timeline explains real behaviour you have surely seen: why editing the text after a # reloads nothing, why two URLs that differ only in query parameters can return different pages, and why the port silently disappears from the address bar when it matches the scheme's default.
Why the structure matters in practice
Understanding URL anatomy is not trivia; it underpins a lot of practical engineering and security judgement.
For security, the most important part to identify correctly is the host, because attackers deliberately construct URLs that hide it — burying the real domain behind userinfo, lookalike subdomains, or a confusing path. Knowing that the host is exactly the text between :// (or the last @) and the next /, : or ? is what lets you tell https://apple.com.evil.example/login apart from the real thing.
For web development, the split between path and query drives routing and API design: paths identify resources (/users/42) while query parameters modify or filter them (/users?role=admin), a distinction that maps straight onto REST conventions. Percent-encoding rules decide whether a link with special characters survives copy-paste. And the fact that fragments never reach the server is the historical foundation of client-side routing in single-page apps.
The practical takeaway is to read every URL as the structured command it is. When a link misbehaves, walk the parts in order — is the scheme right, does the host resolve, is the port correct, does the path exist on the server, are the query parameters well-formed, and is the fragment pointing at something real — and the failure almost always announces itself.
Full shape: scheme://userinfo@host:port/path?query#fragment — most parts are optional.
The scheme (https) tells the browser which protocol and default port to use.
The host resolves via DNS to an IP; the port picks the process (default 80 for http, 443 for https).
The path names the resource on the server; the query string passes key=value parameters after a ?.
The fragment (#anchor) is handled entirely by the browser and is never sent to the server.
Quick quiz
Which part of a URL is never sent to the server?
If a URL has no port, how does the browser decide which one to use?
What happens when you type google.com
The single most-asked interview question, animated end to end.
How DNS works
Turning a human name into a machine address by walking a global hierarchy.
Common HTTP status codes
Three digits that tell you, at a glance, exactly how a request went.
HTTP vs HTTPS
The single letter that turns an open postcard into a sealed, verified envelope.