← Back to Networking

IP and addressing

The network layer moves datagrams from source host to destination host across many networks. The Internet Protocol and its addressing scheme are the glue of the whole internet.

Forwarding and routing

The network layer has two key functions. Forwarding is the local action of moving an arriving packet from a router's input link to the appropriate output link, done in nanoseconds in hardware. Routing is the network-wide process of computing the paths packets should take, done by routing algorithms in software over seconds or minutes. Routing fills the forwarding tables that forwarding uses.

The IPv4 datagram

An IPv4 header, usually 20 bytes, includes the version, header length, type of service (now differentiated services and ECN bits), total length, fields for fragmentation, time-to-live (TTL), the upper-layer protocol number (6 for TCP, 17 for UDP), a header checksum, and 32-bit source and destination addresses. Each router decrements TTL and discards the datagram if it reaches zero, preventing endless loops.

IPv4 addresses

An IPv4 address is 32 bits, written as four decimal numbers in dotted-decimal notation, such as 192.0.2.17. Addresses are assigned to interfaces, not hosts: a router with four links has four addresses. With 2^32, about 4.3 billion, possible addresses, IPv4 space has effectively run out; most regional registries exhausted their free pools between 2011 and 2019.

Subnets and CIDR

Classless Inter-Domain Routing (CIDR), introduced in 1993, writes addresses with a prefix length: 203.0.113.0/24 means the first 24 bits identify the network and the remaining 8 bits identify hosts, giving 256 addresses (254 usable, since the all-zeros and all-ones host values are reserved). A subnet is a set of interfaces sharing a prefix that can reach each other without a router.

Route aggregation

CIDR lets ISPs advertise one prefix covering many customers: an ISP holding 198.51.0.0/16 can give its customers smaller blocks such as /24s yet announce just the /16 to the rest of the internet. This aggregation keeps global routing tables manageable, though the full table still holds roughly a million IPv4 prefixes.

Longest-prefix matching

A router's forwarding table holds prefixes, and a destination address may match several. The router uses the longest matching prefix, the most specific route. If a table has 10.0.0.0/8 to link 1 and 10.1.2.0/24 to link 2, a packet for 10.1.2.5 goes to link 2, while one for 10.9.9.9 goes to link 1. Fast hardware such as TCAM performs these lookups at line rate.

Fragmentation

Each link has a maximum transmission unit (MTU), 1,500 bytes for standard Ethernet. IPv4 routers can fragment datagrams too large for the next link, with the destination reassembling them using identification, flag, and offset fields. Fragmentation hurts performance and complicates security, so hosts prefer path MTU discovery, sending datagrams marked 'don't fragment' and adjusting when routers report they are too big.

Worked example

For 172.16.40.130/26: 26 network bits leave 6 host bits, so the block holds 2^6 = 64 addresses. 130 in binary is 10000010; the top two bits of the last byte belong to the prefix (since 26 = 24 + 2), giving the network address 172.16.40.128. The block runs from .128 to .191: .128 is the network address, .191 the broadcast address, and .129 to .190, 62 addresses, are usable for hosts.

Key takeaways

Forwarding moves packets from input to output links using tables; routing computes paths to fill those tables. The IPv4 header includes TTL, protocol, checksum, and 32-bit addresses; TTL prevents loops. Addresses belong to interfaces, and IPv4's 4.3 billion addresses are exhausted. CIDR prefixes such as /24 define subnets and allow route aggregation. Routers forward by longest-prefix match. MTUs, 1,500 bytes on Ethernet, may force fragmentation, which path MTU discovery avoids.

Flashcard

Forwarding

Moving a packet to the right output link

Data plane, nanoseconds.

Check your understanding

A router's table has 10.0.0.0/8 via link A and 10.20.0.0/16 via link B. Where does a packet to 10.20.7.1 go?

← Previous lesson Next lesson →