The main purpose of subnetting is to help relieve network congestion.
1. Improve network performance and speed
2. Reduce network congestion
3. Boost network security
4. Control network growth
5. Ease administration
Bits Subnet-Mask
11111111 /32 .255
1111111 /31 .254
111111 /30 .252 64 Nets 2 hosts
11111 /29 .248 32 Nets 6 hosts
1111 /28 .240 16 Nets 14 hosts
111 /27 .224 8 Nets 30 hosts
11 /26 .192 4 Nets 62 hosts
1 /25 .128 2 Nets 126 hosts
Class C first octet 192-223
/24 .0
/23 .254
/22 .252
/21 .248
/20 .240
/19 .224
/18 .192
/17 .128
Class B first octet 128-191
/16 .0.0
/15 .254
/14 .252
/13 .248
/12 .240
/11 .224
/10 .192
/9 .128
Class A first octet 1-126
/8 .0.0.0
/7 .254
/6 .252
/5 .248
/4 .240
/3 .224
/2 .192
/1 .128
/0
Example Giving 172.16.200.0/29
1. How many Networks are created?
2. How many Hosts are created?
3. What is the Network Number?
4. What is the Subnet mask?
5. What is the Broadcast?
Calculation
For a /24 network 00000000 to be used as a /29 11111000, it means, you will have to borrow 5 host bits 11111 to be used as network, and that leaves us with 3 bits 000 for hosts.
11111000 /29 .248 32 Nets 6 hosts
1. How many Networks are created?
Formula n^2 (number of network bits raised to the 2nd power)
n^2 = 5^2 = 32 Networks created
2. How many Hosts are created?
Formula 2^n -2 (2 raised to the number of host bit power, minus 2 for network mask and subnet mask.
2^n -2 = 2^3 -2 = 8-2 = 6 hosts per subnet
3. What is the Network Number?
Examples of the 32 subnets
172.16.200.0/29 Network .0 Hosts .1 .2 .3 .4 .5 .6 Broadcast .7
172.16.200.8/29
172.16.200.16/29
172.16.200.24/29
172.16.200.32/29
172.16.200.40/29
172.16.200.48/29
172.16.200.56/29
172.16.200.64/29
4. What is the Subnet mask?
1 1 1 1 1 0 0 0
00000000 = 2^7 + 2^6 + 2^5 + 2^4 + 2^3 + 2^2 + 2^1 + 2^0
11111000 = 128 + 64 + 32 + 16 + 8 + 0 + 0 + 0
= 248
So subnet mask = 255.255.255.248
5. What is the Broadcast?
172.16.200.0/29 = Network 172.16.200.0 subnet mask 255.255.255.248 net mask /29
Broadcast 172.16.200.7
IP Addressing IP addressing refers to assigning a 32-bit logical numeric address to a network device. Every IP address on the network must be unique. An IP address is represented in a dotted decimal format, for example: 159.101.6.8
As you can see the address is divided in 4 parts, these parts are called octets. IP is defined at Layer 3 (Network layer) of the OSI model and is routable. In order to be routable a network address must have two parts: a network and a host portion. Subnet masks are used to determine which part represents the network portion and which part represents the host portion. By default the subnet mask is based on the class to which the IP address belongs. The following table lists the classes and corresponding values of the first octet (in the IP address) and the default subnet mask.
Major classes | First octet | Default mask |
Class A | 1 - 126 | 255.0.0.0 |
Class B | 128 - 191 | 255.255.0.0 |
Class C | 192 - 223 | 255.255.255.0 |
Subnetting
Before we go to actually calculating subnets (i.e. subnetting) I want to stress the meaning of the word “subnet mask”. As the name implies, it is a mask that determines what portion of an IP address is the (sub-)network portion. Combined with knowing the class of the IP address it also determines the number of subnets. Although that automatically gives us the host portion as well, it important to realize the class does not influence the number of hosts in a subnet. For example, a class A network with a subnet mask of 255.255.255.0 allows for 254 hosts, which is the same for a class B or class C network with the same subnet mask of 255.255.255.0.
So to determine the maximum number of hosts in a (sub-)network, all you need to know is the subnet mask, or even better: the “prefix”. The class and even the IP address itself are irrelevant when it comes to calculating the maximum number of hosts.
For example, a typical subnetting exam questions might present you with an IP address and a subnet mask or prefix and ask for the total number of hosts and/or subnets. Let’s say the network address is 192.168.1.0 255.255.255.224. To determine the number of hosts we need to translate the mask to a prefix, because that gives us the maximum number of bits we have left for hosts. In this case the prefix is /27 (we’ll get to translation process in detail later) which leaves 5 bits from the 32 bits in an IPv4 address in total. So that’s 5 bits for hosts, which is 5^2 = 32. However, the first address is the network address for the subnet, and the last is the broadcast address, so we need to subtract 2 for those, leaving us with 30 addresses for hosts.
Now, what if the IP address would have been 10.12.3.88, or 179.192.32.254? Or if no IP address was mentioned at all and all we got to go on was the mask? Exactly, it would have made no difference to the number of maximum hosts. So to conclude, the subnet mask doesn’t merely determine what portion of a given IP address is the network portion and what portion is for host, but by itself, without any additional info, a subnet mask can tell you directly how much space it allows for host addresses “per subnet”.
More often we (also) need to know the number of subnets, for which we need one more piece of info than just the subnet mask or prefix, and that’s the class of the IP address. The IP address itself is again irrelevant, except for the first octet, which as shown in the intro above determines the class.
So far we stressed the importance of knowing the prefix and knowing the default subnet mask for the major IP address classes. There is one more thing you need to add to your subnetting toolkit, or actually should be in there already, and that is basic binary math. In particular there are two essential “formulas” you cannot do without:
1. Calculate the maximum number of different decimal values a given amount of bits can represent:
This is really basic binary math. 1 bit allows for 2 different values, 2 bits allows for 4 different values, 3 bits allow for 8 different values. So for every bit you add, the number of possible different values doubles. This can also be written as b^2 where b is the number of bits. Memorizing the first 10 or so is as easy as learning basic multiplication tables back in high school:
1 bit – 2 values
2 bits – 4 values
3 bits – 8 values
4 bits – 16 values
5 bits – 32 values
6 bits – 64 values
7 bits – 128 values
8 bits – 256 values
9 bits – 512 values
10 bits – 1024 values
Again, extending the list is easy because all you need to do is double the previous amount of values for every bit you add. Just remember to start with 2 for the first bit (value 0 and value 1).
The b^2 formula is used to determine the maximum number of subnets and the maximum number of hosts per subnet. For example if you have a class B network with a prefix of /18 you have 2 bits for subnets, which according to the formula and table above means space for 4 different subnets.
When determining the maximum number of hosts in a subnet you need to subtract 2 of the results, one for the network address of the subnet and one for the broadcast address. So basically the formula for hosts is (b^2) - 2.
2. Translate octets from their binary value to their decimal equivalent and back.
The second “bit” of binary math you need to master is translating 8 bits (a byte) to its decimal equivalent (an octet). So instead of looking for the maximum number of different values, we’re going to determine the actual decimal value a given number of bits represent.
Each octet represents 8 bits, for example the IP address 159.101.6.8 mentioned earlier can also be displayed in dotted binary format: 10011111.01100101.00000110.00001000
Converting the decimal address to a binary format (and vice versa) is a fairly easy process. The lowest decimal number you can represent with 8 bits is 0 (when all bits are zero, as in turned off), the highest is 255 (all bits turned on) as shown in the following translation table:
1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
128 + | 64 + | 32 + | 16 + | 8 + | 4 + | 2 + | 1 | = 255 |
0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 | |
0 + | 0 + | 0 + | 0 + | 8 + | 4 + | 0 + | 1 | = 13 |
1 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | |
128 + | 0 + | 32 + | 0 + | 8 + | 0 + | 2 + | 0 | = 170 |
Binary | Decimal |
00000000 | 0 |
00000011 | 3 |
10000000 | 128 |
10000001 | 129 |
10111111 | 191 |
11111010 | 250 |
Although this works for IP addresses and subnet masks, the latter are a little special. In subnet mask the bits are always consecutive. For example, the subnet mask 255.0.0.0 is written in binary as 11111111.00000000.00000000.00000000 and the subnet mask 255.255.240 is written as 11111111.11111111.11110000.00000000. The number of consecutive ‘1’ bits equals the prefix. So for the first example, the subnet mask 255.0.0.0, the prefix is 8 bits, and for the last example, the subnet mask 255.255.240, the prefix is 8+8+4=20 bits. To determine the decimal value for the third octet (11110000) we add up the first 4 values (1 for each bit turned on) in our translation table, starting from the left: 128+64+32+16 = 240.
After some practice this should become basic and easy math, but since the bits in a mask are always consecutive there is a limit to amount of possible values in a mask. Specifically the following 8:
8 bits = 11111111 = 128+64+32+16+8+4+2+1 = 255
7 bits = 11111110 = 128+64+32+16+8+4+2= 254
6 bits = 11111100 = 128+64+32+16+8+4 = 252
5 bits = 11111000 = 128+64+32+16+8 = 248
4 bits = 11110000 = 128+64+32+16 = 240
3 bits = 11100000 = 128+64+32 = 224
2 bits = 11000000 = 128+64 = 192
1 bits = 10000000 = 128 = 128
0 bits = 00000000 = 0 = 0
Simplified the table looks like this:
8 bits = 255
7 bits = 254
6 bits = 252
5 bits = 248
4 bits = 240
3 bits = 224
2 bits = 192
1 bits = 128
0 bits = 0
The decimal values on the right are the only valid values you will find in a subnet mask and I highly recommend memorizing this table (and if needed dump it on the sheet you get during the exam for quick reference). Besides translating individual octets, the table above is very helpful to determine the prefix based on the subnet mask. For example, the subnet mask 255.255.192.0 obviously equals a prefix of 8+8+2= /18. The other way around is almost as easy and becomes more obvious when written in binary format. For example, if you take the prefix /25 and write it in binary format you end up with:
11111111.11111111.11111111.10000000
This according to our table, if we translate the octets individually, is 255.255.255.128. Basically for every prefix above /8 you subtract 8 and write an octet of 255 until you have 8 bits or less left.
Determine the network and broadcast address
Besides calculating the number of subnets and hosts, another common task regarding subnetting is to determining the network and broadcast address for a given subnet. The network address is the first address in a subnet and the broadcast address is the last address. For example, in the class C network 192.168.1.0 using the default subnet mask 255.255.255.0 (a prefix of /24), the network address is 192.168.1.0 and the broadcast address is 192.168.1.255. When you divide this network into subnets, each subnet will get its own network address and broadcast address. For example, if we divide it into two subnets by using a subnet mask of 255.255.255.128, the network address of the first subnet is 192.168.1.0 and the broadcast address is 192.168.1.127. The network address for the second subnet would be 192.168.1.128 and the broadcast address 192.168.1.255.
In a class C network, or any other network with a prefix of 24 or more, it is easy to determine the network address and broadcast address by simply adding up the number of hosts per subnet, butin general writing out the addresses in binary format is the way to go. For example, to determine the network address of the subnet in which the IP address 10.4.220.36 with subnet mask 255.255.248.0 (prefix 21) resides:
Subnet A | 00001010.00000100.11011100.00100100 |
Subnet B | 11111111.11111111.11111000.00000000 |
------------------------ | ----------------------------------------------------- |
Network Address: | 00001010.00000100.11011000.00000000 |
Network Address: | 00001010.00000100.11011000.00000000 |
Broadcast Address: | 00001010.00000100.11011111.11111111 |
The valid host range for a subnet consists of all addresses between the network address and the broadcast address.
VLSM
VLSM stands for Variable Length Subnet Masking and allows you to use the available address space more efficiently. For example, if you divide a class C network into two subnets, you can still divide one of the two subnets into additional subnets. An example network using VLSM is depicted below:
In this example network, a Class C network is divided into variable length subnets. Subnet A uses a prefix of /25, which basically divides the network into two subnets (a class C uses 24 bits for the network portion by default, so 1 additional bit is used for subnets, which allows for 2 different subnets).
Subnet A: 192.168.0.0/25 ranges from 192.168.0.0 – 192.168.0.127, allowing for 126 hosts in total (after subtracting the network address and broadcast address for the subnet). Without VLSM that would automatically leave us with 192.168.0.128 – 192.168.0.255 for the second subnet. However, by assigning a higher prefix/mask to the second subnet we can divide it further into smaller subnets.
Subnet B: 192.168.0.128/26 ranges from 192.168.0.128 – 192.168.0.191, allowing for 64 addresses, minus two for the network (192.168.0.128 ) and broadcast address (192.168.0.191) leaves 62 valid host addresses.
That still gives us 192.168.0.192 – 192.168.0.255, which could be used for another subnet with 62 hosts, but can also be divided into smaller subnets yet again:
Subnet C: 192.168.0.192/27 ranges from 192.168.0.192 – 192.168.0.223, allowing for 30 hosts. To summarize, we end up with the following subnets:
Subnet | Network Address | Hosts |
Subnet A | 192.168.0.0/25 | 126 |
Subnet B | 192.168.0.128/26 | 62 |
Subnet C | 192.168.0.192/27 | 30 |
Unassigned | 192.168.0.224/27 | 30 |
Supernetting
Supernetting is more or less the opposite of subnetting but instead of dividing networks into subnets, networks can be combined in to a larger supernet. In practice this comes down simply to using a smaller prefix/mask than the default for a particular class. For example, a class C network with a prefix of /23 (mask: 255.255.254.0) would allow for twice as many hosts as a regular “classful” class C network using the default mask of 255.255.255.0. The supernet 192.168.0.0/23 for example ranges from 192.168.0.0 - 192.168.1.255 (the first being the network address, the last being the broadcast address and everything in between, 510 addresses, for hosts).