CSEC3616Cybersecurity Engineering

    Network layer: IP addressing, subnets, NAT and IPv6

    What the network layer does, how IPv4 addresses and subnets are structured, the unit's own worked subnetting example, NAT, and what actually changes moving to IPv6.

    • Explain what the network layer does at the sending and receiving host, and name its three components.
    • Define an IPv4 address and what an interface is.
    • Compute the subnets, usable host ranges and broadcast addresses for a given IP address and CIDR prefix.
    • Explain what NAT does and why it exists.
    • List what changed from IPv4 to IPv6, and why the migration is still incomplete.

    20 min readJump to the quiz ↓

    The network layer carries datagrams between hosts

    The network layer gets a segment from one host to another, potentially across many organisations’ networks. Every interface that sends or receives a datagram needs an address the network can use to find it.

    The network layer, also called the Internet layer, transports a segment from the sending host to the receiving host. At the sender, it encapsulates segments into datagrams and passes them to the link layer. At the receiver, it delivers those segments back up to the transport layer. Every Internet device with a network layer, hosts and routers alike, runs this layer’s protocols. Routers, specifically, examine header fields in every IP datagram passing through them and move each datagram from an input port to an output port, along the path toward its destination.

    The network layer has three components. The IP protocol itself defines the fields in a datagram and how end systems and routers act on them: there is exactly one such protocol, and it is the topic of the rest of this page. The routing component determines the path a datagram takes from source to destination, using path-selection algorithms implemented in routing protocols such as OSPF and BGP, or in software-defined networking controllers; these compute the forwarding tables that move packets through the network. The third component, ICMP (Internet Control Message Protocol), reports errors in datagrams and answers requests for network-layer information.

    An IP datagram itself has a header and a payload. The header carries fields including the source and destination IP address, the protocol in use, a time-to-live (TTL) value, a checksum, and a version field that states whether the datagram is IPv4 or IPv6. The maximum size of a datagram is set by the underlying network’s Maximum Transmission Unit (MTU), often 1500 bytes for Ethernet; a datagram exceeding it is fragmented into smaller pieces.

    IPv4 identifies interfaces; subnet bits define their network

    An IPv4 address is a 32-bit identifier associated with each host or router interface, the connection between that host or router and a physical link. A router typically has multiple interfaces; a host typically has one or two, for example a wired Ethernet interface and a wireless 802.11 interface. With 32 bits there are 2^32 possible addresses, written in dotted-decimal notation: each of the four bytes written as a decimal number, separated by dots, for example 223.1.1.1.

    A subnet is a set of device interfaces that can reach each other physically without an intervening router. Detaching every interface from its host or router leaves “islands” of interconnected devices, each island is one subnet. An IP address has structure to match: a subnet part, the high-order bits shared by every device in the same subnet, and a host part, the remaining low-order bits that distinguish devices within it. CIDR (Classless Inter-Domain Routing) notation writes this split explicitly, an address followed by a slash and the number of bits belonging to the network portion, for example /26.

    The lecture material also gives the older, class-based way of dividing up IPv4 space: Class A (0.0.0.0 to 127.255.255.255, default mask 255.0.0.0), Class B (128.0.0.0 to 191.255.255.255, default mask 255.255.0.0), Class C (192.0.0.0 to 223.255.255.255, default mask 255.255.255.0), Class D (224.0.0.0 to 239.255.255.255, multicast), and Class E (240.0.0.0 to 255.255.255.255, experimental). CIDR replaced this rigid class-based system in practice, allowing a network to be divided more flexibly than a fixed class boundary allows, which is exactly what the worked example below does to a Class C address.

    Borrowed bits determine subnets and usable hosts

    Formula

    Number of subnets from borrowed bits

    2s2^{s}
    ss
    number of bits borrowed from the host portion for subnetting

    Formula

    Usable hosts per subnet

    2h−22^{h} - 2
    hh
    number of bits remaining for the host portion

    The 2 subtracted are the subnet's own network address and broadcast address.

    Try it — worked example

    Network 192.168.10.0 with mask 255.255.255.192 (/26). How many subnets, how many usable hosts each, and where does each subnet start?

    Show answer and steps

    Answer192.168.10.0/26 splits into 4 subnets of 62 usable hosts each, at .0, .64, .128 and .192.

    Given: IP address 192.168.10.0, subnet mask 255.255.255.192 (/26 in CIDR notation).

    1. Convert the subnet mask to binary, one octet at a time: 255 = 11111111, 255 = 11111111, 255 = 11111111, 192 = 11000000. The full mask in binary is 11111111.11111111.11111111.11000000.

    2. A /26 prefix means 26 bits belong to the network portion, leaving 32 - 26 = 6 bits for the host portion.

    3. Number of subnets: this is a Class C base network (24 network bits by default), so the bits borrowed for subnetting are 26 - 24 = 2. By 2s2^{s} with s=2s = 2: 22=42^2 = 4 subnets.

    4. Hosts per subnet: 6 bits remain for hosts. By 2h−22^{h} - 2 with h=6h = 6: 26−2=64−2=622^6 - 2 = 64 - 2 = 62 usable hosts per subnet, after subtracting the subnet’s network address and its broadcast address.

    5. Block size: 256 - 192 = 64. Each subnet therefore spans 64 addresses, and the four subnets are:

    6. Subnet 1: 192.168.10.0/26. Network address 192.168.10.0; first usable host 192.168.10.1; last usable host 192.168.10.62; broadcast address 192.168.10.63.

    7. Subnet 2: 192.168.10.64/26. Network address 192.168.10.64; first usable host 192.168.10.65; last usable host 192.168.10.126; broadcast address 192.168.10.127.

    8. Subnet 3: 192.168.10.128/26. Network address 192.168.10.128; first usable host 192.168.10.129; last usable host 192.168.10.190; broadcast address 192.168.10.191.

    9. Subnet 4: 192.168.10.192/26. Network address 192.168.10.192; first usable host 192.168.10.193; last usable host 192.168.10.254; broadcast address 192.168.10.255.

    Pitfall

    The network address and the broadcast address of a subnet are never assignable to a host, which is exactly why the hosts-per-subnet formula subtracts 2. In the worked example, 192.168.10.128 identifies Subnet 3 itself and 192.168.10.191 is its broadcast address; a host must sit strictly between them, 192.168.10.129 through 192.168.10.190.

    NAT shares one public IPv4 address using ports

    NAT (Network Address Translation) exists because IPv4’s roughly four billion addresses are not enough for every device everyone now owns, phones, laptops, tablets, all online at once. NAT lets all devices in a local network share a single IPv4 address as far as the outside world is concerned, proposed in 1994 as a response to that address exhaustion. A NAT-enabled router keeps a translation table mapping each internal device’s private address and a chosen port number to the one shared public address and a distinct port: for example, a public address and port of 138.76.29.7, 5007 mapping back to an internal 10.0.0.1, 3345. This also provides a side benefit: outside devices cannot directly address anything inside the local network, since they only ever see the single shared public address.

    IPv6 expands addresses and simplifies the header

    IPv6 answers the same address-exhaustion problem NAT works around, by moving from 32-bit to 128-bit addresses, enough for every device on Earth to have a unique public address, removing the need for NAT entirely. Its header is also redesigned: a fixed 40-byte header speeds up router processing, the header checksum and hop-by-hop fragmentation are removed and pushed to the network’s edges instead, and a 20-bit field lets routers identify and prioritise specific traffic flows. IPsec support was built in as a core design requirement from the start, rather than added on afterward. The migration from IPv4 is still not finished; the unit names compatibility, financial return on investment, and the existence of NAT itself as the reasons why.

    The IP hourglass is the shape of the whole stack: the Internet has exactly one network-layer protocol, IP, and it must be implemented by every one of the billions of Internet-connected devices. Many application protocols run above it and many link technologies run below it, but everything funnels through this single, narrow waist in the middle.

    Exam detail

    For any subnetting question, work the same four numbers every time: the block size (256 minus the last non-zero octet of the mask), the number of subnets (2s2^{s} for ss borrowed bits), the usable hosts per subnet (2h−22^{h} - 2 for hh remaining host bits), and then the four values per subnet, network address, first host, last host, broadcast, exactly as laid out in the worked example above.

    Recall

    A host has the address 192.168.10.200 on the 192.168.10.0/26 network from the worked example. Which subnet is it in, and what is that subnet's broadcast address?

    192.168.10.200 falls in Subnet 4, 192.168.10.192/26, which runs from 192.168.10.192 to 192.168.10.255. Its broadcast address is 192.168.10.255.

    Check yourself