HTTPS, TLS & TCP — a Secure Request End to End

Follow one request from the TCP handshake, through the TLS handshake, to an encrypted request and response — every step a browser and server actually take.

A secure request in 30 seconds

  • Resolve: the browser turns the hostname into an IP with DNS.
  • TCP handshake: a 3-way SYN / SYN-ACK / ACK sets up a reliable, ordered byte stream.
  • TLS handshake: client and server agree on a cipher, the server proves its identity with a certificate, and they derive a shared secret key — without ever sending that key on the wire.
  • Encrypted request/response: the HTTP request and response now travel as ciphertext over the TCP connection; only the two endpoints can read them.
  • Keep-alive: the expensive handshakes are amortized — many requests reuse one warm connection.
  • The guarantees: confidentiality (nobody can read it), integrity (nobody can tamper undetected), and authentication (you're really talking to the right server).

Mailing a locked box

Imagine mailing a confidential document. First you need the recipient's address (DNS). Then you need a reliable courier who guarantees the pages arrive in order and none go missing (TCP). But the courier could still read your pages — so before sending anything sensitive, you and the recipient agree on a lockbox only the two of you can open, and you verify you're really dealing with the right person and not an impostor (TLS). Only then do you send the document, locked (encrypted HTTP). Every secure web request follows exactly this sequence, and it's worth walking through each step because interviewers love it and because almost every production system depends on getting it right.

Step 0 — Resolve the name

Before any connection, the browser needs an IP address. It asks the DNS resolver to turn example.com into something like 93.184.216.34 (covered in depth in DNS). This step involves no encryption yet — it's just the lookup that tells the browser where to open a connection.

Step 1 — The TCP handshake (the reliable pipe)

TCP gives us a reliable, ordered byte stream — the foundation TLS and HTTP sit on top of. Before any data flows, the two sides perform a three-way handshake to agree they're both ready and to sync their sequence numbers:

  • SYN — the client sends a packet: 'I'd like to talk; here's my starting sequence number.'
  • SYN-ACK — the server replies: 'Got it, I acknowledge yours; here's mine.'
  • ACK — the client acknowledges the server's number. The connection is now established.
The TCP three-way handshake (pseudocode)
Client                               Server
  |  --- SYN  seq=x          --->      |   # 'let's talk, my seq is x'
  |  <-- SYN-ACK seq=y ack=x+1  ---    |   # 'ok; my seq is y, I got x'
  |  --- ACK  ack=y+1        --->      |   # 'got yours too'
  |                                    |
  |======== connection established ====|   # reliable ordered byte stream

# Cost: one full round trip (RTT) before a single byte of data moves.
# This is why opening connections is expensive and why we reuse them.

The key takeaway: a handshake costs a round trip before any real data moves. Over a long-distance link that's tens of milliseconds of pure setup — which is exactly why reusing connections (keep-alive) matters so much.

SYN / SYN-ACK / ACK — one round trip to open a reliable stream.

Why TCP alone isn't enough — the case for TLS

TCP is brilliant at what it does, but notice what it doesn't do. A plain TCP connection is like a reliable postcard service: your message always arrives, in order, undamaged — but anyone handling the postcard can read it, and a dishonest courier could rewrite it before delivering. TCP guarantees delivery, not privacy. Every byte travels in the clear across routers, ISPs, coffee-shop Wi-Fi, and corporate proxies, and any of them can read or alter it. That's fine for public content, but catastrophic for a password, a payment, or a session token.

TLS is the layer that fixes exactly the three things TCP leaves open:

Threat on a raw TCP linkWhat could happenWhat TLS adds
EavesdroppingAnyone on the path reads your password, token, or data.Confidentiality — the payload is encrypted; only the two endpoints can read it.
TamperingA proxy silently changes an amount, a URL, or injects content.Integrity — every record is authenticated; tampering is detected and rejected.
ImpersonationYou connect to an attacker pretending to be the real server.Authentication — the certificate proves you're talking to the genuine server.

So TLS doesn't replace TCP — it rides on top of it. TCP carries the bytes reliably; TLS makes those bytes private, tamper-evident, and provably from the right server. You almost always want both: the reliability of TCP and the security of TLS.

HTTPS vs 'TCP + TLS' — same layers, different names

This trips people up constantly, so let's make it precise. HTTPS is not a separate protocol stack — it's just HTTP running inside a TLS tunnel that runs over TCP. Read the name literally: HTTP-S = HTTP Secure. The layers stack like this:

HTTPS is HTTP layered over TLS layered over TCP (pseudocode)
   +------------------------------+
   |  HTTP   (GET /account ...)   |   <- your application's request
   +------------------------------+
   |  TLS    (encrypt + verify)   |   <- privacy, integrity, identity
   +------------------------------+
   |  TCP    (reliable, ordered)  |   <- delivers the bytes in order
   +------------------------------+
   |  IP     (routing, addresses) |   <- gets packets to the host
   +------------------------------+

# HTTPS  =  HTTP  +  TLS  +  TCP   (just these layers, stacked)
# Plain  =  HTTP  +  TCP           (no TLS layer -> readable on the wire)

So 'HTTPS' and 'HTTP over TCP+TLS' describe the same thing — HTTPS is the web's specific, named combination of those layers (conventionally on port 443). 'TCP + TLS' is the more general building block: any application protocol can be wrapped in TLS over TCP, not just HTTP. A few concrete cases make the distinction clear:

You're securing...The stackCommon name
A website / web APIHTTP over TLS over TCPHTTPS (port 443)
Email submissionSMTP over TLS over TCPSMTPS / STARTTLS
A database connectionPostgres/MySQL wire protocol over TLS over TCP'SSL mode' on the DB
A custom microservice RPCYour protocol over TLS over TCP (or gRPC over HTTP/2 over TLS)mTLS service-to-service
A raw secure socketYour bytes over TLS over TCP'a TLS socket'

The takeaway: TCP + TLS is the generic secure-channel recipe; HTTPS is that recipe applied to HTTP. When you need to secure web traffic specifically, you use HTTPS. When you need to secure non-HTTP traffic — a database link, a message-queue connection, a bespoke RPC — you reach for the same TCP + TLS foundation directly, without HTTP in the picture.

When do you need both HTTP(S) and TCP + TLS?

A natural question: if HTTPS is HTTP over TCP+TLS, when would you ever think about them separately? In practice it comes down to what you're transporting and where encryption begins and ends:

  • Securing a browser-to-server web request: you want HTTPS. You don't configure TCP and TLS by hand — the browser and server library assemble HTTP + TLS + TCP for you when the URL starts with https://.
  • Securing service-to-service calls inside your system (zero-trust): you want TCP + TLS (often mutual TLS) on every hop — sometimes carrying HTTP, sometimes a raw RPC. Here you think about the TLS layer explicitly because you manage the certificates on both ends.
  • Securing non-HTTP traffic: a database driver, a Kafka client, an SSH-like tunnel — these are TCP + TLS without HTTP. There's no HTTPS involved because there's no HTTP.
  • Terminating TLS at the edge: the client speaks HTTPS to your load balancer; the balancer may then speak plain HTTP over the trusted internal network, or a second TCP + TLS hop internally for defense in depth.

How your request data actually travels, encrypted, to the destination

Here's the part people find most mysterious: your plaintext GET /account request is readable in your application code, yet an eavesdropper sees only gibberish. How does the data get from readable to encrypted and back, across the network? It's a pipeline, and each layer wraps the one above it:

  • 1. App writes plaintext. Your code produces an ordinary HTTP request — method, path, headers, body. At this point it's fully readable, but it hasn't left your process.
  • 2. TLS encrypts it into records. The TLS layer takes that HTTP, encrypts it with the shared session key (derived during the handshake), and wraps it into TLS records — each a sealed, authenticated chunk of ciphertext. Nobody without the key can read or alter a record undetected.
  • 3. TCP chops it into segments. TCP takes the stream of ciphertext records and splits it into segments, numbering each so the far side can reassemble them in order and re-request any that go missing.
  • 4. IP routes the packets. Each segment is placed in an IP packet addressed to the server and hops across routers and networks — every hop sees only ciphertext.
  • 5. The server unwraps, in reverse. The server's TCP reassembles the ordered byte stream; its TLS layer decrypts and verifies each record back into the original HTTP; the application reads the exact plaintext request you wrote.
  • 6. The response makes the same trip backward — encrypted by the server's TLS, carried by TCP, decrypted by your client — so the reply is just as private.
The same request, wrapped layer by layer on its way out (pseudocode)
# OUTBOUND, top to bottom (each layer wraps the previous one):

HTTP   : GET /account  Authorization: Bearer eyJ...     # readable plaintext
           |  TLS encrypts with the session key
           v
TLS    : [record: 17 03 03 00 6b  a1 f3 9c ...]          # sealed ciphertext
           |  TCP splits into numbered segments
           v
TCP    : [seq=1 | ...cipher...] [seq=2 | ...cipher...]   # ordered, reliable
           |  IP addresses and routes each segment
           v
IP     : [src -> dst | ...cipher...]  ... hops across the internet ...

# INBOUND at the server, bottom to top (unwrap in reverse):
#   IP reassembles -> TCP orders the stream -> TLS decrypts + verifies
#   -> HTTP handler reads the ORIGINAL 'GET /account' plaintext.
# Every router in between saw only the encrypted bytes.

That layered wrapping is the whole trick: the HTTP never changes — the same request you wrote is what the server reads — but between the two endpoints it exists only as TLS-encrypted, TCP-delivered, IP-routed ciphertext. The security lives entirely in the TLS layer sandwiched between your application and the reliable TCP pipe.

Step 2 — The TLS handshake (the lockbox)

Now there's a reliable pipe, but anyone on the path could read it. TLS (Transport Layer Security — the 'S' in HTTPS) turns that open pipe into a private one. The handshake does three jobs at once: agree on how to encrypt, prove the server's identity, and establish a shared secret key — all without ever transmitting the secret key itself. Here's the modern (TLS 1.3) flow, slightly simplified:

  • ClientHello — the client says 'I support these TLS versions and cipher suites,' and includes its half of a key-exchange (a public value).
  • ServerHello + Certificate — the server picks a cipher, sends its half of the key-exchange, and presents its certificate (its public key, signed by a Certificate Authority).
  • Verify identity — the client checks the certificate: is it signed by a CA the browser trusts? Does the name match the host? Is it unexpired and not revoked? If not, the connection is refused — this is what stops impostors.
  • Derive the shared key — using the two key-exchange halves, both sides independently compute the same secret key (Diffie-Hellman). The eavesdropper saw the public halves but cannot derive the secret.
  • Finished — both sides confirm with a message encrypted under the new key, proving the handshake wasn't tampered with. From here on, everything is encrypted.
The TLS 1.3 handshake, step by step (pseudocode)
Client                                        Server
  |  ClientHello  { versions, ciphers, key_share } -->  |
  |  <-- ServerHello { chosen_cipher, key_share }       |
  |  <-- Certificate (server's public key, CA-signed)   |
  |  <-- Finished (encrypted)                           |
  |                                                      |
  |  -- verify cert: trusted CA? name matches? valid? -- |
  |  -- both derive the SAME secret from the key_shares  |
  |     (Diffie-Hellman: the secret never crosses wire)  |
  |  Finished (encrypted) -->                            |
  |                                                      |
  |========== encrypted application data flows ==========|

# TLS 1.3 needs just ONE round trip (1-RTT); a resumed session can be 0-RTT.
Agree a cipher, prove identity with a certificate, derive a shared key — then go encrypted.

Why encrypt in transit at all?

Before the how, nail the why. A request leaving your machine doesn't teleport to the server — it hops across a dozen networks you don't control: your Wi-Fi, your ISP, backbone routers, the destination's data center. Anyone sitting on any of those hops can, by default, read and modify every byte. Encryption in transit is what makes the data meaningless to everyone except the two endpoints that hold the key. Concretely, it defends against:

  • Passive eavesdropping — someone on shared Wi-Fi or a tapped link silently capturing passwords, tokens, cookies, and personal data (a 'man-in-the-middle' sniffing traffic).
  • Active tampering — a proxy or compromised router altering a request in flight: changing an amount, redirecting a payment, injecting malware into a page.
  • Session hijacking — stealing a session cookie or auth token from an unencrypted request and impersonating the user.
  • Credential harvesting at scale — one tapped network segment can harvest thousands of logins if they travel in the clear.

The guarantee you're buying is threefold: confidentiality (only the endpoints can read it), integrity (any tampering is detected), and — paired with certificates — authenticity (you're talking to the real server, not an impostor). Encryption in transit is the baseline, non-negotiable protection for anything that isn't already public.

The two ways to encrypt — symmetric vs asymmetric

There are exactly two families of encryption, and the elegant trick of TLS is that it uses both, each where it's strongest. Understanding the split is the key to the whole scheme — including how the receiver decrypts.

SymmetricAsymmetric (public-key)
KeysOne shared secret key encrypts AND decrypts.A key pair: public key encrypts, private key decrypts (and vice-versa for signing).
SpeedVery fast — ideal for bulk data.Slow — hundreds of times costlier; only for tiny payloads.
The hard partHow do both sides get the same secret without an eavesdropper seeing it?No shared-secret problem — you can hand out the public key freely.
Used in TLS forEncrypting the actual request/response data.Verifying identity and safely establishing the symmetric key.
ExamplesAES-256-GCM, ChaCha20-Poly1305.RSA, ECDSA, Diffie-Hellman (ECDHE).

Each family has a weakness the other fixes. Symmetric is fast but needs both sides to already share a secret — a chicken-and-egg problem over an open network. Asymmetric solves that (you can publish a public key for the world to see) but is far too slow to encrypt a whole response. So TLS combines them: use asymmetric key-exchange to agree on a symmetric key safely, then use that fast symmetric key for all the real data. This is called a hybrid cryptosystem, and it's why the handshake and the data phase use different cryptography.

One shared key (fast, for data) vs a public/private pair (for exchanging that key safely).

How the receiver decrypts

Follow the key, and decryption stops being mysterious. By the end of the handshake, both the client and the server hold the same symmetric session key — derived independently via the key exchange, never transmitted. From then on, decryption is symmetric and simple:

  • Sender encrypts each chunk of data with the shared symmetric key, producing a sealed, authenticated record.
  • The record travels across the network as ciphertext — unreadable to every hop in between.
  • Receiver decrypts with the same symmetric key it already holds, recovering the exact original bytes.
  • Integrity is checked at the same time — modern ciphers (AEAD, like AES-GCM) attach an authentication tag; if even one bit was altered in flight, decryption fails loudly rather than returning corrupted data.
Both ends hold the same key: encrypt on send, decrypt on receive (python)
# After the handshake, BOTH sides share this symmetric key (never sent).
session_key = derived_during_handshake()        # identical on client & server

# --- Sender (e.g. the browser) ---
nonce = random_96_bits()                          # unique per record, never reused
ciphertext, tag = aes_gcm_encrypt(session_key, nonce, plaintext_http)
send(nonce + ciphertext + tag)                    # only ciphertext goes on the wire

# --- Receiver (the server) ---
nonce, ciphertext, tag = parse(received_bytes)
plaintext_http = aes_gcm_decrypt(session_key, nonce, ciphertext, tag)
# ^ if any byte was tampered with, the tag check FAILS and this raises -
#   the receiver rejects the record instead of trusting corrupted data.

So the receiver doesn't do anything exotic — it holds the same symmetric key and runs the decryption in reverse. The genuinely clever work already happened in the handshake: getting that one shared key into both parties' hands without ever putting it on the wire. The asymmetric step (and certificates) exist entirely to make that safe.

The most secure options available today

'Most secure' isn't one algorithm — it's a set of modern choices plus the discipline to avoid the deprecated ones. Here's what a well-configured, security-first endpoint uses in 2026:

LayerStrong choiceAvoid / deprecated
TLS versionTLS 1.3 (fewer round trips, only safe ciphers)SSL 3.0, TLS 1.0/1.1 — broken, disable them
Bulk (symmetric) cipherAES-256-GCM or ChaCha20-Poly1305 (AEAD)RC4, DES/3DES, AES-CBC without AEAD
Key exchangeECDHE (gives forward secrecy)Static RSA key exchange (no forward secrecy)
Signature / certificateECDSA (P-256) or RSA-2048+MD5/SHA-1 signatures, RSA-1024
Hash / integritySHA-256 or stronger (built into AEAD)MD5, SHA-1
  • Prefer TLS 1.3 — it strips out every legacy, weak option, so you can't accidentally negotiate something broken.
  • Insist on forward secrecy (ECDHE): a fresh key per session means a future private-key leak can't decrypt traffic captured today.
  • Use AEAD ciphers (AES-GCM, ChaCha20-Poly1305): they encrypt and authenticate in one step, closing the door on tamper and padding attacks.
  • Keep certificates modern: ECDSA or RSA-2048+, short lifetimes, automated renewal (e.g. ACME/Let's Encrypt), and rotate immediately on any suspected compromise.
  • Harden the config: disable old protocol versions and weak cipher suites, enable HSTS so browsers refuse to downgrade to plain HTTP, and test with a scanner (SSL Labs-style) to catch misconfigurations.

Step 3 — Certificates: proving who you're really talking to

The gap encryption alone can't fill

So far we've made the connection private — nobody on the network can read it. But there's a sneaky problem hiding in plain sight. Encryption guarantees that whoever you're talking to can't be overheard. It does not guarantee you're talking to the right person.

Picture this: you want to visit your bank. You open an encrypted connection to a server and exchange keys perfectly. But what if an attacker secretly sat in the middle, and you encrypted everything to the attacker's server instead of the bank's? The connection is still beautifully encrypted — just encrypted to the wrong party, who happily reads your password and then forwards it to the real bank so you notice nothing. This is a man-in-the-middle attack, and encryption by itself does absolutely nothing to stop it.

The missing guarantee is identity: proof that the server on the other end genuinely owns yourbank.com and isn't an impostor who also knows how to do encryption. Certificates exist to solve exactly this, and nothing else.

Why not just hand out a public key directly?

Fair question — and it's the heart of why certificates exist. Remember from the previous section that asymmetric encryption uses a public key (which anyone may have) and a private key (kept secret). So why can't the bank simply publish its public key and let you use it? Because anyone can generate a public key and claim to be anyone. There's nothing about a raw public key that says who it belongs to.

  • An attacker generates their own key pair and announces: 'Hi, I'm yourbank.com, here's my public key.'
  • You have no way to tell their key apart from the bank's real key — both are just big random-looking numbers.
  • You encrypt your login to the attacker's key, convinced it's the bank's. Game over.
  • A key by itself carries no proof of ownership — that's the gap.

What's missing is a trusted third party to vouch: 'I have personally verified that this public key really belongs to the organization that controls yourbank.com.' That vouching, in a form your browser can check automatically, is a certificate. The certificate is the public key plus a trustworthy stamp of who owns it.

The notary analogy

Think of buying a house. You and the seller could just exchange a hand-written note, but how do you know the 'seller' actually owns the house? So instead, a notary — someone everyone already trusts — checks the seller's identity and stamps the document. You don't need to personally verify the seller; you trust the notary's stamp, and the notary did the checking.

  • The website = the seller, who wants to prove it owns yourbank.com.
  • The Certificate Authority (CA) = the notary everyone trusts — companies like DigiCert, or free ones like Let's Encrypt.
  • The certificate = the notarized document: the site's public key + its name, stamped (digitally signed) by the CA.
  • Your browser = you — it already trusts a fixed list of notaries, so it trusts anything they've stamped.

The key insight: you never have to trust the website directly. You only have to trust the notary, and the notary vouches for the website. That shifts the problem from 'how do I verify millions of websites?' to 'how do I trust a handful of well-known notaries?' — which is a problem we can solve.

What's actually inside a certificate

A certificate is just a small file with a few plain fields. Nothing mysterious:

A certificate, in plain terms (pseudocode)
Certificate {
  subject:      "yourbank.com"          # WHO this ID is for (the domain)
  public_key:   30 82 01 0a 02 ...       # the site's public key
  issuer:       "DigiCert Global CA"     # WHICH notary (CA) vouched for it
  valid_from:   2026-01-01               # not valid before this
  valid_to:     2026-04-01               # expires -> must be renewed
  signature:    9f 2c a7 ...             # the CA's tamper-proof STAMP
}

# The signature is the magic: the CA signed all the fields above with the
# CA's OWN private key. Anyone can verify that stamp using the CA's
# well-known public key -- but nobody can forge it without the CA's secret.

The signature is the stamp, and it's worth seeing why it can't be faked. The CA takes all the other fields, and signs them with the CA's own private key. To forge a certificate, an attacker would need the CA's private key — which the CA guards like crown jewels. Anyone (your browser included) can verify the stamp using the CA's public key, which ships inside your browser already. So the stamp is easy to check but impossible to forge.

How your browser checks the ID — step by step

When the server presents its certificate during the handshake, your browser runs a quick, automatic checklist. If any item fails, it refuses the connection and shows that scary full-page warning:

The browser's certificate checklist (pseudocode)
def accept_certificate(cert, requested_host):
    # 1. Is the stamp genuine? Verify the CA's signature using the CA's
    #    public key (which the browser already trusts).
    if not verify_signature(cert, cert.issuer_public_key):
        reject("forged or tampered certificate")

    # 2. Does the name match? The cert must be for the site you asked for.
    if cert.subject != requested_host:
        reject("wrong site -- cert is for someone else")

    # 3. Is it in date? Expired certs are refused.
    if today() > cert.valid_to or today() < cert.valid_from:
        reject("expired or not-yet-valid")

    # 4. Has it been revoked early (key was stolen)? Check revocation lists.
    if is_revoked(cert):
        reject("revoked")

    # 5. Is the issuer itself trusted? (walk the chain -- see below)
    if not chains_to_trusted_root(cert):
        reject("unknown, untrusted issuer")

    accept()   # all checks pass -> this really is the site you wanted

The chain of trust — notaries vouching for notaries

One more layer makes the whole thing scale. There are only a few dozen root CAs, and their keys are so precious they're kept offline in vaults. They don't sign website certificates directly. Instead a root signs a few intermediate CAs, and those intermediates sign the millions of website certificates. So verification walks a short chain:

  • Your site's certificate was signed by an intermediate CA.
  • That intermediate's certificate was signed by a root CA.
  • The root CA is in the list your browser and operating system already trust (shipped with them).
  • The browser follows this chain link by link; if every signature checks out and it ends at a trusted root, the site's identity is proven.

This is why it's called a chain of trust: trust flows down from a root you already trust, through an intermediate, to the website. Break any link — a bad signature, an untrusted root — and the whole chain is rejected.

Trust flows from a built-in root CA, down through an intermediate, to the website's certificate.

Why certificates beat the alternatives

You might wonder if there's a simpler way to manage all this. People have tried; here's why the certificate (CA) model won for the open web:

ApproachHow it'd workWhy it fails / when it fits
Raw public key, no proofSite just publishes its key.No proof of ownership — an impostor can publish a key too. Wide open to man-in-the-middle.
Everyone pre-shares keysYou manually install each site's key before visiting.Impossible at web scale — you'd need billions of keys before browsing anything new.
Password / shared secret per siteYou and the site agree a secret in advance.Still needs a secure first exchange, and doesn't scale to strangers.
Certificate Authorities (the winner)Trust a few notaries; they vouch for everyone else.Scales to the whole web — trust a few roots, reach any site. The model HTTPS uses.
Self-signed certificateThe site stamps its own ID, no CA.No third party vouches, so browsers warn. Fine for internal/testing, not public sites.

The certificate model wins because it turns an impossible problem (verify every website on earth) into a tiny one (trust a short, curated list of root authorities). That's the entire reason certificate-based encryption is the backbone of secure communication on the web, rather than any of the simpler-sounding alternatives.

Step 4 — The encrypted request and response

Only now does the actual HTTP exchange happen — and it rides inside the encrypted TLS tunnel. The browser serializes the HTTP request, TLS encrypts it into ciphertext, TCP carries the ciphertext reliably to the server, the server's TLS layer decrypts it, the app handles it, and the response makes the same trip back in reverse:

What the app writes (plaintext) vs what travels on the wire (ciphertext) (http)
# What your application code sends/receives (plaintext HTTP):
GET /account HTTP/1.1
Host: example.com
Authorization: Bearer eyJhbGci...

HTTP/1.1 200 OK
Content-Type: application/json

{ "balance": 4210 }

# What an eavesdropper on the network actually sees (TLS ciphertext):
#   17 03 03 00 6b  a1 f3 9c 2e d4 ...   (opaque encrypted bytes)
# The method, path, headers, token, and body are ALL inside the encryption.

Step 5 — Keep-alive: pay for the handshake once

Those two handshakes (TCP + TLS) cost multiple round trips — real latency, especially on mobile or across continents. You don't want to pay that on every request. Keep-alive (persistent connections) reuses one established, encrypted connection for many requests. HTTP/2 goes further and multiplexes many requests over a single connection at once. TLS session resumption lets a returning client skip most of the handshake (even 0-RTT in TLS 1.3).

One warm connection, many requests (pseudocode)
open_connection(host):              # pay the cost ONCE
    tcp_handshake()                 #   ~1 RTT
    tls_handshake()                 #   ~1 RTT (0-RTT if resumed)

# Then reuse the same encrypted pipe for every subsequent request:
for request in page_requests:       # html, css, js, api calls...
    send_encrypted(request)         #   no new handshake
    read_encrypted(response)

close_connection()                  # after an idle timeout
# Amortizing the handshake across many requests is why keep-alive
# and HTTP/2 multiplexing matter so much for real-world latency.

The whole journey, at a glance

StepWhat happensWhat it buys you
DNS resolveHostname -> IP address.Knowing where to connect.
TCP handshakeSYN / SYN-ACK / ACK (~1 RTT).A reliable, ordered byte stream.
TLS handshakeAgree cipher, verify cert, derive shared key (~1 RTT).A private, authenticated tunnel.
Certificate checkWalk the chain to a trusted root; match host.Proof you're talking to the real server.
Encrypted request/responseHTTP travels as ciphertext inside TLS.Confidentiality + integrity of the payload.
Keep-alive / resumptionReuse the warm connection for more requests.Amortized handshake cost; lower latency.

Where this sits in a real web app

In production the TLS handshake usually terminates at the edge — a load balancer, reverse proxy, or CDN does the certificate and encryption work (see Proxy vs reverse proxy), then forwards the decrypted request to your application servers over a trusted internal network (or a second, internal TLS hop for zero-trust setups). This TLS termination centralizes certificate management and offloads the CPU cost of encryption from your app servers — one more reason the reverse proxy is such a common fixture.

TLS often terminates at the edge; internal hops run on a trusted network.

HTTPS isn't a checkbox — it's a carefully layered handshake that delivers three guarantees at once: confidentiality, integrity, and authentication. Understanding the layers is what lets you reason about latency, certificates, and where encryption lives in your architecture.

Why it matters

  • Every credential, token, and byte of user data on the modern web depends on this exact sequence working correctly.
  • The handshake cost (round trips) directly shapes real-world latency, which is why keep-alive, HTTP/2, and resumption exist.
  • Knowing that TLS terminates at the edge explains a huge amount of production architecture — proxies, CDNs, and certificate management.

If ignored

  • Sending sensitive data over plain HTTP exposes it to anyone on the network path — a basic, serious breach.
  • Mishandled or expired certificates cause outages and the browser's full-page security warnings.
  • Opening a fresh TCP+TLS connection per request adds round trips of latency that compound badly at scale.

Where it fits

  • Sits beneath every HTTP request as the transport-security layer: DNS, then TCP, then TLS, then HTTP.
  • Terminates at the edge (load balancer / reverse proxy / CDN) in most real deployments.
  • Connects directly to the broader security picture — it's the 'in transit' half of protecting data.

Related topics

Interview lens

Questions it unlocks

  • Walk me through everything that happens when I type a URL and hit enter, focusing on how it stays secure.
  • How does TLS establish a shared key without ever sending it over the network?
  • What does HTTPS actually hide from someone watching the network?
  • Where does TLS termination happen in a typical architecture, and why?

60-second answer

The browser resolves the hostname via DNS, then opens a TCP connection with the three-way SYN/SYN-ACK/ACK handshake to get a reliable byte stream. On top of that, TLS handshakes: the client and server agree on a cipher, the server proves its identity with a CA-signed certificate the browser validates against its trusted roots, and both sides derive the same secret key via a Diffie-Hellman key exchange — the key itself never crosses the wire, and forward secrecy means a later key leak can't decrypt past sessions. From there the HTTP request and response travel as ciphertext inside the tunnel, so the path, headers, token, and body are all hidden; only the IP and some metadata leak. Because the handshakes cost round trips, we reuse connections with keep-alive, HTTP/2 multiplexing, and session resumption. In production TLS usually terminates at a reverse proxy or CDN at the edge, which centralizes certificates and offloads encryption from the app servers.

Common traps

  • Thinking the encryption key is transmitted during the handshake — it's derived, never sent.
  • Confusing TCP (reliable transport) with TLS (encryption on top of it).
  • Assuming HTTPS hides the destination entirely — the IP and some metadata can still be visible.
  • Forgetting that opening connections is expensive, so per-request handshakes wreck latency.

Search topics

↑↓ to move · Enter to open · Esc to close