Subnets
What is a Subnet
A subnet or subnetwork is a small LAN (Local Area Network) which forms part of a WAN (Wide Area Network). Using subnets (instead of one big network) can reduce network traffic and reduce network bottle necks.
From an IP address point of view, subnets are ranges of contiguous IP addresses. With IPv4 addresses, subnets are usually specified by either a base IP addresses and a dotted decimal netmask (eg. 192.0.2.28/255.255.255.248) or in CIDR format (eg. 192.0.2.28/29).
Netmasks
A dotted decimal netmask specifies the bits of the IP address which are fixed and which bits form the subnet. If a bit in the netmask is set, the corresponding bit in the IP address is fixed. This means that it forms part of the network ID (ie. This means that this bit of the address is the same for all hosts on the subnet). If a bit in the netmask is clear, the corresponding bit in the IP address forms the host ID (ie. This means that this bit of the address is different for all hosts on the subnet, and is used to identify a host on the subnet).
CIDR format consists of a base IP address and an integer. The integer specifies the number of bits which form the network ID, starting from the most significant bit.
This table shows some netmask examples:
Dotted Decimal Netmask | CIDR Mask | Binary Mask | Number of Addresses |
---|---|---|---|
255.0.0.0 | /8 | 11111111 00000000 00000000 00000000 | 16,777,216 |
255.240.0.0 | /12 | 11111111 11110000 00000000 00000000 | 1,048,576 |
255.255.0.0 | /16 | 11111111 11111111 00000000 00000000 | 65,536 |
255.255.255.0 | /24 | 11111111 11111111 11111111 00000000 | 256 |
255.255.255.248 | /29 | 11111111 11111111 11111111 11111000 | 8 |
With the dotted decimal netmask it is possible to configure a non contiguous ip address range. Although it's possible, I can't think of a good reason for doing so. It will almost certainly cause confusion and make it harder to manage IP address allocation!
Allocating IP Addresses
With an IP address subnet, not all addresses will be able to be assigned to hosts. The first IP address in a subnet is the network address. The last IP address in a subnet is the broadcast address. So with a /24 (255.255.255.0) network, although there are 256 addresses, only 254 can be assigned to hosts. In most situations you will also have to use one IP address for the gateway, so this would reduce the available addresses to 253.