Computer networks: TCP/UDP, HTTP, DNS, TLS
Explain what happens when you type a URL.
By Invicly Tech, , in Interview Preparation. About 12 minutes to read.
In short
Networking questions centre on how data travels reliably and securely. Knowing TCP vs UDP, DNS, HTTP and TLS lets you explain what happens when you type a URL.
Explained simply
Computer networks are built in layers. Each layer does one job and trusts the layer below it. IP moves packets from one machine to another. TCP or UDP sits on top and decides how those packets become a conversation. HTTP sits on top of that and says what the conversation means.
TCP is like a phone call. You connect first, both sides confirm, and everything you say arrives in order. If something gets lost, it is sent again. UDP is like sending postcards. Each one goes on its own, with no promise it arrives or arrives in order, but it is quick and light.
DNS is the internet's phone book. People remember names like example.com, but computers need IP addresses. Your computer asks a DNS resolver, which finds the answer and remembers it for a while so the next lookup is instant.
TLS is the lock on HTTPS. It checks that you are really talking to the right server, using a certificate, and then encrypts everything so nobody in the middle can read or change it. Interviewers love the question "what happens when you type a URL" because it touches all of these layers.
Press Play on a diagram to walk through it one step at a time.
- Browser to DNS resolver: Where is example.com?1Where is example.com?
- DNS resolver to Browser: 93.184.215.14293.184.215.14
- Browser to Web server: TCP SYN3TCP SYN
- Web server to Browser: SYN-ACK4SYN-ACK
- Browser to Web server: ACK, then TLS ClientHello5ACK, then TLS ClientHello
- Web server to Browser: Certificate, keys agreed6Certificate, keys agreed
- Browser to Web server: GET / over HTTPS7GET / over HTTPS
- Web server to Browser: 200 OK with HTML8200 OK with HTML
- Connection with 3-way handshake
- Reliable, ordered delivery
- Retransmits lost packets
- Web, email, databases
- No connection setup
- No delivery or order guarantee
- Low latency, small overhead
- Video calls, games, DNS
- 1Application: HTTP
GET /index.html, headers, body
- 2Security: TLS
Encrypts and authenticates the bytes
- 3Transport: TCP or UDP
Ports, ordering, retransmission
- 4Network: IP
Source and destination IP, routing
- 5Link: Ethernet or Wi-Fi
MAC addresses, one hop at a time
In depth
TCP in more detail: handshake, reliability, closing
TCP opens with the three-way handshake: SYN, SYN-ACK, ACK. Each side picks a random starting sequence number, and every byte after that is numbered. The receiver sends ACKs saying "I have everything up to byte N". If an ACK does not arrive in time, or three duplicate ACKs arrive, the sender retransmits.
Two separate controls limit speed. Flow control uses the receive window, so a fast sender cannot overrun a slow receiver. Congestion control protects the network: the sender starts small (slow start), grows its congestion window, and cuts it when it sees loss. Linux uses CUBIC by default; Google's BBR is another option.
Closing uses FIN and ACK from each side (often shown as a four-way close). The side that closes first enters TIME_WAIT for a while so late packets from the old connection are not mistaken for a new one.
- Sequence numbers give ordering; ACKs give reliability
- Receive window = flow control (protect the receiver)
- Congestion window = congestion control (protect the network)
- ss -tan shows TCP connections and states like ESTAB and TIME-WAIT
DNS resolution step by step
When you look up www.example.com, your machine first checks its own cache and the hosts file. If there is no answer, the stub resolver in your OS asks a recursive resolver, usually from your ISP, your company or a public one like 1.1.1.1 or 8.8.8.8. That resolver does the real work if it has no cached answer.
It asks a root server, which replies with the servers for .com. It asks a .com TLD server, which replies with the authoritative servers for example.com. It asks the authoritative server, which gives the final record. Every answer carries a TTL (time to live) in seconds, and resolvers cache it for that long. That is why DNS changes do not appear everywhere at once.
DNS normally uses UDP port 53 and switches to TCP for large answers and zone transfers.
- A = IPv4, AAAA = IPv6, CNAME = alias, MX = mail, NS = name servers, TXT = text
- Lower the TTL before a migration so the switch spreads fast
- dig +trace example.com shows the root, TLD, authoritative chain
- Your laptop to Recursive resolver: A record for www.example.com?1A record for www.example.com?
- Recursive resolver to Root and .com servers: Ask root, then .com TLD2Ask root, then .com TLD
- Root and .com servers to Recursive resolver: Referral: ask ns1.example.com3Referral: ask ns1.example.com
- Recursive resolver to example.com server: A record for www.example.com?4A record for www.example.com?
- example.com server to Recursive resolver: Answer with TTL 3005Answer with TTL 300
- Recursive resolver to Your laptop: Answer, cached for 300 s6Answer, cached for 300 s
HTTP/1.1, HTTP/2 and HTTP/3
HTTP/1.1 is text based and keeps connections open (keep-alive), but each connection handles one request at a time. Browsers worked around this by opening about six connections per host.
HTTP/2 is binary and multiplexes many streams over one TCP connection, with header compression (HPACK). This fixes blocking at the HTTP level, but not at the TCP level: if one TCP packet is lost, every stream waits for the retransmission. That is TCP head-of-line blocking.
HTTP/3 runs over QUIC, which runs on UDP. QUIC builds reliability and TLS 1.3 into the transport and keeps streams independent, so a lost packet only delays its own stream. It also connects faster and survives network changes, such as moving from Wi-Fi to mobile data, because connections are identified by an ID rather than by IP and port.
- Text format
- One request at a time per connection
- Browsers open about 6 connections
- Runs over TCP
- Binary frames
- Many streams on one connection
- HPACK header compression
- TCP loss still blocks all streams
- Runs on QUIC over UDP
- Streams independent of each other
- TLS 1.3 built in
- Survives network changes
The TLS 1.3 handshake
TLS 1.3 needs only one round trip. The client sends ClientHello with supported cipher suites and a key share (its half of an ECDHE key exchange, usually X25519). The server answers with ServerHello and its own key share. Both sides can now compute the same secret, and everything after this point is encrypted, including the server's certificate.
The server then sends its certificate chain and a CertificateVerify signature that proves it holds the private key. The client checks that the chain leads to a trusted root CA, that the name matches the domain, and that the certificate has not expired. Both send Finished messages, and application data flows.
Because the keys come from fresh ephemeral exchanges, TLS 1.3 always has forward secrecy: stealing the server's private key later does not decrypt old traffic. TLS 1.2 needed two round trips and allowed older, weaker options.
- TLS 1.3: 1 round trip; resumption can use 0-RTT (replay risk)
- SNI in ClientHello tells the server which site you want
- The certificate proves the server's identity, not the user's
What happens when you type a URL: a strong answer
Structure your answer by layer and say you can go deeper anywhere. 1. The browser parses the URL and checks HSTS, its cache and service workers. 2. DNS resolves the name to an IP. 3. TCP handshake to port 443 (or a QUIC handshake for HTTP/3). 4. TLS handshake, certificate check. 5. The browser sends GET / with headers like Host, cookies and Accept-Encoding. 6. On the server side: a load balancer or CDN, then a web server, then the app, which may hit a cache and a database. 7. The response returns with a status, headers and a compressed body. 8. The browser parses HTML, builds the DOM, fetches CSS, JavaScript and images (often in parallel over the same HTTP/2 connection), then lays out and paints the page.
Interviewers often stop you and ask about one step. Pick the area matching the role: DNS and load balancers for DevOps, rendering for frontend, caching and databases for backend.
Learn it in 4 short steps
About 1h each. Track them with a timer in your plan.
- 1Compare TCP and UDP with handshakes~1h
- 2Explain DNS resolution step by step~1h
- 3Explain HTTP versions and TLS handshakes~1h
- 4Answer: what happens when you type a URL~1h
Key points
- DNS resolves names via cache, then root, TLD and authoritative servers.
- TLS proves the server's identity with a certificate and sets up encryption keys.
- HTTP/2 multiplexes many requests on one connection; HTTP/3 runs over QUIC on UDP.
- Then the browser parses HTML and fetches CSS, JS and images, often from a CDN.
Key terms
Tap a card to flip it. 0/5 known
Examples
# Resolve a name and see the answer chain
dig example.com +short
dig example.com +trace
# Watch TCP connect, TLS handshake and HTTP exchange
curl -v https://example.com -o /dev/nullA site works by IP but not by name
A user says curl to the server's IP works, but the domain does not load. Step 1: suspect DNS, since the network path is fine. Step 2: run dig on the name and compare with the expected IP. Step 3: ask the authoritative server directly to see if the record is right at the source. Step 4: if the authoritative answer is correct but your resolver is wrong, it is caching an old answer; check the TTL in the response and wait or flush. Saying this order aloud shows a calm, layer-by-layer method.
dig +short shop.example.com # what my resolver says
dig +short shop.example.com @1.1.1.1 # a different resolver
dig NS example.com +short # find the authoritative servers
dig shop.example.com @ns1.example.com # ask the source directly
curl -v --resolve shop.example.com:443:203.0.113.10 https://shop.example.com/Choosing TCP or UDP for a multiplayer game
The interviewer asks which transport to use for a real-time game. Step 1: separate the data. Player positions are sent 30 times a second and an old position is useless once a newer one arrives, so retransmitting it only adds lag. Use UDP with a sequence number and drop stale packets. Step 2: chat messages and purchases must arrive exactly once and in order, so use TCP (or a reliable channel built on UDP). Step 3: mention that many games use a library or QUIC that offers both reliable and unreliable channels on UDP. The point is to match the guarantee to the data.
Quick reference
- TCP handshake: SYN, SYN-ACK, ACK; close with FIN/ACK from each side, then TIME_WAIT
- Flow control protects the receiver (window); congestion control protects the network (cwnd)
- Well-known ports: 22 SSH, 53 DNS, 80 HTTP, 443 HTTPS, 5432 PostgreSQL, 3306 MySQL
- DNS: cache, recursive resolver, root, TLD, authoritative; answers cached for the TTL
- HTTP/2 multiplexes over TCP; HTTP/3 uses QUIC over UDP to avoid TCP head-of-line blocking
- TLS 1.3 handshake takes 1 round trip and always gives forward secrecy
- curl -v shows DNS, connect, TLS and HTTP; dig +trace shows the DNS chain
Common mistakes
- Skipping DNS or TLS when describing the URL journey.
- Saying UDP is unreliable so it is never used; DNS and video rely on it.
- Confusing HTTPS encryption with authentication of the user.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Use dig to find the A, AAAA and MX records of a domain you know, and note the TTL of each answer.
- Exercise 2medium
Use curl to measure how long DNS, TCP connect, the TLS handshake and the first byte take for an HTTPS site.
- Exercise 3hard
Give a five-minute answer to "what happens when you type https://shop.example.com and press Enter", covering at least DNS, TCP, TLS, HTTP, the server side and rendering. Write it as a numbered outline.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- Is UDP unreliable and therefore bad?
- UDP gives no delivery guarantees, but that is a feature when late data is useless. DNS, video calls, games and QUIC (HTTP/3) all run on UDP.
- What is the difference between HTTP and HTTPS?
- HTTPS is HTTP sent inside a TLS connection, usually on port 443. TLS encrypts the traffic and lets the browser verify the server's identity with a certificate.
- Why does DNS use UDP?
- Most queries and answers fit in a single small packet, so skipping the TCP handshake makes lookups faster. DNS falls back to TCP for large responses and zone transfers.
- How deep should I go on the OSI model?
- Know the seven layer names and map common protocols to them, but most interviews use the simpler TCP/IP model. Being able to explain real behaviour, like the TCP handshake or DNS caching, matters far more.