Subnetting
Posted in Tek on February 7th, 2010 by LazarusA subnet mask determines which part of an ipv4 address refers to the network and which part refers to the host. For example a standard class C private address used in many home ADSL networks might be;
192.168.1.1 with a subnet mask of 255.255.255.0
In binary the subnet mask is: 11111111.11111111.11111111.00000000
All the bits that are switched on (1) are naming the network.
All the bits that are switched off (0) are naming the host.
So in this example 192.168.1.1 describes host number 1 on the network segment 192.168.1
On this network the subnet mask informs us that the last octet is available for host addresses. This includes 0 to 255 minus 2. (255 is reserved for broadcasts and 0 is the network name) Meaning we could have a total of 253 hosts on the 192.168.1.0/24 network.
The ‘/24′ at the end refers to the number of bits in the subnet mask. In a 255.255.255.0 subnet mask 24 bits are switched on (1). Subnet masks expressed in this fashion is called ‘bit notation’.
Subnetting is basically altering the bit length of a network subnet mask to either increase the number of available networks (moving the number of ‘on/1′ bits to the right which therefore decrease the number of hosts) or increasing the number of hosts (by moving the number of ‘off /0′ bits to the left).
Cisco recommend that you should not have more than 500 hosts on a network.
Certainly in most private class A network ranges (10.0.0.0 to 10.255.255.255) the default class A subnet mask would be 255.0.0.0 (11111111.00000000.00000000.00000000) allowing 255 networks and millions of hosts. This would obviously be an unmanageable number of hosts and so the subnet mask will normally be ’subnetted’ to increase the number of available networks while also reducing the available number of hosts on each network. This would be accomplished by moving the on (1) bits to the right changing the mask from 255.0.0.0 to, perhaps, 255.255.255.0 or 255.255.128.0 any other combination that gives the desired balance of network/host addresses.
To create more networks
1) determine number of networks and convert to binary (right to left)
2) reserve bits in subnet mask and find your increment (lowest bit, left to right – add the number of bits it takes to represent the desired number of networks in decimal to the subnet mask from left to right – the lowest bit at the far right is the increment.)
3) use increment to find your network ranges
To create more hosts
1) determine number of hosts and convert to binary
2) reserve bits in subnet mask and find your increment
(tweak = save the hosts! work out how may bits it takes to represent the desired number of hosts in binary and save that many zeros in the mask from right to left – all zeros in the mask that aren’t in the reserved portion are converted to 1.)
3) use increment to find your network ranges
if subnetting the next range is 256 carry the one to the left octet until the one can be added without exceeding 255.
Reverse engineering subnets
is this ip address valid? what range does it belong to? = 192.168.1.127, 255.255.255.224
the answer is 224…
what increment was used to build the network ranges? the lowest subnet mask octet and break into binary and find the lowest bit value (left to right) so it’s 32.
192.168.1.0
192.168.1.32
192.168.1.64
192.168.1.96 – 192.168.1.127 = ip address belongs to this range but is invalid as is last address of the range and so is the broadcast address.
192.168.1.128
The great exception
because binary begins counting from zero
these network values may throw off calculations for the number of networks;
2, 4, 8, 16, 32, 128
these host values may throw off calculations for number of hosts,
3, 7, 15, 31, 127
to play it safe;
subtract 1 when finding networks (ie if asked to find 128 networks subtract 1 and find it on 127 networks)
add 1 when finding hosts (ie if asked to find 63 hosts add 1 and find 64 hosts)