IPv4 Subnetting Guide.

rob42rob42 Member Posts: 423
In this guide, I'll try to address some of the FAQs of IPv4 Subnetting.

First. You can find a very good guide to Subnetting in the TechNotes section of this site URL="http://www.techexams.net/technotesnew/158-ipv4-subnetting-guide.html"]IPv4 Subnetting TechNotes[/URL, which you should read, but we still get many questions on the subject which means that either people are not looking for it (or are simply unaware of it) or it lacks the details that people need.

I hope that this guide will address whatever the issue is, in two ways...

• By providing some details
• By becoming a 'Sticky Thread'

It's important to understand the relationship between IP Addresses and the underlying Binary Code. IP Addresses are written in two ways; both are with Decimal Digits...

• DDN (Dotted Decimal Notation).
• CIDR (Classless Inter-Domain Routing) Notation.

CIDR is now the most common way in which IP Addresses are written and includes a representation of the Subnet Mask, by way of a '/' followed by a number at the end of the IP Address. With DDN, it is necessary to include the Subnet Mask in full.

DDN: 192.168.0.10 255.255.255.0
CIDR: 192.168.0.10 /24

Both of the above IP Addresses are the same, both use 24 'Bits' to Address the Network. When you start working with Cisco Switches and Routers, you'll find that IP Addresses are assigned via a Command Line, in DDN.

With IPv4, the IP Address is a string of 32 'Bits'. So that the IP Protocol knows which 'Bits' are used to Address the Network and which 'Bits' are used to Address a Host on a Network, the concept of a Mask is used. This is to mask-off one part from the other.

A Mask is a very simple 'logical operation'; it uses 'AND' logic to separate the Network Address from the Host Address. To understand how this works, we need to see the underlying Binary Code.

As we've seen, IPv4 Addresses are split-up into four parts, separated by dots. These four regions are referred to as 'Octets', because they represent eight 'Bits'...

IP Address.. 1 1 0 0 0 0 0 0 | 1 0 1 0 1 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 1 0 1 0 = 192.168.0.10
Mask........ 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 0 0 0 0 0 0 0 0 = 255.255.255.0
'AND'....... 1 1 0 0 0 0 0 0 | 1 0 1 0 1 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 = 192.168.0.0


You should be able see that the Output from the Mask (the ‘AND’) tells us what the Network IP Address is (also called the 'Network ID'). The Mask has done this by ‘Masking’ the Host portion of the IP Address using ‘zeros’. It just so happens that the Host portion in this example is one full ‘Octet’, or eight ‘Bits’, and the Network portion is three full ‘Octets’, or 24 ‘Bits’, but it doesn’t have to be this way. We can ‘set’ or ‘unset’ the Mask Bits (in a consecutive way) so more or less of the IP Address is Masked, thus more or less Bits are used to Address the Network / Hosts.

To understand exactly how many Networks and Hosts can be addressed, requires a little basic math.

First, the Hosts: Each ‘Bit’ can only have two states: either ‘zero’ or ‘one’, and we have eight of them when using a 24 Bit Mask (32 Bits Total, less the 24 Bits used for the Network ID, leaves 8 Bits for the Hosts). Two-to-the-power-of-eight (written 2 ^ icon_cool.gif = 256.

This would be the number of addressable hosts, but for two things…
1. We need to Address the Network.
2. We need to be able to Address all the hosts at once; this is called a ‘Broadcast’.

So, we can’t use 0 0 0 0 0 0 0 0 or 1 1 1 1 1 1 1 1, which leaves 0 0 0 0 0 0 0 1 to 1 1 1 1 1 1 1 0 (or .1 to .254) for the Host IDs on the 192.168.0.0 Network. So, the number of addressable hosts is (2 ^ icon_cool.gif - 2 = 254.

It could be that we don’t need to be able to Address that many Hosts, and it would be better if we could introduce some separation between the Hosts, either for security reasons or performance reasons, or both, but we only have that one IP Address Block to work with: enter Subnetting.

Remember, I said that the Host portion of the IP is Masked using Zeros. If we Mask an additional Bit, we can split the Network into two parts. To see how this can be, again requires a little basic math.

Networks = 2 ^ {the number of 'extra' bit used to map the Network}. To start with, that's zero. Any number to the power of zero = 1.

The next bit is easier if we add the 2 host addresses back on to make 256.

Subnets have to go up in powers of two, while at the same time, we half the number of Hosts...

2 ^ 0 = 1 | 256: The starting point.
2 ^ 1 = 2 | 256 / 2 = 128: Two Networks, with (128 - 2) 126 Hosts on each Network.

If we re-map the Binary...

IP Address.. 1 1 0 0 0 0 0 0 | 1 0 1 0 1 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 1 0 1 0 = 192.168.0.10
Mask........ 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 0 0 0 0 0 0 0 = 255.255.255.128
'AND'....... 1 1 0 0 0 0 0 0 | 1 0 1 0 1 0 0 0 | 0 0 0 0 0 0 0 0 | 0 0 0 0 0 0 0 0 = 192.168.0.0


Now we have only seven Bits for the Host Addresses (2 ^ 7 = 12icon_cool.gif, less two, as before, = 126 Host IDs...

We can only use 0 0 0 0 0 0 0 1 to 0 1 1 1 1 1 1 0 (or .1 to .126) for the Host IDs, because we need 0 0 0 0 0 0 0 0 for the Network ID and 0 1 1 1 1 1 1 1 (.127) for the Broadcast, for the 192.168.0.0 Network. The CIDR Notation would be 192.168.0.0 /25, because we've now used 25 Bits for the Network portion of the IP Address.

So, if this Network Address block now ends at 192.168.0.127 (the Broadcast), what happens if we have 192.168.0.128 as an IP Address? Let's map it out...

IP Address.. 1 1 0 0 0 0 0 0 | 1 0 1 0 1 0 0 0 | 0 0 0 0 0 0 0 0 | 1 0 0 0 0 0 0 0 = 192.168.0.128
Mask........ 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 1 1 1 1 1 1 1 | 1 0 0 0 0 0 0 0 = 255.255.255.128
'AND'....... 1 1 0 0 0 0 0 0 | 1 0 1 0 1 0 0 0 | 0 0 0 0 0 0 0 0 | 1 0 0 0 0 0 0 0 = 192.168.0.128


The Output from the Mask (the ‘AND’) again tells us what the Network ID is (192.168.0.12icon_cool.gif, and again, if it's all zeros, it's the Network ID (1 0 0 0 0 0 0 0), and if it's all ones, it's the Network Broadcast Address (1 1 1 1 1 1 1 1). So the first Host ID for the Network will be 1 0 0 0 0 0 0 1 (.129) and the Broadcast will be 1 1 1 1 1 1 1 1 (.255).

I could add anther example, using another Bit for the Network, but I’ll leave that to the reader to do, but to continue the math…

2 ^ 0 = 1 | 256: The starting point.
2 ^ 1 = 2 | 256 / 2 = 128: Two Networks, with (128 - 2) 126 Hosts on each Network.
2 ^ 2 = 4 | 128 / 2 = 64: Four Networks, with (64 - 2) 62 Hosts on each Network.

This concludes this part of this guide. If encouraged to do so, I'll be happy to submit another part, which could include the answers to any questions that you may have regarding what I've written here.
No longer an active member
Sign In or Register to comment.