Skip to content
TryHired.
Interview prep · Technical · Python 3.12.10

Networking interview questions: answers with real output

The fundamentals questions for IT, support, network and cloud roles, answered in plain words, with subnetting and socket examples that were actually run.

Updated Nov 15, 2026 · Examples run with Python 3.12.10 · questions: TryHired
Quick answer

Networking interviews start with the fundamentals: CIDR notation and subnetting, private address ranges, TCP versus UDP and the three-way handshake, DNS records, DHCP, ARP, NAT, port ranges, how hosts and routers choose where to send a packet, TTL and traceroute, IPv6 differences and the layer models. Below are 17 questions; the addressing and socket examples were run with Python's standard library on this machine, and the protocol facts were checked against the IETF RFCs.

Basic

Basic networking interview questions

Advice

Basic1. What does a /26 mean, and how many hosts fit in it?

The number after the slash is the prefix length: how many leading bits of the address identify the network. A /26 leaves 32 - 26 = 6 bits for hosts, so 2^6 = 64 addresses. In an ordinary IPv4 subnet the first address names the network and the last is the broadcast address, which leaves 62 usable host addresses. (Point-to-point /31 links are a documented exception.)

Python
import ipaddress
net = ipaddress.ip_network("192.168.10.0/26")
hosts = list(net.hosts())
print("netmask:", net.netmask)
print("addresses:", net.num_addresses)
print("usable hosts:", len(hosts), "from", hosts[0], "to", hosts[-1])
print("network:", net.network_address, "| broadcast:", net.broadcast_address)
Output (Python 3.12.10)
netmask: 255.255.255.192
addresses: 64
usable hosts: 62 from 192.168.10.1 to 192.168.10.62
network: 192.168.10.0 | broadcast: 192.168.10.63

Checked against: RFC 4632: CIDR (IETF)

Basic2. What are the private IPv4 address ranges?

RFC 1918 reserves three blocks for private networks: 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, so private hosts reach it through NAT. A common trap is 172.32.x.x, which is outside the 172.16/12 block. Note that Python's is_private is broader than RFC 1918 (it also covers loopback, link-local and other special-purpose ranges), so the example tests the three blocks directly.

Python
import ipaddress
RFC1918 = [ipaddress.ip_network(n) for n in ("10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16")]
for a in ["10.20.30.40", "172.16.5.1", "172.31.255.254", "172.32.0.1", "192.168.1.10", "8.8.8.8"]:
    print(f"{a:<15} RFC 1918 private: {any(ipaddress.ip_address(a) in n for n in RFC1918)}")
Output (Python 3.12.10)
10.20.30.40     RFC 1918 private: True
172.16.5.1      RFC 1918 private: True
172.31.255.254  RFC 1918 private: True
172.32.0.1      RFC 1918 private: False
192.168.1.10    RFC 1918 private: True
8.8.8.8         RFC 1918 private: False

Checked against: Python docs: ipaddress, RFC 1918: private address space (IETF)

Basic3. What is the difference between TCP and UDP?

TCP sets up a connection and gives applications a reliable, ordered stream of bytes, with retransmission and flow control; message boundaries are not kept, so the application has to frame its own messages. UDP sends independent datagrams with no connection, no retransmission and no promise of ordering, but each datagram arrives whole or not at all. That makes UDP suit DNS queries, voice and video, and protocols that handle loss themselves. The example sends two UDP datagrams over the loopback interface: each recv() returns exactly one of them.

Python
import socket
rx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); rx.bind(("127.0.0.1", 0))
tx = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
for msg in (b"first", b"second"):
    tx.sendto(msg, rx.getsockname())
print("recv 1:", rx.recv(1024))
print("recv 2:", rx.recv(1024))
Output (Python 3.12.10)
recv 1: b'first'
recv 2: b'second'

Checked against: RFC 768: UDP (IETF), RFC 9293: TCP (IETF)

Basic4. What happens in the TCP three-way handshake, and what does connection refused mean?

The client sends SYN, the server replies SYN-ACK, and the client answers ACK; then both sides can send data. If nothing is listening on the port, the target answers the SYN with a reset (RST), which the client reports as connection refused. A timeout instead usually means the packets were dropped, often by a firewall. The example connects to a listening socket on 127.0.0.1, closes it, and connects again.

Python
import socket
srv = socket.socket(); srv.bind(("127.0.0.1", 0)); srv.listen(); port = srv.getsockname()[1]
c = socket.create_connection(("127.0.0.1", port)); conn, _ = srv.accept()
print("while listening: connected, accept() returned a socket")
for s in (c, conn, srv): s.close()
try:
    socket.create_connection(("127.0.0.1", port), timeout=10)
except ConnectionRefusedError as e:
    print("after closing:", type(e).__name__)
Output (Python 3.12.10)
while listening: connected, accept() returned a socket
after closing: ConnectionRefusedError

Checked against: RFC 9293: TCP (IETF)

Basic5. What are the common DNS record types?

A maps a name to an IPv4 address and AAAA to an IPv6 address; CNAME makes a name an alias of another name; MX names the mail servers for a domain; NS lists the authoritative name servers; TXT holds text such as domain-verification and email-policy records. When asked how a lookup works, describe the resolver: your machine asks a recursive resolver, which follows referrals from the root to the top-level domain to the domain's authoritative servers and caches the answer for its TTL.

Checked against: RFC 1034: DNS concepts (IETF), RFC 1035: DNS implementation (IETF)

Basic6. How does a device get an IP address with DHCP?

Four messages, often remembered as DORA: the client broadcasts a DHCPDISCOVER, servers reply with a DHCPOFFER, the client broadcasts a DHCPREQUEST for one offer, and that server confirms with a DHCPACK. The lease also carries settings such as the subnet mask, default gateway and DNS servers, and the client renews it before it expires.

Checked against: RFC 2131: DHCP (IETF)

Basic7. What does ARP do?

ARP finds the hardware (MAC) address that belongs to an IPv4 address on the local network. The sender broadcasts a request asking who has that IP address, the owner replies with its MAC address, and the answer is cached. It works only within one broadcast domain: for a destination on another subnet, the host resolves the MAC address of its default gateway instead. IPv6 uses Neighbor Discovery for the same job.

Checked against: RFC 826: ARP (IETF)

Intermediate

Intermediate networking interview questions

Advice

Intermediate8. How do you split a /24 into four subnets?

Borrow two host bits: a /24 becomes four /26 networks of 64 addresses each. Each subnet has its own network and broadcast address, so hosts run from .1 to .62, .65 to .126 and so on. Interviewers often ask for this by hand, so practice the arithmetic and use the code to check yourself.

Python
import ipaddress
for s in ipaddress.ip_network("10.1.0.0/24").subnets(new_prefix=26):
    h = list(s.hosts())
    print(f"{str(s):<14} hosts {h[0]} - {h[-1]}  broadcast {s.broadcast_address}")
Output (Python 3.12.10)
10.1.0.0/26    hosts 10.1.0.1 - 10.1.0.62  broadcast 10.1.0.63
10.1.0.64/26   hosts 10.1.0.65 - 10.1.0.126  broadcast 10.1.0.127
10.1.0.128/26  hosts 10.1.0.129 - 10.1.0.190  broadcast 10.1.0.191
10.1.0.192/26  hosts 10.1.0.193 - 10.1.0.254  broadcast 10.1.0.255

Checked against: RFC 4632: CIDR (IETF)

Intermediate9. How does a host decide whether to send a packet directly or to the default gateway?

It compares the destination with its own network: if the destination is inside the host's subnet, it delivers directly on the local link (after ARP); otherwise it sends the packet to the default gateway's MAC address and the router forwards it. With a /25 mask, 192.168.1.100 is local to 192.168.1.20 but 192.168.1.200 is not.

Python
import ipaddress
iface = ipaddress.ip_interface("192.168.1.20/25")
print("my network:", iface.network)
for dst in ["192.168.1.100", "192.168.1.200"]:
    local = ipaddress.ip_address(dst) in iface.network
    print(dst, "-> same subnet, deliver directly" if local else "-> other subnet, send to the default gateway")
Output (Python 3.12.10)
my network: 192.168.1.0/25
192.168.1.100 -> same subnet, deliver directly
192.168.1.200 -> other subnet, send to the default gateway

Checked against: RFC 1122: host requirements (IETF)

Intermediate10. What is route summarization (supernetting)?

Advertising one shorter prefix that covers several contiguous networks, so routers carry fewer routes. Four contiguous /24 networks that start on a boundary divisible by four summarize to one /22; three of them cannot be a single prefix and need a /23 plus a /24.

Python
import ipaddress
nets = [ipaddress.ip_network(f"172.20.{i}.0/24") for i in range(4)]
print("four /24s: ", list(ipaddress.collapse_addresses(nets)))
print("three /24s:", list(ipaddress.collapse_addresses(nets[:3])))
Output (Python 3.12.10)
four /24s:  [IPv4Network('172.20.0.0/22')]
three /24s: [IPv4Network('172.20.0.0/23'), IPv4Network('172.20.2.0/24')]

Checked against: Python docs: ipaddress

Intermediate11. What are well-known, registered and ephemeral ports?

Port numbers 0 to 1023 are the system (well-known) ports, such as 22 for SSH and 443 for HTTPS; 1024 to 49151 are user (registered) ports; and 49152 to 65535 are dynamic (ephemeral) ports, which are never assigned to services and are used for the client side of connections. Operating systems may use a different ephemeral range in practice.

Python
def port_range(p):
    if p <= 1023: return "system (well-known)"
    if p <= 49151: return "user (registered)"
    return "dynamic (ephemeral)"
for p in (22, 443, 3306, 8080, 51000):
    print(f"{p:>5}  {port_range(p)}")
Output (Python 3.12.10)
   22  system (well-known)
  443  system (well-known)
 3306  user (registered)
 8080  user (registered)
51000  dynamic (ephemeral)

Checked against: RFC 6335: port numbers (IETF)

Intermediate12. How do you shorten an IPv6 address correctly?

Drop leading zeros in each 16-bit group, replace the longest run of all-zero groups with :: (only once, and only for two or more groups), and write hex digits in lowercase; if two zero runs are equally long, shorten the first. The exploded form writes all eight groups in full.

Python
import ipaddress
for a in ["2001:0DB8:0000:0000:0000:0000:0002:0001", "2001:db8:0:0:1:0:0:1", "fe80:0000:0000:0000:0204:61ff:fe9d:f156"]:
    ip = ipaddress.ip_address(a)
    print(f"{ip.compressed:<26} {ip.exploded}")
Output (Python 3.12.10)
2001:db8::2:1              2001:0db8:0000:0000:0000:0000:0002:0001
2001:db8::1:0:0:1          2001:0db8:0000:0000:0001:0000:0000:0001
fe80::204:61ff:fe9d:f156   fe80:0000:0000:0000:0204:61ff:fe9d:f156

Checked against: RFC 5952: IPv6 text representation (IETF)

Intermediate13. What is NAT, and what is port address translation?

NAT rewrites addresses as packets cross a router, typically so hosts with private addresses can reach the internet. The common home and office form, NAPT (also called PAT or NAT overload), maps many private address and port pairs onto one public address by also rewriting port numbers, and keeps a table so replies reach the right host. The usual consequence to mention: inbound connections need port forwarding or another traversal method.

Checked against: RFC 3022: traditional NAT (IETF)

Advanced

Advanced networking interview questions

Advice

Advanced14. How does a router choose between overlapping routes?

It uses the longest prefix match: of all routes that contain the destination, the one with the longest prefix wins, and the default route 0.0.0.0/0 matches only when nothing else does. Administrative distance and metrics only decide between routes to the same prefix.

Python
import ipaddress
routes = {"0.0.0.0/0": "ISP uplink", "10.0.0.0/8": "core router", "10.2.0.0/16": "branch VPN", "10.2.3.0/24": "lab switch"}
def lookup(dst):
    hits = [ipaddress.ip_network(r) for r in routes if ipaddress.ip_address(dst) in ipaddress.ip_network(r)]
    best = max(hits, key=lambda n: n.prefixlen)
    return f"{dst:<13} -> {str(best):<12} via {routes[str(best)]}"
for d in ("10.2.3.9", "10.2.9.9", "10.9.9.9", "198.51.100.7"):
    print(lookup(d))
Output (Python 3.12.10)
10.2.3.9      -> 10.2.3.0/24  via lab switch
10.2.9.9      -> 10.2.0.0/16  via branch VPN
10.9.9.9      -> 10.0.0.0/8   via core router
198.51.100.7  -> 0.0.0.0/0    via ISP uplink

Checked against: RFC 4632: CIDR (IETF)

Advanced15. What is TTL, and how does traceroute use it?

Every IPv4 packet carries a Time to Live (the Hop Limit in IPv6). Each router decreases it by one and discards the packet when it reaches zero, usually sending an ICMP Time Exceeded message back. Traceroute sends probes with TTL 1, 2, 3 and so on, and lists the routers that report back, which maps the path hop by hop.

Checked against: RFC 791: IPv4 (IETF)

Advanced16. How is fragmentation different in IPv6?

In IPv4, routers can fragment a packet that is too big for the next link (unless Don't Fragment is set). In IPv6 only the sending host fragments: routers drop oversized packets and return an ICMPv6 Packet Too Big message, so hosts rely on path MTU discovery. Blocking those ICMP messages is a classic cause of connections that hang on large transfers.

Checked against: RFC 8200: IPv6 (IETF)

Advanced17. How do the OSI model and the TCP/IP model compare?

OSI has seven layers (physical, data link, network, transport, session, presentation, application); the internet's own architecture, as described in the host requirements RFCs, uses four: link, internet (IP), transport and application. Map them when you answer: Ethernet and Wi-Fi are link layer, IP and ICMP are the internet layer, TCP and UDP are transport, and HTTP and DNS are application. Use the model to locate a fault, for example a DNS failure versus a routing problem.

Checked against: RFC 1122: host requirements (IETF)

Practice

How to practice with this page

Advice
  • Do the subnet arithmetic by hand first, then check it with the code.
  • Explain each answer at the packet level: what is sent, by whom, to which address.
  • Practice a troubleshooting story: a host that cannot reach a website, step by step from link to DNS.
  • Add vendor topics (VLANs, OSPF, BGP) if the role is network engineering.
Next

Related interview prep and tools

Disclosure: TryHired makes HIRED, a paid job-search program, so we have a conflict of interest when we mention it. This question bank is free, with no TryHired signup.

FAQ

Questions people ask

What networking topics come up often in interviews?
Subnetting and CIDR, TCP versus UDP, the three-way handshake, DNS, DHCP and ARP, NAT, routing basics (default gateway, longest prefix match), ports, and troubleshooting steps for a host that cannot connect.
Do I need to subnet by hand in an interview?
Often, yes: many interviewers ask for a network address, broadcast address or host count without a calculator. Practice the powers of two and the block sizes (/25 = 128, /26 = 64, /27 = 32 and so on), then use a tool like Python's ipaddress module to check your answers.
Are these questions enough for a network engineer interview?
They cover the fundamentals. Network engineer roles usually add vendor-specific configuration, VLANs and trunking, spanning tree, routing protocols such as OSPF and BGP, and security topics. Use the role page for those.
Method

How this page is built

TryHired wrote these questions and answers. Every code block on this page was run with Python 3.12.10 when the page was built (2026-11-15), using only the standard library (ipaddress and socket). Socket examples use the loopback address 127.0.0.1, so nothing was sent over a real network. The output shown is the real output, and the build stops if any example fails. The question list is general practice: it does not predict what a particular employer will ask.

What this page can't tell you
  • Interviewers ask different questions for different roles and levels.
  • Answers are short explanations, not complete references.
  • Examples use Python's ipaddress and socket modules on the loopback interface; they show addressing and transport behavior, not packet captures. On Windows, a refused connection is reported after the operating system's SYN retries, so it takes about two seconds; other systems usually report it at once.
Sources
  1. Python docs: ipaddress (read 2026-11-15)
  2. RFC 1034: DNS concepts (IETF) (read 2026-11-15)
  3. RFC 1035: DNS implementation (IETF) (read 2026-11-15)
  4. RFC 1122: host requirements (IETF) (read 2026-11-15)
  5. RFC 1918: private address space (IETF) (read 2026-11-15)
  6. RFC 2131: DHCP (IETF) (read 2026-11-15)
  7. RFC 3022: traditional NAT (IETF) (read 2026-11-15)
  8. RFC 4632: CIDR (IETF) (read 2026-11-15)
  9. RFC 5952: IPv6 text representation (IETF) (read 2026-11-15)
  10. RFC 6335: port numbers (IETF) (read 2026-11-15)
  11. RFC 768: UDP (IETF) (read 2026-11-15)
  12. RFC 791: IPv4 (IETF) (read 2026-11-15)
  13. RFC 8200: IPv6 (IETF) (read 2026-11-15)
  14. RFC 826: ARP (IETF) (read 2026-11-15)
  15. RFC 9293: TCP (IETF) (read 2026-11-15)