Internet Protocol (IP)
IP delivers datagrams between networks best-effort: addresses, prefixes, and a forwarding decision made fresh at every hop. Everything above assumes IP may drop or reorder, so its promises matter.
on this pageshowhide
guide
overview
~1 minThe Internet Protocol moves datagrams from one network to another and promises almost nothing about it: a packet may be dropped, duplicated, delayed or reordered, and every router along the way decides on its own where to send it next. Interviewers probe it because every networked system rests on it and its rules are exact enough to test on paper. Can you read an address together with its prefix, do the subnet arithmetic without a calculator, explain why one route beat another, and say what goes wrong when a packet is too big for the path? Those answers show whether you understand the layer that TCP, QUIC and every load balancer quietly assume. The hub follows that split. [IPv4](/topics/proto-ipv4) covers the address format, the header and fragmentation that most captures and configs still show. [CIDR](/topics/proto-cidr) is the prefix arithmetic: subnetting, variable-length plans, summarisation and the reserved ranges. [Hop-by-hop forwarding](/topics/proto-ip-routing) is what a router does with a single packet, and [choosing between route sources](/topics/proto-ip-route-selection) is how its table gets filled and why one candidate wins. [IPv6](/topics/proto-ipv6) revisits all of it with 128-bit addresses, self-configuring hosts, no broadcast and a different story for NAT and transition. Junior rounds stay concrete: write a mask, size a subnet, name a private range, trace a packet's TTL. Senior and principal rounds turn to consequences — asymmetric paths through stateful firewalls, path MTU black holes, fragment-based evasion, ECMP and reordering, and what changes in a service when its hosts become globally reachable over IPv6. Learn IPv4 addressing and CIDR math first; everything else is phrased in prefixes. Then take forwarding and route selection, and leave IPv6 until you can say precisely which IPv4 assumptions it drops.
primer
### Best effort is the contract IP delivers each datagram independently and admits it may fail. It keeps no connection, sends no acknowledgement and makes no ordering promise; reliability, ordering and congestion response belong to the layers above. Many interview answers go wrong by quietly crediting IP with a guarantee TCP provides, so start from what the layer refuses to do. ### An address means nothing without its prefix A bare address does not say which network it lives on. The prefix length splits it into a network part, which routers act on, and a host part, which only the final link cares about. Subnetting, summarisation, firewall rules and the host's own "is this destination local?" check are all the same bitwise operation applied with different prefixes. Fluency with powers of two and bit boundaries is the price of entry for most of this hub. ### Every hop decides alone A router looks at the destination, picks a next hop, adjusts the header and moves on, holding no memory of the flow. That statelessness is why IP scales and survives link failures, and also why: - replies can take a different path from requests; - a packet caught in a loop is stopped by a counter it carries, not by any router remembering it; - anything that does keep state, such as a firewall or a NAT, must see both directions to work. ### The table is ranked in layers When several routes could carry a packet, the most specific prefix decides first. Candidates sharing one prefix then compete on how trusted their source is, and only routes from the same source compare metrics. Ties may be shared across equal-cost paths. Many "why did this route lose?" questions are about mixing up those layers. ### Size is a property of the path Every link has a largest frame it carries, and the smallest one on a path decides what fits end to end. IPv4 lets routers split oversized packets; IPv6 leaves that to the sender. Either way, finding the limit depends on error messages getting back to the source — and on nobody filtering them. ### IPv6 is a redesign, not a wider field Longer addresses are the least interesting change. IPv6 drops broadcast, replaces ARP with multicast-based discovery, lets hosts configure themselves from router advertisements, strips per-hop work out of the header and removes the scarcity that made NAT routine. Interviewers want to hear which IPv4 habits stop holding, especially the ones that were quietly doing security work.
- Datagram
- A self-contained IP packet: header plus payload, routed on its own with no relation to the packets before or after it.
- Prefix length
- The number of leading address bits that identify the network, written after a slash. Everything after those bits identifies a host on that network.
- Subnet mask
- The IPv4 dotted-decimal form of a prefix length: one-bits over the network part, zero-bits over the host part.
- Default route
- The zero-length prefix that matches every destination, so it carries traffic only when no more specific route exists.
- Longest-prefix match
- The forwarding rule that, among all table entries containing the destination, the one with the most network bits wins.
- Next hop
- The neighbouring router, named by its IP address, to which a packet is handed for the next stage of its journey.
- TTL / Hop Limit
- A per-packet counter every router lowers; at zero the packet is discarded and the source is told. IPv4 calls it TTL, IPv6 Hop Limit.
- MTU and path MTU
- The largest IP packet, header included, one link carries in a single frame; the path MTU is the smallest of these between two hosts.
- Fragmentation
- Splitting one IP packet into smaller pieces that only the destination puts back together. IPv4 routers may do it; IPv6 leaves it to the source.
- ICMP
- The control and error protocol carried in IP that reports unreachable destinations, expired TTLs and oversized packets back to senders.
- Administrative distance
- A vendor-defined trust ranking of route sources, used only to choose between routes to the same prefix learned in different ways. Lower wins.
- ECMP
- Equal-cost multipath: installing several next hops for one prefix and spreading traffic across them, normally keeping each flow on one path.
- Neighbor Discovery
- IPv6's ICMPv6-based mechanism for finding neighbours' link-layer addresses, routers and prefixes, replacing ARP and IPv4-style router discovery.
- SLAAC
- Stateless address autoconfiguration: an IPv6 host builds its own address from a router-advertised prefix plus an identifier it picks.
Follow one packet from an application to a server on another network. The sending host compares the destination with its own prefix: inside it, the packet goes straight to the neighbour; outside, it goes to a router. Either way the host looks up the neighbour's hardware address, through ARP or Neighbor Discovery, and frames the packet. Each router on the way repeats a short loop: check the header, find the best route, lower the hop counter, resolve the next hop, reframe and forget. If the packet is too large for the next link, IPv4 may split it or report back; IPv6 only reports. The destination reassembles any fragments and hands the payload to the protocol the header names. The sections attach to stages of that walk: - **[CIDR](/topics/proto-cidr)** is the arithmetic behind both the host's local-or-remote check and every table entry. - **[Hop-by-hop forwarding](/topics/proto-ip-routing)** is the per-router loop itself. - **[Choosing between route sources](/topics/proto-ip-route-selection)** decides what is in the table before any packet arrives: connected, static and protocol-learned routes, ranked and installed. - **[IPv4](/topics/proto-ipv4)** and **[IPv6](/topics/proto-ipv6)** are the two concrete formats the walk runs on, with different answers for discovery, fragmentation and configuration. The forwarding decision and summarisation are both prefix operations, which Python's standard `ipaddress` module makes easy to see: ```python import ipaddress as ip table = {ip.ip_network("0.0.0.0/0"): "upstream", ip.ip_network("203.0.112.0/22"): "core", ip.ip_network("203.0.113.0/24"): "branch"} dst = ip.ip_address("203.0.113.40") best = max((n for n in table if dst in n), key=lambda n: n.prefixlen) print(table[best]) # branch: three entries match, the /24 is most specific pair = [ip.ip_network("203.0.112.0/24"), ip.ip_network("203.0.113.0/24")] print(list(ip.collapse_addresses(pair))) # [IPv4Network('203.0.112.0/23')] ``` The sketch skips the step route selection adds: if two sources offered the same /24, trust and metric would choose between them before this lookup ever ran.
- Address Structure →
Start with what an IPv4 address and mask are, because every other section reads addresses as network and host bits.
- CIDR →
Prefix notation, subnet sizing and summarisation: the arithmetic that interview exercises and routing tables both depend on.
- Hop-by-Hop Forwarding →
What one router does with one packet, and why keeping no per-flow state shapes so much above it.
- Choosing Between Route Sources →
How routes from different sources compete for the table, once longest-prefix matching is clear.
- Fragmentation and MTU →
MTU, fragmentation and path MTU discovery, the source of several senior troubleshooting scenarios.
- IPv6 →
Last, because IPv6 is best learned as a list of IPv4 assumptions it changes: discovery, configuration, fragmentation and NAT.
Crediting IP with reliability or ordering: it may drop, duplicate or reorder packets, and recovering from that is the transport layer's job.
Ranking routes by administrative distance or metric before prefix length: the most specific match wins first, and the other tie-breakers only compare routes for the same prefix.
Forgetting the network and broadcast addresses when counting hosts, or applying that subtraction to
/31and/32prefixes where it does not hold.Starting a subnet on an address that is not a multiple of its own size; the plan looks fine until two subnets overlap.
Quoting the middle private block as
172.16.0.0/16: it is a/12, and the mistake leaves172.17–172.31misclassified in filters and plans.Blocking all ICMP as a security measure, which silently breaks path MTU discovery and produces connections that hang on large transfers.
Treating NAT as a firewall: when hosts gain IPv6 addresses, anything that was hidden only by translation becomes reachable unless a real policy exists.
Saying IPv6 routers fragment oversized packets or that IPv6 uses ARP and broadcast; see IPv6 vs IPv4 Differences.
IP itself changes slowly, but interviewers still ask about the revisions, because old documents, configs and habits outlive them. This guide assumes IPv4 as defined in RFC 791 with the router requirements of RFC 1812, IPv6 as defined in RFC 8200, and classless addressing throughout. - **Classful to classless.** Class A, B and C networks fixed the prefix by the first address bits. Classless addressing took over in 1993 and is now specified in RFC 4632; "a class C" in an old document means a `/24` and nothing more. - **Type of Service to DSCP and ECN.** The second header byte was redefined into a differentiated-services code point and an explicit congestion notification field; the old precedence meanings are history. - **`/31` links.** RFC 3021 made two-address point-to-point subnets legitimate, which changed the textbook host-count rule for that case. - **IPv6 interface identifiers.** Early SLAAC derived the host part from the MAC address; current guidance prefers stable hashed identifiers plus short-lived temporary addresses, for privacy. - **Fragmentation's standing.** RFC 8900 records the long-held view that relying on fragmentation is fragile, and new protocols are expected to size their packets to the path instead. When an answer depends on which era you describe, say so.
Interviewers expect you to place IP among the protocols that make it usable. Below it sit link technologies such as Ethernet and Wi-Fi, which carry frames between neighbours; IP gives those frames a destination beyond the local link. Beside it sit its helpers: ARP or Neighbor Discovery to find a neighbour's link-layer address, ICMP to report errors back to senders, and DHCP or SLAAC to hand a host its address in the first place. Above it, TCP, UDP and QUIC add ports, and TCP and QUIC add reliability and congestion control; DNS turns names into the addresses IP routes on. Routers fill their tables with routing protocols: interior protocols such as OSPF and IS-IS inside one organisation, and BGP between organisations, where policy matters more than shortest paths. NAT and firewalls sit at the edges, where IP's statelessness is deliberately broken. IPv4 and IPv6 are the only versions in production use, and they compete only in the sense that both run side by side; dual stack, tunnelling and translation are how a network carries both while the move continues.
explore
- IPv416 questions
- Address Structure4 questions
- Header Format6 questions
- Fragmentation and MTU6 questions
- IPv630 questions
- Address Space and Notation5 questions
- Address Types5 questions
- Simplified Header Format5 questions
- NDP and SLAAC5 questions
- Transition Mechanisms6 questions
- IPv6 vs IPv4 Differences4 questions
- CIDR24 questions
- Prefix Notation4 questions
- Subnetting Math5 questions
- VLSM5 questions
- Route Aggregation5 questions
- Special Address Ranges5 questions
- Hop-by-Hop Forwarding5 questions
- Choosing Between Route Sources6 questions
questions
81 · 5 sectionsIn IPv4, how is a 32-bit address written in dotted decimal, and how does the subnet mask split it into network and host parts?
basics
~20 sAn IPv4 address is 32 bits written as four decimal octets, each 0-255, such as 198.51.100.37. The subnet mask's one-bits mark the network part and its zero-bits the host part; ANDing address and mask gives the network.
In IPv4, how do unicast, limited broadcast, directed broadcast and multicast differ in who receives a datagram and which addresses signal them?
basics
~20 sUnicast reaches one interface. Limited broadcast, 255.255.255.255, reaches every host on the sender's link and is never routed. A directed broadcast (a network's all-ones host address) reaches every host on that remote network. Multicast, 224.0.0.0-239.255.255.255, reaches joined group members.
In IPv4, what is the MTU, and what happens to a datagram that is larger than the next link's MTU?
basics
~20 sThe MTU is the largest IP datagram, header included, that a link carries in one frame: 1,500 bytes on Ethernet. An IPv4 router fragments a bigger datagram and only the destination reassembles it; with Don't Fragment set, the router drops it instead.
In IPv4, what does the Time to Live field do, and what happens when a router decrements it to zero?
basics
~20 sIPv4's Time to Live is an 8-bit counter each router decrements by at least one; a router that brings it to zero discards the datagram and, for unicast, returns ICMP Time Exceeded to the source, so looping packets cannot circulate forever.
How does IPv4 Path MTU Discovery use the Don't Fragment flag to find the largest datagram a path can carry?
basics
~20 sThe source assumes the path MTU equals its first link's MTU and sets DF on every datagram. A router that cannot forward one drops it and returns an ICMP error carrying the next hop's MTU; the source lowers its estimate and sends smaller.
How is a 128-bit IPv6 address written as text, and what rules govern compressing it with :: in RFC 5952 canonical form?
basics
~20 sAn IPv6 address is eight 16-bit hex groups separated by colons. RFC 5952 canonical form drops leading zeros, uses lowercase, and writes :: once, for the longest run of two or more zero groups, the first run on a tie.
What are the three IPv6 address types, how is a packet sent to each one delivered, and why is there no broadcast?
basics
~20 sIPv6 has unicast (delivered to one interface), multicast (delivered to every member of a group, ff00::/8) and anycast (delivered to the nearest of a set, using unicast-format addresses). Broadcast was dropped; scoped multicast groups such as all-nodes ff02::1 replace it.
In IPv6, what replaces ARP for finding a neighbour's MAC address, and why does no broadcast take part?
basics
~20 sIPv6 Neighbor Discovery (RFC 4861) replaces ARP: a host sends an ICMPv6 Neighbor Solicitation to the target's solicited-node multicast address, and the target answers with a unicast Neighbor Advertisement carrying its MAC. IPv6 has no broadcast.
Why can an IPv6-only host not talk directly to an IPv4-only host, and which three families of transition mechanism bridge the gap?
basics
~20 sIPv4 and IPv6 are separate protocols with different headers and address sizes, so neither stack can read the other's packets. Coexistence comes from dual stack (run both), tunnelling (carry IPv6 inside IPv4) or translation (NAT64 rewriting headers).
Apart from the longer addresses, what are the main design differences between IPv6 and IPv4?
basics
~20 sIPv6 widens addresses to 128 bits and moves work off routers: a fixed 40-byte header with extension headers, no header checksum, source-only fragmentation, multicast instead of broadcast, Neighbor Discovery instead of ARP, built-in autoconfiguration, and no NAT in its base design.
In IPv4 CIDR notation, what does the number after the slash mean, and how do you convert /20 to a dotted-decimal subnet mask and back?
basics
~20 sThe number after the slash is the prefix length: how many leading bits of the 32-bit IPv4 address are network bits. /20 is twenty ones then twelve zeros, 255.255.240.0; counting the ones in 255.255.240.0 gives 20 back.
An IPv4 host's interface shows 169.254.37.12/16 instead of its usual address; what does that address signal, and how did the host choose it?
basics
~20 sIt is an RFC 3927 IPv4 link-local address: the host obtained no address from DHCP or manual configuration and assigned itself one. It picked a pseudo-random address, confirmed it was free with ARP probes, and can reach only hosts on its own link.
Which IPv4 address blocks does RFC 1918 reserve for private networks, and why are they not routed on the public internet?
basics
~10 sRFC 1918 reserves 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. Anyone may reuse them without registration, so they are not unique, and routes and packets for them are kept off inter-network links.
In IPv4, how do you work out the usable host count for a prefix length, and the smallest prefix fitting a host requirement?
basics
~20 sAn IPv4 /n prefix leaves 32 - n host bits: 2^(32 - n) addresses, minus the all-zeros network and all-ones broadcast addresses. To size a subnet, pick the fewest host bits h whose 2^h - 2 covers the hosts needed.
In IPv4 addressing, what is VLSM, and why use it instead of giving every subnet the same mask?
basics
~20 sVLSM (variable-length subnet masking) carves one IPv4 block into subnets with different prefix lengths, each sized to its segment. A single fixed mask must fit the largest segment, which wastes space on small ones and yields too few subnets.
What does an IPv4 router do with each packet it forwards, from the moment it arrives until it leaves?
basics
~20 sAn IPv4 router validates the header, finds the longest matching prefix for the destination address, decrements the TTL, resolves the next hop's link-layer address, sends the packet in a new frame, and then forgets it.
An IPv4 routing table holds 0.0.0.0/0, 10.0.0.0/8, 10.1.0.0/16 and 10.1.1.0/24; which entry forwards a packet to 10.1.1.7, and why?
basics
~10 s10.1.1.0/24 forwards it. All four entries match 10.1.1.7, and IPv4 forwarding picks the longest matching prefix, so the most specific route wins; the default route 0.0.0.0/0 is used only when nothing longer matches.
Why must every IPv4 router decrement a packet's TTL, and how does that end a packet caught in a transient routing loop?
basics
~20 sEach router must lower the 8-bit IPv4 TTL by at least one; at zero it discards the packet and sends ICMP Time Exceeded to the source, so a looping packet dies after a bounded number of hops.
Why does an IPv4 route name its next hop by IP address, and how does the router turn that into a sendable frame?
basics
~20 sRoutes are IP-layer knowledge that must work over any link, so the next hop is an IP address; the router then resolves it to a link-layer address (ARP on IPv4 Ethernet) and frames the unchanged packet to it.
IP forwards every packet independently; why can a connection's replies return by a different path, and what breaks when a stateful firewall sees only one direction?
basics
~20 sRequests are routed by lookups of the server's address and replies by lookups of the client's, often in different routers, so paths can differ; a stateful firewall seeing one direction lacks half the connection and typically drops it.
On an IP router, what are connected, static and default routes, and how does each one get into the routing table?
basics
~20 sA connected route appears when an interface with an address and prefix comes up; a static route is configured by hand; the default route (0.0.0.0/0, ::/0) matches everything and is used only when nothing more specific matches.
When an IPv4 router learns one prefix from a static route, OSPF and BGP, which wins, and how does administrative distance differ from a metric?
basics
~20 sOnly routes for the same prefix compete. Among them the router keeps the source with the best administrative distance, an implementation-defined trust ranking where lower wins; a metric ranks routes only within one protocol. With common defaults the static route wins.
How do distance-vector and link-state routing protocols differ in what each router learns and how it computes its routes?
basics
~20 sA distance-vector router learns only its neighbours' distances to each destination and adds its link cost (Bellman-Ford); a link-state router floods descriptions of its own links, so every router holds the whole topology and runs shortest-path-first itself.
What distinguishes an interior gateway protocol from an exterior gateway protocol, and why is BGP used between autonomous systems instead of an IGP?
basics
~20 sAn interior gateway protocol finds best paths inside one autonomous system; an exterior gateway protocol exchanges reachability between autonomous systems. BGP-4 fills that role because it carries AS paths and applies each operator's policy, which a shared shortest-path metric cannot express.
How does a floating static route back up a BGP-learned default route, and which failures will it fail to catch?
basics
~20 sA floating static route is given a worse administrative distance than the dynamic route, so it stays uninstalled until that route is withdrawn. It misses failures that never withdraw the primary, and dead backup paths behind an up interface.