Wednesday, June 07, 2006

Subnets and Subnetting

Subnetting is the process of altering the length of a subnet mask in order to accomodate more networks within an address space.
A subnet mask defines the number of network bits that are relevant for an address. For example the standard class C private network address 192.168.1.0 has a subnet mask of 255.255.255.0. Note that 192.168.1.0 is a network adress, not a host address, as the binary host part of the address is all 0's . If we convert the subnet mask and network address into binary we get:
Network Address: 11000000 10110000 00000001 00000000
Subnet mask: 11111111 11111111 11111111 00000000

The subnet mask is 24 bits (commonly denoted /24). This tells us that the first 24 bits of the network address represents the network part of the address, and the remaining 8 bits represents the host part of the address.
To calculate the maximum number of hosts this network can accomodate, simply fill the binary host part of the address with '1's. Thus,
Highest ip possible: 11000000 10110000 00000001 11111111
: 192.168.1.255
However, this is not quite right as we cannot have an all 1's host part as this is reserved for the broadcast address for the network (if we sent a data packet addressed to 192.168.1.255, all the hosts on the subnet would receive it).
Therefore the highest ip address on the 192.168.1.0/24 network is:
11000000 10110000 00000001 11111110
192.168.1.254.

Also we now know that the 192.168.1.0/24 network can accomodate 254 hosts. This can be calculated more quickly using the formula:

(2n-2) where the 'n' represents the number of bits in the host part of the address. So we would calculate:

(28-2) which equals 254 (remember there are 24 network bits and 8 host bits in the example).



Why is this important?
Computers can only communicate directly with each other if they are on the same network (the same subnet). So if HostA had IP address 192.168.1.1/24 and HostB had an IP address of 192.168.1.2, they could communicate directly without the need of a router.
However if the network part of an IP address is different for two hosts, they can only communicate using a router sat between them.
For example, if HostA has an IP address of 192.168.1.1/24 and HostB has an IP address of 192.168.2.1/24, they cannot communicate without the use of a router. Note we are still using the subnet mask of 255.255.255.0 here.

Lets make some subnets
Lets start with the reserved private address space 10.0.0.0. This is a class A address space with a default subnet mask of 255.0.0.0 - only 8 bits represent the the network part of the address and 24 bits reresent the host part of the address. Thus the maximum number of hosts on this network is:

(224-2) which equals 16777214. That is a lot of hosts.

Lets imagine that we have a company with 700 offices all over the country. Each office is going to need its own subnet within the 10.0.0.0/8 private address space.

In order to subnet the 10.0.0.0 address space we need to extend the subnet mask (borrow bits from the host part).

We increase the length of the subnet mask by 9 bits to /17 (8+9). This gives us a maximum of

(29-2) -10 = 502 possible subnets, which is not enough. So we increase the subnet mask by 10 bits [mask=/18] :

(210-2) -10 = 1022 possible subnets, which is enough!

Using a Subnet Mask of /18 leaves 14 bits for the host part of the address, so each subnet can accomodate (214-2) = 16382 Hosts.

The binary representation of an 18 bit subnet mask is:

11111111 11111111 11000000 00000000

Subnet mask = 255.255.192.0

What will be the network address of the first subnet?

00001010 00000000 00:000000 00000000
[The colon represents the end of the network part of the address]

10.0.0.0

Why do we keep the 10 at the front? Well we are working here with the 10.0.0.0/8 private address space which is one of the three standard reserved address spaces for internal use (not visible to the Internet - Internet routers ignore these addresses).

What will be the network address of the second subnet?

00001010 00000000 01:000000 00000000
[The colon represents the end of the network part of the address]

10.0.64.0

What will be the network address of the third subnet?

00001010 10000000 10:000000 00000000
[The colon represents the end of the network part of the address]

10.0.128.0



No comments: