In computer networking, a subnet is a piece of a larger network where all devices in that piece can physically reach each other without passing through an intervening router, i.e., they are directly connected to each other with a link layer technology.

IP addresses have a structure:

  • Subnet part: devices in the same subnet have common higher-order bits.
  • Host part: the remaining lower-order bits.

Addressing

To define a subnet, we detach each interface from its host or router, creating “islands” of isolated networks. This leads us to be able to define IP addresses according to the subnets. This formatting is called the classless interdomain routing (CIDR).

IPv4 addresses are made up of 4 bytes separated by periods. A subnet is defined by an IP/mask format: like 192.168.1.0/24. In this case, the mask /24 denotes that the upper 24-bits are all kept unchanged, and the remaining addresses in the range start from all 0s to all 1s. So smaller mark numbers indicate a wider range of addresses.1

In other words, 192.168.1.0/24 ranges from 192.168.1.0 to 192.168.1.255.

Okay, suppose we want to create a subnet with up to n hosts each, given an organisation with a certain class address. This class defines how many hosts are allocated to that network, with m host ID bits.

  • We need to find how many hosts need to be in the subnet, by taking the binary . Suppose we need 100 hosts in each subnet. This means 7 bits are sufficient.
  • Then, suppose we have a class B address with 16-bit host IDs. This means: 16 - 7 = 9 bits for the subnet ID.
  • Then, the mask is 16 + 9 = 25.

CIDR

This allows the classful addressing scheme to be combined into a larger contiguous group of addresses, without taking up an entire next block, called supernetting. This allows, for example, a subnet that consists of multiple group C blocks without incurring the space of a group B block.

What this means is that a single larger subnet can be represented with a single CIDR-style IP/mask addressing scheme. This means that routing tables don’t have to grow as large to store essentially the same information.

Routing

Hosts and routers maintain a routing table to determine where to send their packets.

  • In the originating host, it consults its routing table.
    • If the destination host is in the same network, then the packet is sent directly with the link layer technology.
    • Otherwise, it is sent indirectly, often via a default router.
  • In the router, it examines the IP destination address.
    • If the destination isn’t its own, the routing table is consulted to determine the next hop and associated network interface. Then, it forwards the packet.

Footnotes

  1. Remember from Wikipedia, why IP ranges are never blocked lower than /16?