# Subnetting
## What is Subnetting
Subnetting is the practice of dividing a single large network into smaller logical subnetworks called subnets. By borrowing bits from the host portion of an IP address and using them as additional network bits, an administrator can create multiple smaller networks from a single larger network block. Subnetting improves network management, increases security by isolating groups of devices, reduces broadcast traffic by limiting the size of broadcast domains, and allows more efficient use of the available IP address space.
## Subnet Mask
A subnet mask is a 32-bit number used alongside an IP address to determine which portion of the address represents the network and which portion represents the host. In a subnet mask, all network bits are set to 1 and all host bits are set to 0. The subnet mask 255.255.255.0 in binary is 11111111.11111111.11111111.00000000, indicating that the first 24 bits are the network portion and the last 8 bits are the host portion. When the subnet mask is applied to an IP address using a logical AND operation, the result is the network address.
## How Subnetting Works
To create subnets, bits are borrowed from the left side of the host portion of the address and added to the network portion. Each bit borrowed doubles the number of possible subnets but halves the number of available host addresses per subnet. If you borrow 2 bits, you can create 4 subnets. If you borrow 3 bits, you can create 8 subnets. The formula for the number of subnets is 2 to the power of n, where n is the number of bits borrowed. The formula for the number of usable host addresses per subnet is 2 to the power of h minus 2, where h is the number of remaining host bits. Two addresses are subtracted because the network address and the broadcast address within each subnet cannot be assigned to hosts.
## Subnetting Example
Consider the network 192.168.1.0/24. This gives 254 usable host addresses. If you need to divide this into 4 subnets, you borrow 2 bits from the host portion, creating a /26 network. Each subnet has 6 host bits remaining, giving 64 total addresses per subnet, of which 62 are usable. The four subnets are 192.168.1.0/26 with usable addresses from .1 to .62 and broadcast .63, then 192.168.1.64/26 with usable addresses from .65 to .126 and broadcast .127, then 192.168.1.128/26 with usable addresses from .129 to .190 and broadcast .191, and finally 192.168.1.192/26 with usable addresses from .193 to .254 and broadcast .255.
## Block Size Method
A practical shortcut for subnetting is the block size method. The block size is the number of addresses in each subnet, calculated as 2 to the power of the number of host bits. For /26, the block size is 64. Subnets start at multiples of the block size within the interesting octet. For a /26 in the last octet, subnets start at 0, 64, 128, and 192. The broadcast address of each subnet is one less than the start of the next subnet.
## Benefits of Subnetting
Subnetting reduces broadcast traffic because broadcasts are contained within each subnet and do not propagate to other subnets. It improves security by allowing network policies and firewall rules to be applied at subnet boundaries. It enables better organization of devices by grouping devices by department, function, or location into separate subnets. It allows more efficient use of IP address space by allocating only as many addresses as each subnet needs.Back to Subject