Many networks are divided into smaller networks called subnets.
|
With subnets, utilization of addressing space is more efficient.
|
In large organizations, subnets are used to divide one large network into a number of smaller subnetworks.
|
Here, the network 172.16.0.0 is subdivided, or broken up, into four subnets:

• 172.16.1.0
|
• 172.16.2.0
|
• 172.16.3.0
|
• 172.16.4.0
|
If your network is attached to the Internet, the NIC will assign you a unique network address.
|
This address represents the network as a whole, even if it has been divided into subnets.
|
The subnets must share the same network address, so additional information is required to distinguish between them.
|
Subnet addresses are extensions of the network number.
|
Subnetting involves reassigning part of the node component of an IP address to act as an additional network address.
|
Subnet masking is a technique used to adapt Internet IP addresses to subnets.
|
Network devices, such as routers, use subnet masks to identify which part of the address refers to a network and which refers to the destination host.
|
Routing decisions are then based on network and subnet numbers.
|
The process of assigning addresses in a network that has been subnetted has three steps:

• defining a subnet mask
|
• assigning an address to each
  subnet
|
• assigning IP addresses to
  each node in each subnet
@@
A subnet mask is a 32-bit number that is applied to an IP address to override the default network/node address division.
|
Subnet masks indicate which of the bits in the host field are used to specify the subnets in a particular network.
|
In the subnet mask you assign a value of 1 to each bit that corresponds to a part of the IP address that refers to the network rather than the node.
|
The 32-bit subnet mask can be written as four octets.
|
The layout of the mask field is as follows:

• binary 1 for the network bits
|
• binary 1 for the subnet bits
|
• binary 0 for the host bits
|
Class A, B, and C addresses all have default subnet masks that reflect their default network/node address divisions.
|
These default masks have a 1 in every position that corresponds to the default network address component of the appropriate IP address class.
|
The subnet bits come from the high order bits of the host field.
|
In a class A address, the first octet alone constitutes the network address.
|
This is equivalent to a subnet mask of 255.0.0.0 decimal.
|
Similarly, the default mask for a class B address is 255.255.0.0 decimal, and the default mask for a class C network is 255.255.255.0 decimal.
|
The default subnet mask for each class of network treats its corresponding IP address as if there were no subnets.
|
If you want to subnet your network, you will need to alter your subnet mask.
|
Specifically, you will need to alter some of the 0s in the mask to 1s.
|
This will mean that part of the node component of each IP address will be treated as additional network addressing information.
@@
Let's consider an example of subnet masking.
|
Argo Corporation, a hypothetical company, has been assigned a single class B network address (172.16.0.0) by the NIC.
|
However, Argo wishes to divide its network into separate subnets.
|
To do this, Argo will need to modify the default class B subnet mask 255.255.0.0.
|
The simplest approach that Argo can take is to define the entire third octet of its address as a network address for the subnets.
|
Class C networks cannot be subnetted in this way because they have only one octet devoted to the node address.

However, you can subnet class C networks by using only part of the final octet as the subnet address.
|
Doing this changes the third octet of the subnet mask to 11111111.
|
Argo's subnet mask is therefore set to 255.255.255.0 decimal.
|
Notice that this is the same as the default subnet mask for a class C network.
|
When the new subnet mask is put in place, IP addresses for nodes within Argo's network will have three components.
|
The first two octets remain as the standard class B Internet network address.
|
The third octet will become a subnet address within Argo's network.
|
The last octet functions as a node address within each subnet.
|
From the point of view of external routers, Argo's network appears to be a single class B network.
|
However, Argo's own routers perceive the subnets to be effectively individual class C networks.
|
When data is sent to the Argo network, the router extracts the IP destination address from a packet and retrieves the internal subnet mask.
|
It then performs a logical AND operation to obtain the network number.
|
During the AND operation, the host portion of the destination address is removed.
|
This is because any bit ANDED with 0 will return a 0.
|
If no subnet is present, the network number extracted is 172.16.0.0.
|
If there is a subnet, both it and the network number is extracted - in this illustration 172.16.2.0.
|
So routing decisions are based on network and subnet numbers only.
|
The rules for subnet addressing are defined by the Internet Protocol specification RFC 791 and subnetting specification RFC 950.
|
Under these rules, subnet addresses that consist entirely of either 1s or 0s are reserved for identifying the local network and broadcast purposes.
|
Using the entire third octet to identify subnets allows for up to 254 (two to the power of eight, minus two) possible subnets.
@@
Let's consider the case of a class C network.
|
The default mask for a class C network is 255.255.255.0 decimal.
|
Setting the last octet of the subnet mask to 11111111 will result in a mask of 255.255.255.255.
|
This would allow 254 possible subnets, but it is not permitted because no node addressing information remains.
|
Using seven masked bits (11111110 in the last octet, 254 decimal) is pointless, because the single remaining node address bit must have a value of either 0 or 1.
|
Node addresses consisting entirely of 1s or 0s are reserved and cannot be allocated to hosts.
|
So although the mask 255.255.255.254 supports 126 legal subnets, it leaves no address space for hosts.
|
Similarly, using only one bit for the mask is also pointless as it results in no subnets.
|
This is because there are only two possible values for the subnet address - 0 and 1.
|
It is important to note that a 1-bit mask (1000000) is not equivalent to the 0-bit default mask (00000000), even though both result in no subnets.
|
This is because the 1-bit mask has only seven bits available for node addressing and so can support only 126 hosts.
|
The default mask, on the other hand, uses all eight bits for node addressing and so can support 254 hosts.
|
The table shows the relationship between the number of subnets and supported hosts for all possible masks in a class C network.
|
As you can see, the restrictions on the number of supported hosts constrains your ability to subnet class C networks.
@@
There is a trade-off between the number of available subnet addresses and the number of hosts that can be supported on each subnet.
|
When setting up an internetwork, you determine the number of subnets and hosts per subnet you need to support.
|
The number of possible subnets depends on the number of bits allocated to the subnet address.
|
This is equivalent to the number of 1s in the subnet mask minus the number of 1s in the default mask for the particular class of network.
|
The exact number of subnets is given by two to the power of the number of bits allocated to the subnet address, minus two (the unassignable addresses made up of all 0s or all 1s).
|
The number of hosts per subnet is obtained from the number of unmasked bits (0s) in the subnet mask.
|
It is given exactly by two to the power of the number of unmasked bits, minus two (the unassignable addresses made up of all 0s or all 1s).
|
Consider this subnet mask.
|
The number of subnets it can support depends on whether the network has a class A or class B address.
|
If the network has a class A address then the subnet address occupies eleven bits, the whole of the second octet and three bits in the third.
|
There are therefore two to the power of eleven, minus two, possible subnets.
|
This works out as 2046.
|
If class B addresses are used then the subnet address occupies just three bits in the third octet.
|
There are, therefore, two to the power of three, minus two, possible subnets.
|
This works out as six.
|
Regardless of whether class A or class B addresses are used, the last thirteen bits are devoted to the node addresses.
|
There are therefore two to the power of thirteen, minus two, possible hosts per subnet.
|
This works out as 8190.
@@
Here, the NIC (or the RIPE in Europe) has assigned you a class C address 192.168.5.0.
|
You need 20 subnets with 5 hosts per subnet.
|
So you need to select a subnet field size that yields enough subnets.
|
Choosing a 5-bit mask gives you 30 subnets, and allows for the 20 subnets you need.
|
The subnet addresses are all multiples of 8, such as 192.168.5.16, 192.168.5.32, 192.168.5.48.
|
Acceptable values for subnet addresses depend on the number of bits set aside for the subnet address.
|
Subnet addresses of all ones (111111) or zeros (000000) are not permitted by the IP standard.
|
You use the remaining bits in the last octet for the host field.
|
Three bits are used in the example for the host address.
|
Allocating three unmasked (0s) bits for the host address field allows you six hosts per subnet.
|
This is enough hosts to cover the required five hosts per subnet.
|
The example shown means that the first subnet starts at 192.168.5.8, this address is known as the subnet identifier and cannot be used as a node address.
|
The addresses 192.168.5.9 through to 192.168.5.14 (note there are six as predicted) can be used as node addresses.
|
The address 192.168.5.15 is the subnet broadcast address which you cannot use either as a node address.
|
The next subnet starts at 192.168.5.16, this is its subnet identifier and it has node addresses from 192.168.5.17 to 192.168.5.22.
|
The subnet broadcast address is 192.168.5.23.
|
The network and subnet addresses must be the same for all hosts on the same subnet.
|
However, all IP addresses must be unique, so you cannot allocate the same host address to two hosts on the same subnet.
|
As with subnets, the host portion of an IP address must not be set to all 1s or 0s.
|
Apart from this requirement you may assign any values as host addresses.
|
The final host addresses are a combination of the network and subnet addresses plus each host value.
|
The hosts on subnet 192.168.5.120 would be 192.168.5.121, 192.168.5.122, 192.168.5.123 and so forth.
@@
When you first set up an internetwork, it is difficult to predict how many subnets you may need to support in the future.
|
This makes it hard to decide on a suitable subnet mask.
|
RFC 1219 suggests a strategy for assigning IP addresses that allows changes to the subnet mask without reassigning existing IP addresses.
|
The strategy has the effect of filling the node address component bits from the right.
|
The first node address assigned in a subnet should be 1 (1 at the rightmost bit).
|
The next node address assigned should be 2 (10 in binary), the next should be 3 (11 in binary), the next 4 (100), and so on.
|
The subnet value bits should be filled from the left - that is, in exactly the opposite direction to the node address bits.
|
For example one bit corresponds to 128, two bits to 192, three bits to 224, and four bits to 240.
|
The point of the RFC 1219 addressing strategy is that the bits nearest the division between the subnet and node are the last to be allocated.
|
At any stage you can reassign one or more of these bits between node and subnet by varying the subnet mask.
