Intro
A network can be divided into multiple smaller networks due to organizational needs and for security reasons. Each of this smaller network is called a subnet. This is achieved with the use of a subnet mask.
Subnet
Every IP address in a subnet has 2 portions; the network portion and the host portion. The network portion identifies the subnet and the host portions contains the addresses within that subnet.
A subnet is specified using what’s called a Classless Inter-Domain Routing (CIDR) notation where you specify the first IP address of a network, followed by a forward slash (/) and ending with a number denoting the number of bits for the subnet mask.
Subnet mask
A subnet mask is the number of bits which denotes the network portion of an IP address and the remainder of the bits denotes host portion of the IP address.
If the CIDR is 192.168.1.0/24, it means the first 24 bits are the network portion and 8 bits are the host portion. Therefore, this subnet contains 28 or 256 IP addresses ranging from 192.168.1.0 to 192.168.1.255.
Binary form | Dot-decimal notation | |
IP address | 11000000.10101000.00000001.01111000 | 192.168.1.120 |
Subnet mask | 11111111.11111111.11111111.00000000 | 255.255.255.0 |
Network portion | 11000000.10101000.00000001.00000000 | 192.168.1.0 |
Host portion | 00000000.00000000.00000000.01111000 | 0.0.0.120 |
If the CIDR is 192.168.0.0/16, it means the first 16 bits are the network portion and 16 bits are the host portion. Therefore, this subnet contains 216 or 65536 IP addresses ranging from 192.168.0.0 to 192.168.255.255.
Binary form | Dot-decimal notation | |
IP address | 11000000.10101000.00000101.01111000 | 192.168.5.120 |
Subnet mask | 11111111.11111111.00000000.00000000 | 255.255.0.0 |
Network portion | 11000000.10101000.00000000.00000000 | 192.168.0.0 |
Host portion | 00000000.00000000.00000101.01111000 | 0.0.5.120 |
Reasons to subnet
On the global scale, subnets are made to be able to better allocate and utilize the limited IPv4 address ranges. This way, more organizations can get their IP address allocations as the ranges are much smaller.
In private networks, subnetting allows better access control and security for resources like files, servers and so forth. E.g. marketing department may be in one subnet while the engineering department may be in another. So, documents that are relevant to the marketing department will not be accessible by the engineering department and vice-versa.
Subnetting also improves performance on the local network since broadcast messages are only sent to those in the same subnet.