Lesson 245 of 296
What happens when you type a URL: DNS, TCP and TLS
What you will learn
- The full journey of a request, step by step
- How DNS turns a name into an IP address
- TCP and the three-way handshake
- TLS and HTTPS: keys, certificates and the handshake
- What the server and browser do next
On this page
This is one of the most asked interview questions of all time. Answer it as a clear sequence, then go deeper wherever the interviewer wants.
Step 1: the browser parses the URL
https://www.jobprep.example/lessons?id=7
| Part | Value |
|---|---|
| Scheme | https (HTTP over TLS, default port 443) |
| Host | www.jobprep.example |
| Path | /lessons |
| Query | id=7 |
If you typed words without a scheme, the browser may treat them as a search. With HSTS (a header telling the browser "always use HTTPS for this site"), the browser upgrades http:// to https:// itself.
Step 2: DNS: finding the IP address
Computers connect to IP addresses (IPv4 like 203.0.113.10, or IPv6 like 2001:db8::1), not names. DNS (Domain Name System) is the internet's phone book.
- The browser checks its own cache, then the operating system's cache (and the
hostsfile). - If not found, the OS asks a recursive resolver: usually your internet provider's, or a public one such as 1.1.1.1 or 8.8.8.8.
- If the resolver does not have it cached, it walks the hierarchy:
- A root server: "who handles
.example?" - The TLD server for
.example: "who handlesjobprep.example?" - The domain's authoritative name server (for example Route 53 or Cloudflare): "
www.jobprep.exampleis203.0.113.10."
- A root server: "who handles
- The answer is cached at each level for its TTL (time to live).
Common DNS record types:
| Record | Maps |
|---|---|
A / AAAA | Name → IPv4 / IPv6 address |
CNAME | Name → another name (an alias) |
MX | Mail servers for the domain |
TXT | Text, used for verification and email security (SPF, DKIM, DMARC) |
NS | The authoritative name servers |
Why DNS changes "take time": old answers stay cached until their TTL expires. Lower the TTL before planned migrations.
Step 3: TCP connection
TCP (Transmission Control Protocol) gives a reliable, ordered stream of bytes over the unreliable internet: lost packets are re-sent, out-of-order packets are reordered. It starts with the three-way handshake:
Client → Server: SYN "I want to connect"
Server → Client: SYN-ACK "OK, I acknowledge"
Client → Server: ACK "Connected"This costs one round trip before any data is sent. (HTTP/3 uses QUIC over UDP instead, Lesson 246.)
Step 4: TLS handshake (the S in HTTPS)
TLS (Transport Layer Security) encrypts the connection and proves the server's identity.
- Client Hello: supported TLS versions and cipher suites, and the hostname (SNI, Server Name Indication, so one IP can serve many sites).
- Server Hello + certificate: the server picks the settings and sends its certificate: a document that says "this public key belongs to
www.jobprep.example", signed by a Certificate Authority (CA) such as Let's Encrypt. - The browser verifies the certificate: the CA chain leads to a root CA the operating system trusts, the name matches, it has not expired or been revoked.
- Key exchange: client and server use an asymmetric key exchange (Diffie-Hellman over elliptic curves) to agree a shared secret without ever sending it.
- Both sides derive symmetric session keys and from then on encrypt everything with fast symmetric encryption (AES-GCM or ChaCha20).
TLS 1.3 (the current version) completes this in one round trip (and can resume earlier sessions in zero round trips). TLS 1.0 and 1.1 are obsolete.
Why both kinds of encryption: asymmetric (public/private keys) solves "how do we agree a secret with a stranger?" but is slow; symmetric (one shared key) is fast for bulk data.
Step 5: the HTTP request
GET /lessons?id=7 HTTP/2
Host: www.jobprep.example
Accept: text/html
Cookie: sid=...On the way it may pass through a CDN (Lesson 234), which can answer from cache, then a load balancer (Lesson 233), often terminating TLS, then a reverse proxy such as nginx (Lesson 248), then your application server, which may query a cache and a database, and finally returns a response (200 OK with HTML).
Step 6: the browser renders
- Parse HTML into the DOM; parse CSS into the CSSOM (Lesson 86).
- Discover more resources (CSS, JavaScript, images, fonts) and fetch them, often over the same connection.
- Build the render tree, calculate layout, paint, and composite.
- Run JavaScript, which may fetch data and change the page.
- Connections stay open (keep-alive) for later requests.
Short version for interviews
"The browser parses the URL, resolves the hostname through DNS caches and resolvers down to the authoritative name server, opens a TCP connection with a three-way handshake, performs a TLS 1.3 handshake that verifies the certificate and agrees symmetric keys, then sends the HTTP request, which may pass through a CDN, load balancer and reverse proxy to the application and database. The response HTML is parsed into the DOM and CSSOM, more resources are fetched, and the page is laid out, painted and made interactive by JavaScript."
Key words
| Word | Meaning |
|---|---|
| DNS | Turns names into IP addresses |
| Recursive resolver | The DNS server that does the lookups for you |
| Authoritative name server | The server holding a domain's real records |
| TTL | How long a DNS answer may be cached |
| TCP | Reliable, ordered byte streams |
| Three-way handshake | SYN, SYN-ACK, ACK |
| TLS | Encryption and identity for connections |
| Certificate / CA | Proof of a server's identity / the authority that signs it |
| SNI | The hostname sent at the start of TLS |
| HSTS | A header forcing browsers to use HTTPS |
Now prove it
This lesson is complete when you pass the quiz and all three practice levels.