Interview Q&A / Computer Networks

INTERVIEW Q&A · 55 QUESTIONS

Computer Networks interview questions

What happens when you open a website, TCP vs UDP, DNS and HTTP.

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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
  8. 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
  9. 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
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. 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
  23. How do Cache-Control and ETag let a browser reuse a response?

    Cache-Control: max-age tells the browser how long it may reuse a response without asking. After that, the browser can revalidate with If-None-Match and the ETag; if nothing changed, the server replies 304 Not Modified with no body.

    IntermediateQuick answer1 min read
  24. How do TCP slow start and congestion avoidance work? Trace cwnd over time.

    Slow start doubles the congestion window every round trip from a small start until it reaches a threshold (ssthresh). After that, congestion avoidance grows it by about one segment per round trip. On a timeout, ssthresh becomes half the window and cwnd restarts small.

    IntermediateQuick answer1 min read
  25. How does a router choose between several matching routes? Explain longest prefix match.

    The router picks, among all table entries that contain the destination address, the one with the longest prefix (most specific). A /24 beats a /16, which beats a /8, and 0.0.0.0/0 is the last-resort default route.

    IntermediateQuick answer1 min read
  26. How does TCP detect and recover from a lost packet?

    The sender retransmits when its timer expires without an ACK, or sooner if it receives three duplicate ACKs, which signal that later segments arrived but one is missing. That second path is called fast retransmit.

    IntermediateQuick answer1 min read
  27. How does the TCP sliding window work? Give a small example.

    The receiver advertises how many bytes it can accept. The sender may keep that many bytes in flight without waiting for ACKs, and as each ACK arrives the window slides forward so new data can be sent. This keeps the link busy instead of stop-and-wait.

    IntermediateQuick answer1 min read
  28. How does traceroute discover the path to a server?

    It sends packets with TTL set to 1, then 2, then 3 and so on. Each router that drops a packet at TTL 0 replies with an ICMP Time Exceeded message, revealing its address, until the destination itself replies.

    IntermediateQuick answer1 min read
  29. How is a TCP connection closed, and what is the TIME_WAIT state?

    Each side closes its own direction with FIN and the other side ACKs it, so teardown takes four segments. The side that closes first then waits in TIME_WAIT, about twice the maximum segment lifetime (60 seconds on Linux), to catch late packets and to resend the last ACK if lost.

    IntermediateQuick answer1 min read
  30. What are DNS over HTTPS and DNS over TLS, and what problem do they solve?

    Plain DNS is unencrypted, so anyone on the path can read and alter your lookups. DNS over TLS (port 853) and DNS over HTTPS (port 443) encrypt the query between you and the resolver, hiding what names you look up from the local network.

    IntermediateQuick answer1 min read