Tuesday, January 7, 2014

Subnetting

IP addresses consist of two parts: the network ID, and the device (or host) ID. Think of the network ID as the postal zip code, and the device ID as the street address. The network ID identifies the network the device is located on, and then the device or host ID identifies the device on that network.

Subnetting Basics

Remember that an IP address is divided into the network portion, and device (or host) portion. For example, a class B address of 130.16.27.4 has a network address of 130.16 and a device address of 27.4. The subnet mask indicates which portion is the network address and which portion is the host address. In this case, 255.255.0.0, which indicates the first two octets are the network address.

For more flexibility, and to avoid wasting IP addresses, you can "steal" bits from the device portion of the address and make them part of the network address. If you only have 200 or so devices on a network, you could take that class B address above and make the third octet part of the network address. This is called a subnet. The mask becomes 255.255.255.0, and only the last octet is used for device addresses. So the network ID from the above example would now be 130.16.27.0, and the device addresses would be 130.16.27.1, 130.16.27.2, and so on, all the way up to 130.16.27.255, which would be the broadcast address. 

The tricky part comes when you only want to steal a few bits from the host portion of the address. What happens when you steal three bits from the host portion? The binary version of the subnet mask would be 11111111.11111111.11100000.00000000, but what is the mask written in decimal? And what is the range of addresses for each subnetwork?

The best way to do subnetting is to simply memorize a few tables. Commit this list to memory:

128, 192, 224, 240, 248, 252, 254, 255

For each bit in the subnet, you will now know what the subnet mask is. In the above example, we stole three bits from the host portion of the address, so simply count three numbers in on the list you've memorized, which would be 224. So the decimal version of the above address is 255.255.224.0.

But now you need to know the start and ending address of each network within the subnet, and the usable device addresses. Here is the second list you need to commit to memory:

128, 64, 32, 16, 8, 4, 2, 1

Sticking with the example above, you again count three numbers in for the three bits we stole from the host portion, which would be 32. So you know each subnet increments by 32. So the first subnetwork address range would be 130.16.0.0 up to 130.16.31.0, and the next subnetwork would be 130.16.32.0 to 130.16.63.0. Note that in that third octet, (mask 255.255.224.0) we are incrementing by 32.

So the first usable device address in that first subnetwork would be 130.16.0.1, the next would be 130.16.0.2, and so on up to 130.16.0.255, followed by 130.16.1.0, 130.16.1.1, and so on. Until we hit the number right before the next subnetwork (130.16.31.255). If we add one more to this, it will be in the next subnetwork (130.16.32.0), so we know that we now have the broadcast address of this network. Subtract one from this broadcast address, and you have the last usable device address: 130.16.31.254. 

REMEMBER THIS: The first address in the range of each subnetwork is the network address, and the last is the subnetwork's broadcast address.

To recap, the first subnetwork range of addresses would be:

130.16.0.0 network address
130.16.0.1 first usable device address
130.16.31.254 last usable device address
130.16.31.255 network broadcast address

And our next network would be the next 32 block:

130.16.32.0 network address
130.16.32.1 first usable device address
130.16.63.254 last usable device address
130.16.63.255 network broadcast address

And so on in blocks of 32.

Now let's say that we stole 5 bits from the host portion of the address. So the subnet mask is now 11111111.11111111.11111000.00000000. What is the subnet mask in decimal? You memorized the numbers I told you to memorize above, so you simply count 5 in:

128,192,224,240,248,252,254,255

…which would be 248. So the subnet mask is 255.255.248.0. Now what is the network increment size? Again count five in:

128,64,32,16,8,4,2,1

The increment is 8. So in the third octet, the network will increment by 8. So the address range is:

130.16.0.0 network address
130.16.0.1 first usable host address
130.16.7.254 last usable host address
130.16.7.255 network broadcast address

130.16.8.0 network address
130.16.8.1 first usable host
130.16.15.254 last usable host
130.16.15.255 last usable host

And so on until we hit 255 in the third octet. 

CIDR Notation

A different way to represent the subnet mask is to list the number of bits used in the mask. So the last example above uses the first two octets (16), plus five more bits from the host portion, for a total of 21. So the addresses above could be written like this: 130.16.0.0/21.

Practice, Practice, Practice!

You need to be able to do subnetting quickly, in your head. Let's say you see the following address: 196.43.16.18/29. You may need to know what subnetwork this address is a part of. Note the CIDR notation of 29 bits. Note that the address is a class C address (between 192 and 223). So you know that the normal mask for a class C address is 255.255.255.0, or /24. Since this address uses 29 bits for the mask, that is 5 bits past the normal mask for a class C address. Count five in from the list you memorized:

128,192,224,240,248,252,254,255

So you now know that the subnet mask is 255.255.255.248.

Now count five in from the other list of numbers you memorized:

128,64,32,16,8,4,2,1

So you know the network increment size is 8. For example, the first network would be 196.43.16.0, the next would be 196.43.16.8, then 196.43.16.16, followed by 196.43.16.24 and so on, with the host addresses in between. So the IP address of 196.43.16.18 falls between 196.43.16.16 and 196.43.16.24, so it belongs to the 196.43.16.16 network.

Now, what is the first usable host from this network? One more than the network address. The network address is 196.43.16.16, so the first usable host address would be 196.43.16.17.

And what is the broadcast address for this network? One less than the next network address. The next network addres is 196.43.16.24, so the broadcast address is 196.43.16.23.

So we started with this: 196.43.16.18/29

And got this:

196.43.16.16 network address
196.43.16.17 first usable host address
196.43.16.23 broadcast address

You need to be able to do this backwards as well. Let's say you have 20.27.42.11, with a subnet mask of 255.240.0.0. What is the CIDR notation for this? As long as you keep that table in mind, you should not have any problems:

128,192,224,240,248,252,254,255

That mask is four numbers in, so the CIDR would be four numbers more than the normal mask address for that class, which would be 8, so the CIDR would be four more than that: /12. Since you know you are four past the normal mask, you can then get the network increment:

128,64,32,16,8,4,2,1

And you will know that 20.27.42.11 belongs to the 20.16.0.0 network, with a broadcast address of 20.31.255.255, which is one less than the next network of 20.32.0.0.

This needs to be second nature, so use subnettingquestions.com for an endless supply of randomly-generated practice questions.

No comments:

Post a Comment