Interview Q&A / Computer Networks
Computer Networks interview questions
What happens when you open a website, TCP vs UDP, DNS and HTTP.
Prefer rapid revision? Practise Computer Networks short interview answers →
- What are the common HTTP methods and status codes, and what does idempotent mean?
GET reads, POST creates or triggers an action, PUT replaces, PATCH partly updates and DELETE removes. A method is idempotent if repeating the same request leaves the server in the same state as doing it once - GET, PUT and DELETE are, POST is not. Status codes are grouped as 2xx success, 3xx redirect, 4xx client error and 5xx server error.
BeginnerIn-depth5 min read - What happens when you type a URL in the browser and press Enter?
The browser finds the server's IP address with DNS, opens a TCP connection, sets up TLS for HTTPS, sends an HTTP request, gets a response and then parses and renders the HTML, CSS and JavaScript into the page you see.
BeginnerIn-depth3 min read - What is the difference between HTTP and HTTPS, and what does TLS actually do?
HTTPS is HTTP sent inside a TLS connection. TLS gives three things plain HTTP lacks - encryption so others on the network cannot read the data, integrity so it cannot be changed in transit, and authentication through a certificate so you know you are talking to the real site.
BeginnerIn-depth4 min read - What is the difference between TCP and UDP?
TCP is connection-based and reliable, with ordering, retransmission and flow control, so it suits web pages, email and file transfer. UDP just sends datagrams with no guarantees, so it is faster and lighter and suits video calls, games, DNS and live streaming.
BeginnerIn-depth3 min read - What is the OSI model, and how is it different from the TCP/IP model?
The OSI model is a 7-layer reference model (Physical, Data Link, Network, Transport, Session, Presentation, Application) used to explain and troubleshoot networks. The TCP/IP model is the 4-layer model the internet actually runs on (Link, Internet, Transport, Application), which folds OSI's top three layers into one.
BeginnerIn-depth4 min read - How does DNS resolution work, step by step?
Your device asks a recursive resolver, which checks its cache and, if needed, asks a root server, then the TLD server (like .com), then the domain's authoritative server, which returns the IP address. Every answer carries a TTL, so resolvers and devices cache it and skip most of these steps next time.
IntermediateIn-depth4 min read - What is an IP address, a subnet and CIDR notation like /24?
An IPv4 address is a 32-bit number that identifies a device on a network. CIDR notation such as 192.168.1.0/24 says how many leading bits are the network part; the rest identify hosts. A /24 has 256 addresses (254 usable), a /16 has 65,536, and each extra bit halves the size of the subnet.
IntermediateIn-depth4 min read - What is the difference between cookies, sessions and tokens like JWT?
A cookie is just a small piece of data the browser stores and sends back automatically. A session keeps login state on the server and puts only a random session ID in a cookie. A JWT is a signed token that carries the user's data itself, so the server can verify it without a lookup, but it is harder to revoke before it expires.
AdvancedIn-depth5 min read - Can UDP datagrams arrive out of order, duplicated, or not at all?
Yes to all three. UDP makes no promises about order, duplicates, or delivery. Each datagram is independent and can take a different route, so the application must tolerate or handle these cases.
BeginnerQuick answer1 min read - Convert 255.255.255.240 to CIDR notation, and /21 to a dotted mask.
255.255.255.240 has 28 one-bits (24 plus 4 from 240 = 11110000), so it is /28, giving 16 addresses and 14 usable hosts. A /21 is 255.255.248.0.
BeginnerQuick answer1 min read - Given 192.168.10.77/27, find the network address, broadcast address and host range.
A /27 has blocks of 32 addresses. 77 falls in the block starting at 64, so network is 192.168.10.64, broadcast is 192.168.10.95, and usable hosts are .65 to .94 (30 hosts).
BeginnerQuick answer1 min read - How do you check whether two IP addresses are in the same subnet?
Apply the subnet mask to both addresses (bitwise AND). If the network addresses match, they are in the same subnet and can talk directly. If not, traffic must go via the default gateway.
BeginnerQuick answer1 min read - How do you divide 192.168.1.0/24 into four equal subnets?
Borrow 2 host bits (2^2 = 4 subnets) to get /26. The subnets are 192.168.1.0/26, .64/26, .128/26 and .192/26, each with 64 addresses and 62 usable hosts.
BeginnerQuick answer1 min read - How many usable hosts are in a /26 subnet, and what is the general formula?
A /26 leaves 6 host bits, so 2^6 = 64 addresses, of which 62 are usable because the first is the network address and the last is the broadcast address. The formula is 2^(32 - prefix) minus 2.
BeginnerQuick answer1 min read - What are the common DNS record types: A, AAAA, CNAME, MX, TXT and NS?
A maps a name to an IPv4 address, AAAA to an IPv6 address, CNAME makes one name an alias of another, MX names the mail servers, TXT holds free text such as verification and SPF data, and NS lists the authoritative name servers for the domain.
BeginnerQuick answer1 min read - What are the four layers of the TCP/IP model, and which protocols belong to each?
Application (HTTP, DNS, SMTP, SSH), Transport (TCP, UDP), Internet (IP, ICMP), and Link (Ethernet, Wi-Fi, ARP). It merges OSI's top three layers into one and its bottom two into one.
BeginnerQuick answer1 min read - What are the private IP ranges, and what are loopback and link-local addresses?
Private ranges are 10.0.0.0/8, 172.16.0.0/12 (172.16.0.0 to 172.31.255.255) and 192.168.0.0/16. They are not routed on the public internet. Loopback is 127.0.0.0/8 (your own machine) and link-local is 169.254.0.0/16 (self-assigned when DHCP fails).
BeginnerQuick answer1 min read - What do the TCP flags SYN, ACK, FIN and RST mean?
SYN starts a connection and syncs sequence numbers, ACK acknowledges received data, FIN politely closes one direction, and RST aborts the connection immediately. PSH asks the receiver to hand data to the app without waiting.
BeginnerQuick answer1 min read - What does a UDP header contain, and how big is it?
A UDP header is 8 bytes with four 16-bit fields: source port, destination port, length, and checksum. A TCP header is at least 20 bytes. That small size is part of why UDP is light.
BeginnerQuick answer1 min read - What does each of the seven OSI layers do, in one line each?
Physical sends bits, Data Link moves frames between neighbours, Network routes packets across networks, Transport delivers data between processes, Session manages dialogues, Presentation handles format and encryption, Application is what the user's software talks to.
BeginnerQuick answer1 min read - What is a port number, and how is it different from an IP address?
An IP address identifies a machine on a network. A port number (0 to 65535) identifies which program on that machine should receive the data. Together they pick out one exact conversation endpoint.
BeginnerQuick answer1 min read - What is DNS TTL, and why do DNS changes seem to take time to "propagate"?
TTL is how many seconds resolvers may cache a record. When you change a record, resolvers that cached the old one keep serving it until its TTL expires, so different users see the change at different times.
BeginnerQuick answer1 min read - What is encapsulation, and what is the data unit called at each layer?
Encapsulation means each layer wraps the data from the layer above with its own header. The unit is called data at the application layer, a segment (TCP) or datagram (UDP) at transport, a packet at network, a frame at data link, and bits at physical.
BeginnerQuick answer1 min read - What is HTTP keep-alive, and why does it speed up page loads?
Keep-alive reuses one TCP connection for several HTTP requests instead of opening a new one each time. This saves the handshake round trips (and the TLS handshake for HTTPS) for every file after the first. It is the default in HTTP/1.1.
BeginnerQuick answer1 min read - What is the difference between IPv4 and IPv6, and how do you shorten an IPv6 address?
IPv4 uses 32-bit addresses (about 4.3 billion), IPv6 uses 128-bit addresses (about 3.4 x 10^38). IPv6 is written as eight hex groups; you may drop leading zeros in each group and replace one run of all-zero groups with ::.
BeginnerQuick answer1 min read - What is the difference between static and dynamic routing?
Static routes are entered by hand and never change unless an admin edits them. Dynamic routing uses protocols like OSPF and BGP so routers learn routes from each other and adapt automatically when links fail.
BeginnerQuick answer1 min read - When would you choose UDP over TCP? Give real examples.
Choose UDP when speed and low delay matter more than perfect delivery, or when the app wants its own control: live video calls, online games, DNS lookups, and streaming. Old data is useless in real time, so waiting for a retransmission is worse than skipping it.
BeginnerQuick answer1 min read - Why does an HTTP/1.1 request need a Host header?
One server IP can host many websites. The TCP connection only carries the IP address, so the Host header tells the server which site the browser wants, letting it choose the right content. HTTP/1.1 requires it.
BeginnerQuick answer1 min read - Why does TCP use a three-way handshake, and why not two?
The handshake lets both sides agree on starting sequence numbers and confirm that each can send and receive. Two steps would prove only that the server can hear the client, so a delayed old SYN could make the server open a connection nobody wants.
BeginnerQuick answer1 min read - At which OSI layer does TLS work?
TLS has no clean place in OSI. It runs on top of TCP and below HTTP, so it is usually described as layer 6 (presentation) or between layers 4 and 7. In the TCP/IP model it simply sits inside the application layer.
IntermediateQuick answer1 min read