Core CS · 18 questions

Computer Networks interview questions

The OSI and TCP/IP models, TCP and UDP, IP addressing, DNS, HTTP and HTTPS: the networking questions interviews ask most, and what really happens when you type a URL.

By Akshay, software engineer, India

Flashcards for these

Models and devices

Explain the OSI model.

Seven layers, each using the one below it:

  • 7 Application: what apps speak (HTTP, DNS, SMTP).
  • 6 Presentation: formats, encryption, compression.
  • 5 Session: setting up and keeping conversations.
  • 4 Transport: process to process, reliability, ports (TCP, UDP).
  • 3 Network: host to host across networks, IP addresses, routing.
  • 2 Data link: node to node on one link, MAC addresses, frames (Ethernet, Wi-Fi).
  • 1 Physical: bits on a wire or radio.

OSI vs the TCP/IP model?

TCP/IP has four layers: Application (OSI 5–7), Transport, Internet (OSI's network layer) and Link (OSI 1–2). OSI was designed first, as a model; TCP/IP grew out of working protocols, and it's what the internet uses.

Hub vs switch vs router?

  • Hub (layer 1): repeats every bit to every port; everyone shares one collision domain.
  • Switch (layer 2): learns which MAC address is on which port and sends each frame only there.
  • Router (layer 3): connects different networks and forwards packets by IP address, using a routing table. Your home "router" is a router, a switch and a Wi-Fi access point in one box.

TCP and UDP

TCP vs UDP?

TCP is connection-oriented and reliable: a handshake first, then every byte arrives, in order, with retransmission, flow control and congestion control. Used for the web, email and file transfer.

UDP just sends datagrams: no connection, no guarantee of delivery or order, but very little overhead and delay. Used for DNS lookups, video calls, games and live streaming, where late data is useless anyway. QUIC (HTTP/3) builds reliability on top of UDP.

Explain the TCP three-way handshake.

SYN: the client picks a starting sequence number x and sends it. SYN-ACK: the server replies with its own sequence number y and acknowledges x + 1. ACK: the client acknowledges y + 1. Now both sides know the other can send and receive, and both sequence numbers are agreed.

Closing takes four steps: each side sends its own FIN and the other ACKs it, because each direction closes separately.

Flow control vs congestion control?

Flow control protects the receiver: it advertises a window (how much it can still buffer), and the sender never has more than that in flight. Congestion control protects the network: the sender keeps a congestion window that grows while things go well (slow start, then additive increase) and shrinks sharply on loss (multiplicative decrease). TCP sends at most min(receive window, congestion window).

What is a port? Name some well-known ones.

A number (0–65535) that picks which process on a host gets the data; an IP address plus a port is a socket address. Well-known ports: HTTP 80, HTTPS 443, SSH 22, FTP 21, SMTP 25, DNS 53, DHCP 67/68, MySQL 3306, PostgreSQL 5432.

IP and the network layer

What is an IP address, and how do IPv4 and IPv6 differ?

An IP address identifies a host's interface on a network. IPv4 is 32 bits (about 4.3 billion addresses, written 192.168.1.10), and it ran out long ago, which is why NAT is everywhere. IPv6 is 128 bits (written 2001:db8::1), with a simpler header, no broadcast, and enough addresses that NAT isn't needed.

What is subnetting, and how many hosts does a /26 have?

Splitting a network into smaller networks by moving the boundary between network and host bits. A /26 leaves 32 − 26 = 6 host bits: 26 = 64 addresses, minus the network and broadcast addresses, so 62 usable hosts. Its mask is 255.255.255.192.

Work any subnet question on the subnet calculator →

What is NAT?

Network address translation lets many devices with private addresses (192.168.x.x) share one public IP. The router rewrites the source address and port of outgoing packets and keeps a table, so replies get sent back to the right device. It saves IPv4 addresses and hides the inside network, but it breaks direct incoming connections, which is why peer-to-peer apps need tricks like STUN.

What does ARP do?

It finds the MAC address for an IP address on the local network. A host broadcasts "who has 192.168.1.1?"; the owner replies with its MAC address, and the answer is cached in the ARP table. It's needed because frames on a LAN are delivered by MAC address, not IP.

How does DHCP give a device its address?

Four messages, DORA: the device broadcasts a Discover; a DHCP server answers with an Offer (an address, the mask, the gateway and DNS servers); the device sends a Request for it; the server confirms with an Acknowledge. The address is leased for a time and renewed before it runs out.

How does ping work?

It sends ICMP echo request packets and waits for echo replies, measuring the round-trip time and the packets lost. traceroute uses increasing TTLs: each router that drops a packet because its TTL ran out sends back an ICMP "time exceeded", revealing the path hop by hop.

DNS, HTTP and the web

How does DNS resolve a name?

The browser and OS check their caches first. Then a recursive resolver (your ISP's, or 8.8.8.8) does the work: it asks a root server, which points it to the .com TLD servers, which point it to the domain's authoritative server, which returns the address. Every answer is cached for its TTL, so most lookups never reach the root.

HTTP vs HTTPS?

HTTPS is HTTP inside TLS. The TLS handshake checks the server's certificate (that it really is the site, signed by a trusted authority) and agrees on keys; after that everything is encrypted and tamper-proof. Plain HTTP can be read and changed by anyone on the path: public Wi-Fi, an ISP. HTTPS uses port 443; HTTP uses 80.

Name the HTTP methods and the status code classes.

Methods: GET (read), POST (create), PUT (replace), PATCH (change part), DELETE. GET, PUT and DELETE are idempotent: doing them twice has the same effect as once; POST isn't.

Status codes: 1xx information; 2xx success (200 OK, 201 Created, 204 No Content); 3xx redirect (301 permanent, 302 temporary, 304 not modified); 4xx your mistake (400, 401 not logged in, 403 not allowed, 404, 429 too many requests); 5xx the server's (500, 502 bad gateway, 503 unavailable).

What happens when you type a URL and press Enter?

  1. The browser parses the URL and checks its caches.
  2. DNS turns the name into an IP address.
  3. A TCP connection is opened (the three-way handshake), then a TLS handshake for HTTPS.
  4. The browser sends an HTTP request; it travels through routers, maybe a CDN or load balancer, to a server.
  5. The server answers with HTML; the browser parses it, fetches the CSS, JavaScript and images it refers to, builds the page and paints it.

Lesson: what happens when you open an app (with the timings) →

Cookies vs sessions?

HTTP itself forgets you between requests. A cookie is a small piece of data the server asks the browser to store and send back with every request. A session keeps your data on the server, and only a session id travels in the cookie. Tokens like JWTs put signed data in the client instead, so any server can check it without a session store.

Keep it for the interview

A few cards a day, back just before you'd forget them.

Core CS flashcards