Skip to content
Telecom Networks

IP addressing: CIDR, subnets, longest prefix, NAT and IPv6

IPv4 addresses and CIDR notation, the number of hosts proved, subnet calculation with an example, aggregation and longest prefix, ARP and DHCP, NAT, fragmentation and MTU, IPv6.

The IP protocol is the meeting point of the whole Internet: above it there are thousands of applications, below it tens of link technologies, and in between a single packet format and a single addressing scheme. In this lesson we look at IPv4 addresses and CIDR notation, subnet calculation with an example and the proof of the number of hosts, address aggregation, the longest-prefix rule, the support protocols ARP and DHCP, NAT, fragmentation and IPv6.

IPv4 addresses

An IPv4 address is a 32-bit number, written as four bytes in decimal separated by dots: 192.168.10.70. Every address is divided into two parts: a network prefix, common to all the interfaces of the same network, and a host part. With CIDR notation (classless inter-domain routing) the prefix length is written after a slash: 192.168.10.0/24 denotes the network whose addresses share the first 24 bits. The same information is the mask 255.255.255.0, with 24 bits set to 1.

Theorem. A network with an n-bit prefix contains 2^{32-n} addresses, of which 2^{32-n} - 2 can be assigned to interfaces.

Proof. The 32 - n host bits can take 2^{32-n} different combinations. Two are reserved: the one with all host bits 0 identifies the network itself, the one with all 1s is the network’s broadcast address. ∎

A /24 therefore has 254 hosts, a /16 65 534. For point-to-point links between two routers /31s are used, with only two combinations, for which the rule makes an exception.

Subnets

Division of an IPv4 address into network prefix, subnet and host
Top, the /24 network: 24 prefix bits and 8 host bits, i.e. 256 addresses. Bottom, the same network divided into /26 subnets: two bits taken from the host part identify four subnets, each with 64 addresses.

A company with the network 192.168.10.0/24 wants four separate networks for four departments. It borrows 2 bits from the host part, obtaining /26 prefixes: four subnets, each of 2^6 = 64 addresses and 62 hosts.

SubnetFirst hostLast hostBroadcast
192.168.10.0/26.1.62.63
192.168.10.64/26.65.126.127
192.168.10.128/26.129.190.191
192.168.10.192/26.193.254.255

Host 192.168.10.70 is in the second subnet: its last 8 bits are 01000110, and the first two, 01, indicate subnet number 1 (counting from 0). A host compares its own prefix with that of the destination: if they match, it delivers directly on the local network, otherwise it sends the packet to its default router (gateway).

Aggregation and the longest prefix

CIDR allows aggregation: the four networks 10.4.0.0/24, 10.4.1.0/24, 10.4.2.0/24, 10.4.3.0/24 share the first 22 bits and are announced as a single 10.4.0.0/22. Aggregation is possible when the blocks are contiguous and aligned: 2^k consecutive blocks starting at a multiple of 2^k. Thanks to aggregation the tables of the routers in the core of the Internet have about a million entries instead of billions.

A table may contain overlapping prefixes. The rule is the longest prefix: the most specific entry matching the address is used. With entries 10.0.0.0/8 towards R1, 10.1.0.0/16 towards R2 and 10.1.2.0/24 towards R3, the packet for 10.1.2.5 goes to R3, the one for 10.1.9.9 to R2 and the one for 10.7.0.1 to R1. The entry 0.0.0.0/0, which matches everything, is the default route. Routers find the longest prefix in nanoseconds with tree structures and associative memories (TCAMs).

ARP and DHCP

To deliver a packet on the local network the MAC address of the destination or of the router is needed (lesson on Ethernet). The ARP protocol asks for it with a broadcast: “who has address 192.168.10.1?”, and the owner answers with its MAC, which is remembered for a few minutes. DHCP automatically assigns a newly connected device its IP address, mask, default router and DNS servers, with a four-message broadcast exchange.

NAT

IPv4 addresses number about 4 billion, fewer than the connected devices. The practical solution is NAT (network address translation): a home or company network uses private addresses (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), not routed on the Internet, and the router translates the outgoing source address and port into those of its own public address, remembering the mapping to translate replies back. Hundreds of devices thus share one public address. The price is that a connection to an internal device cannot be started from outside without special configuration.

Fragmentation

Every link has a maximum packet size, the MTU (1500 bytes for Ethernet). In IPv4 a router can split a packet that is too large into fragments, reassembled by the destination; but losing one fragment loses the whole packet, and today path MTU discovery is preferred: packets are sent with fragmentation forbidden, and if a router replies that they are too large the source makes them smaller.

IPv6

IPv6 uses 128-bit addresses, written in hexadecimal in 16-bit groups: 2001:db8:4a2::1f. The space is practically inexhaustible: an ordinary local network receives a /64, i.e. 2^{64} addresses. The header is simplified, routers no longer fragment, and devices can configure themselves by combining the prefix announced by the router with their own identifier. In 2025 about half of accesses to Google happen over IPv6, and the two versions coexist through dual-stack and translation mechanisms.

Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
0
Would love your thoughts, please comment.x
()
x