IP Subnetting

At this point you should know that IP, the Internet Protocol, is a network layer (OSI layer 3) protocol, used to route packets between hosts on different networks. To suit this purpose, IP must define an addressing scheme, so that a packet's intended destination can be indicated.

An IP address is composed of 32 bits. These 32 bits are divided into 4 octets of 8 bits each. You may have seen an IP address represented like this: 172.68.15.24. We must remember, however, that the computer understands this number only in binary, so we must often deal with them in binary. Many people are intimidated by this initially, but soon find that it is not difficult. If you do not allow yourself to be flustered, you can master this topic.

IP addresses are assigned to organizations in blocks. Each block belongs to one of three classes: class A, class B, or class C. You can tell what class an IP address is by the value in its first octet.

Class A

1-126

Class B

128-191

Class C

192 -->

Note:127 is not a valid network. It is used as a computers internal network address.

An IP address consists of two fields. The first field identifies the network, and the second field identifies the node on the network. Which bits of the address are in the network field and which bits are in the host field is determined by the subnet mask.

When a class A IP license is granted, you are assigned something like this: 99.0.0.0. Only the value of the bits in the first octet are assigned. This means you are free to assign any values you wish in the second, third and fourth octets.

The default subnet mask for a class A network is 255.0.0.0. High bits, ones, indicate the bits that are part of the network field of the IP address. The default subnet mask does not create subnets. Therefor, a class A network with the default subnet mask is one network. The three octets that are unassigned and unmasked are part of the host field of the address. There is a total of 24 bits in those three octets. Each bit can be in one of two states. Therefor, 2^24 is the number of host addresses that can be assigned on that network, almost. Two addresses are reserved on every network, x.x.x.0 and x.x.x.255. So the total number of hosts possible on this network is 2^24. 2^24-2=16,777,214 hosts for a class A IP network.

When a class B license is granted, the first two octets are assigned. For example, 172.198.x.x. The default subnet mask for a class B is 255.255.0.0. One network, two octets free, 16 bits for the host address field. 2^16-2=65,534 possible host addresses on a class B IP network.

When a class C license is granted, the first three octets are assigned, for example: 193.52.16.0. The default subnet mask for a class C is 255.255.255.0. Once octet makes up the host address field. 2^8-2=254 host addresses possible on a class C network.

2. Reason for Subnetting

We said that the default subnet mask for a class A IP network is 255.0.0.0. Once octet only of a class A network address identifies the network, with this subnet mask. This leaves three octets of 8 bits each, or 24 bits, to identify the host on that one network. 2^24=16,777,216 addresses. Two addresses are reserved, x.x.x.0 and x.x.x.255. 16,777,214 nodes can be assigned an IP address on this network.

It is highly unlikely that any organization would want one network of 16,777,214 nodes. They might want that many devices connected in a wide area network (WAN), thus capable of communicating when necessary, but they will want to subdivide this huge network into mostly self-contained subnetworks of nodes that communicate with each other often. This is called subnetting.

To understand why, consider what would happen in either a broadcast or a token passing network that consisted of over 16,000,000 nodes. Nothing would happen. It simply would not work. Though the problem is not as drastic, class B and class C IP networks are often subnetted, also.

The subnet mask is used to subdivide an IP network into subnets. This is a division that takes place in OSI layer 3, so it is a logical division that is created by the addressing scheme. This logical division is usually combined with a physical division. Many subnets are physically isolated from the rest of the network by a device such as a router or a switch. This aspect of subnetting is discussed in Unit 3--Data Link Layer.

3. How Subnetting Works

The bits of an address that are masked by the subnet mask are the bits that make up the network field of the address. To subnet, the default subnet mask for a network is extended to cover bits of the address that would otherwise be part of the host field. Once these bits are masked, they become part of the network field, and are used to identify subnets of the larger network.

Here is where we begin dealing with both addresses and subnetmasks in binary. Get yourself a cold beverage, stretch, take a deep breath and don't worry. Once you get your brain around the concepts, it is not difficult. You just have to keep trying until the light goes on.

3.1 Translating Binary to Decimal

Both IP addresses and subnet masks are composed of 32 bits divided into 4 octets of 8 bits each. Here is how a single octet translates from binary to decimal. Consider an octet of all ones: 11111111.

128   64   32   16   8   4   2   1

---   --   --   --   -   -   -   -

 1     1    1    1   1   1   1   1

128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255

Here's another: 10111001

128   64   32   16   8   4   2   1

---   --   --   --   -   -   -   -

 1     0    1    1   1   0   0   1

128 +  0 + 32  +16 + 8 + 0 + 0 + 1 = 185

and 00000000

128   64   32   16   8   4   2   1

---   --   --   --   -   -   -   -

 0     0    0    0   0   0   0   0

 0  +  0 +  0 +  0 + 0 + 0 + 0 + 0 = 0

3.2 Converting Decimal to Binary

Converting decimal to binary is similar. Consider 175:

128   64   32   16   8   4   2   1

---   --   --   --   -   -   -   -

 1     0    1    0   1   1   1   1

128 +  0 + 32 +  0 + 8 + 4 + 2 + 1 = 175

175=10101111

3.3 Simple Subnetting

The simplest way to subnet is to take the octet in the subnet mask that covers the first unassigned octet in the IP address block, and make all its bits high. Remember, a high bit, a 1, in the subnet mask indicates that that corresponding bit in the IP address is part of the network field. So, if you have a class B network 172.160.0.0, with the subnet mask 255.255.0.0, you have one network with 65, 534 possible addresses. If you take that  subnet mask and make all the bits in the third octet high

128   64   32   16   8   4   2   1

---   --   --   --   -   -   -   -

 1     1    1    1   1   1   1   1

128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255

you get the subnet mask 255.255.255.0.

172.60.  0. 0

255.255.255.0

Now the third octet of all the addresses on this network are part of the network field instead of the host field. That is one octet, or eight bits, that can be manipulated to create subnets. 2^8-2=254 possible subnets now on this class B network.

One octet is left for the host field. 2^8-2=254 possible host addressed on each subnet.

3.4 Advanced Subnetting

That is the simplest way to subnet, but it may not be the most desirable. You might not want 254 subnets on your class B network. Instead, you might use a subnet mask like 255.255.224.0. How many subnets would this give you? The first step is to see how many bits are allocated to the network by this mask.

128   64   32   16   8   4   2   1

---   --   --   --   -   -   -   -

 1     1    1    0   0   0   0   0

128 + 64 + 32 +  0 + 0 + 0 + 0 + 0 = 224

3 bits are allocated. 2^3-2=6 subnets.

Note: Cisco does not allow the low and the high IP address to be used for subnets, that  is why we have 23 -2 in the example above.  Since they control 90% of the hardware we follow their rules, most of the time. When finding the available IP addresses for devices we never use the low or high IP addresses.

Note: Following the rule above, we can not subnet with 128. Why you may ask.

Example:

                 255.255.128.0

                 255.255.10000000.00000000

You have one bit in the mask, which gives you 21-2=0  So with this mask you could have 215-2 devices on ZERO networks. Just not going to work.

How many hosts on each subnet? Well, 5 bits from this octet are left for the host field, and 8 bits in the fourth octet, for a total of 13 bits in the host field. 213-2=8190 possible hosts on each subnet.

The subnet mask is always extended by masking off the next bit in the address, from left to right. Thus, the last octet in the subnet mask will always be one of these: 128, 192, 224, 240, 248, 252, 254 or 255.

Given the IP address of a host and the subnet address for the network, you need to be able to calculate which subnet that host is on. To do this we compare the binary representation of the pertinent octet of the subnet mask with the binary representation of the corresponding octet in the IP address.

Example:

IP address=172.60.50.2

subnet mask=255.255.224.0

50= 00110010

224=11100000

We perform a logical on these two numbers. We will be left with only the bits where there is a one in both octets.

00110010

11100000

--------

00100000=32

This host is on subnet 172.60.32.0.

We also need to be able to find the range of assignable IP addresses on this subnet. To do this, we take the binary that tells us the subnet address, in this case 00100000, and compare it with the subnet mask.

00100000

11100000

The bits covered by the mask we will leave as they are. The rest of the bits we make high. 

00100000

11100000

--------

00111111=63

The range of assignable IP addresses on the subnet 172.60.32.0 is 172.60.32.1-172.60.63.254.

On every network and subnet, two addresses are reserved. At the low end of the range of addresses for the network or subnet, in this case 172.60.64.0, is the address for the network or subnet itself. The address at the high end of the range of addresses, in this case 172.60.95.255, is the broadcast address. Any message sent to the broadcast address will be received by every host on the network.

4. Sample Problem

Here is a sample problem for you to calculate. When you are done, you can check your answers using an online subnet calculator at Tactix Engineering .

IP address:  154.16.52.16

subnet mask:  255.255.240.0

First thing we notice is this is a class B network and we are subnetting with the 240. So we know that all of our addresses will at least start with 154.16.

Find:

Number of subnets possible on this networks:24--2=14

Number of hosts possible on each subnet:212-2=4094

Which subnet this address is on:154.16.48.0

Range of addresses on that subnet:154.16.48.1 -- 154.16.63.254

Tip: To find what subnet this IP address is on perform logical on these numbers. Where there is 1's in the mask and address pull those 1's down, then add up the number.

00110100        =52

11110000        =240

-----------------------------

00110000        =48

This IP address is on 154.16.48.0 Subnet

For the range of IP addresses for this subnet leave the ones you pulled down the same and change all the zero to the right in this octet into ones.

00110000

-------------

00111111       =63

This gives us a range of IP's 154.16.48.1  -- 154.16.63.254 for this subnet. Remember we can not use the low or high. 0 or 255 these are reserved for Network and Broadcast.

Now for the tricky part. How many subnets can we have? With four bits high in the subnet (1's) 240 = 11110000 that gives us 24=16 possible subnets. To find what subnet number is associated with those 14 subnets we need to look at the 1's and Zero combos for 24

0000    -0   Cisco says we cannot use this one.

0001    -1

0010    -2

0011    -3

0100    -4

0101    -5

0110    -6

0111    -7

1000    -8

1001    -9

1010    -10

1011    -11

1100    -12

1101        -13

1110    -14

1111    -15  Cisco says we cannot use this one.

--------------

Total =14 Useable Subnets

Our subnet mask is 255.255.240.0 and 240 is 11110000 in binary.

Now these four bits are associated with the left most bits in the third octet in the subnet mask and there values are

  1       1       1     1   0   0   0   0

128 - 64  - 32 - 16.

Keep that in mind and add the 1's and you will know the value for all the available subnets.

0000    -0                   154.16.0.0

0001    -16                   154.16.16.0

0010    -32                   154.16.32.0

0011    -48                   154.16.48.0

0100    -64                   154.16.64.0

0101    -80                   154.16.80.0

0110    -96                   154.16.96.0

0111    -112                 154.16.112.0

1000    -128                 154.16.128.0

1001    -144                 154.16.144.0

1010    -160                 154.16.160.0

1011    -176                 154.16.176.0

1100        -192                 154.16.192.0

1101    -208                 154.16.208.0

1110     224                 154.16.224.0              

1111    -240               154.16.240.0

Results from IP Subnet Calculator Tactix Engineering.

IP Subnetter

IP ADDRESS

CLASS

DEFAULT SUBNET MASK

154.16.52.16

B

ffff0000

11111111 11111111 00000000 00000000

Applying Subnet Mask: 255.255.240.0 0xfffff000 11111111 11111111 11110000 00000000

Network Address

154.16.0.0 0x9a100000 10011010 00010000 00000000 00000000

Increment

4096

Bits Used For Network

4

Possible Subnets

16

Bits Used For Hosts

12

Hosts Per Subnet

4094

Subnet

Network

First Host

Last Host

Broadcast

1

154.16.0.0

154.16.0.1

154.16.15.254

154.16.15.255

2

154.16.16.0

154.16.16.1

154.16.31.254

154.16.31.255

3

154.16.32.0

154.16.32.1

154.16.47.254

154.16.47.255

4

154.16.48.0

154.16.48.1

154.16.63.254

154.16.63.255

5

154.16.64.0

154.16.64.1

154.16.79.254

154.16.79.255

6

154.16.80.0

154.16.80.1

154.16.95.254

154.16.95.255

7

154.16.96.0

154.16.96.1

154.16.111.254

154.16.111.255

8

154.16.112.0

154.16.112.1

154.16.127.254

154.16.127.255

9

154.16.128.0

154.16.128.1

154.16.143.254

154.16.143.255

10

154.16.144.0

154.16.144.1

154.16.159.254

154.16.159.255

11

154.16.160.0

154.16.160.1

154.16.175.254

154.16.175.255

12

154.16.176.0

154.16.176.1

154.16.191.254

154.16.191.255

13

154.16.192.0

154.16.192.1

154.16.207.254

154.16.207.255

14

154.16.208.0

154.16.208.1

154.16.223.254

154.16.223.255

15

154.16.224.0

154.16.224.1

154.16.239.254

154.16.239.255

16

154.16.240.0

154.16.240.1

154.16.255.254

154.16.255.255


Authored by Josh Gentry for CP 282 Network Topologies at TVI, in Albuquerque, NM.