This blog is going to serve as a simple guide to IPv4 addressing. Even though the *RIPE NCC has run out of IP address space to allocate (just two days ago as I write this), IPv4 remains relevant and is something you’ll have to deal with if you’re interconnecting network devices. There are after all a lot of IPv4 addresses allocated with private addresses being used over and over again.
*RIPE (Réseaux IP Européens), NCC (Network Co-ordination Centre).
IP address format
An IPv4 address consists of 32 binary bits so mathematically there is a maximum of 2^32 or 4,294,967,296 addresses. After we take out things like broadcast addresses, private addresses, and special-use addresses like multicasts, we’re left with around 3.7 billion addresses (according to Cisco).
To make IP addresses easier to read, they are split into 4 groups of 8 bits each separated by a dot and converted to decimal format. Now the maximum number of combinations that can be represented by eight binary bits is 256, (including 0) so the maximum decimal number, if all the bits are set to 1 would be 255.
To see the IP address of a Windows machine you can open a command prompt and type in “ipconfig” or “ipconfig /all”. For Linux use “ifconfig” in a terminal window to output something similar.
So an IP address looks like the following “10.250.21.31” when written in human-readable form. In binary (since a binary value can only be a 0 “unset” or a 1 “set”) that would be “00001010.11111010.00010101.00011111”.
Now binary values, as with decimal notation increase in value the further to the left they are. Each position to the left doubles the value of the one next to it. For example, the Least Significant Bit ( the bit furthest to the right, which has the lowest value) can be either unset 0 or set 1, when it is set, it represents a decimal 1 (actually 2 to the power of 0 which we write as 2^0). When the next bit to the left is set, ie 1, the decimal value it represents will be 2 (2 to the power of 1, or 2^1) and if we go on further to the left the decimal values represented are 4, 8, 16, 32, 64, and 128 (increasing in powers of 2 thus 2^2=4, 2^3=8, 2^4=16 and so on until we reach 2^7=128).
So for the IP address in our example, the first number 10 is made up of the set bits representing 8 and 2 hence 8+2=10. Followed by the others below
|Binary bit values||Decimal equivalent and total value|
Identifying the network and the host addresses
The IP address is split into two components, the network part, and the host part.
When IPv4 was first introduced the network space was separated into classes that could be identified by inspecting the address. Class A, B, and C were allocated for public and private address space that could be used for network hosts (with some exceptions), while class D was for multicast addresses. Class E was reserved.
Class A networks used decimal values from 0.0.0.0 to 127.255.255.255.
Class B networks used decimal values from 126.96.36.199 to 188.8.131.52.
Class C networks used decimal values from 192.0.0.0 to 184.108.40.206.
Class D networks used decimal values from 220.127.116.11 to 18.104.22.168.
These values are not random, but align with the binary numbering system and we can identify which class of addresses the number relates to by inspecting the first three (most significant) bits of the first octet of the address. We need to look at the first four bits to identify class E addresses.
|Lowest value||-||Highest value||Decimal values||Class|
So class A addresses always have the most significant bit (MSB) set to 0, class B addresses always have the second most significant bit set to 0 while class C addresses have the third most significant bit always set to 0.
The subnet mask
An IPv4 address is always paired with what’s called a subnet mask. The subnet mask defines which bits in the IP address belong to the network and which bits belong to the host.
The original IPv4 specification defined default subnet masks for each class as follows.
|Class||Number of network bits||Subnet mask dot decimal||Subnet mask CIDR|
Where the subnet mask bit is set to 1, the corresponding bit in the IP address is considered to belong to the network, and where the subnet mask bit is 0, the corresponding IP address bit belongs to the host.
By default then, for a class A address, the first octet is the network address and the rest (octets 2 to 4) can be used for hosts. Similarly, for default class B addresses the first two octets belong to the network and the last two octets belong to the hosts. Class C, has the first three octets reserved for the network with the last octet for hosts.
So for our class A address 10.250.21.31 with a default mask of 255.0.0.0, the ’10’ is our network part and the host part is ‘250.21.31’. The 10 part would be common on all hosts on the network but the rest could be any number. There are two exceptions, which are the subnet address (sometimes referred to as the subnet-zero address) 10.0.0.0 and the subnet broadcast address which in this case is 10.255.255.255.
If we had a class C address such as 22.214.171.124 then with the default mask, the network part of the address would be ‘192.250.21’ which would be common to all the hosts on the network, leaving only the last octet available.
This means the number of hosts on the network will vary depending on the subnet mask. For a class C network, only the last octet is available for hosts so the maximum number of hosts is 256 minus 2 (the unavailable subnet and broadcast address). So we can have up to 254 hosts on a class C network.
For a default class B network such as 128.250.21, there are two octets available so we have 256 times 256 (65,536) subtract the subnet and broadcast and we can have 65,534 hosts. For class A networks we can have up to 16,777,214 hosts (256*256*256-2)
The subnet mask also reflects the number of networks available. If we use the defaults then a class A IP address can have 2^7 networks, since the first bit is always set to ‘0’ leaving 7 bits remaining for network addressing, 0 to 127 in decimal format or 128 networks. In practice 0 isn’t used so we have 127 class A networks by default. For class B and C we can have 2^14=16,384 and 2^21=2,097,152 networks respectively.
Classless IPv4 addressing (CIDR)
CIDR or Classless Inter-Domain Routing was introduced in 1993 to replace the classful network design of the previous system. It essentially decouples the default mask from the IP address and allows for smaller subnets or larger supernets.
IP addresses and subnet masks can be written in dot-decimal notation or CIDR notation ‘192.168.40.2 255.255.255.128’ can be written as ‘192.168.40.2/25’.
Note that the default mask would be 255.255.255.0, or a slash 24 (/24) for a 192 address. In this case, we have split the last octet into two networks by allocating 1 extra bit to the network.
We can tell how many bits are allocated by looking at the subnet mask, 1 bit = 128, 2 bits =128+64=192, 3 bits=128+64+32=224 and so on.
We can also tell how many hosts are on the network by subtracting the subnet mask from the number of possible hosts (256). For the example below, if we look at the CIDR mask of /25 we subtract 128 from 256 which gives us 128 and since we have to subtract 2 addresses for subnet and broadcast, it leaves us with 126 useable host addresses. We can’t use the /31 or /32 masks for the last octet (but you may see these addresses appear in routing tables).
|Subnet bits||Class equivalent||CIDR||Dot decimal value||No of hosts||No of networks|
|2^(32-no of subnet bits)-2||2^(no of subnet bits)|
|8||A Normal, B/C Supernet||/8||255.0.0.0||16,777,214||2^8=256|
|9||A Subnet, B/C Supernet||/9||255.128.0.0||8,388,606||2^9=512|
|10||A Subnet, B/C Supernet||/10||255.192.0.0||4,194,302||2^10=1,024|
|11||A Subnet, B/C Supernet||/11||255.224.0.0||2,097,150||2^11=2,048|
|12||A Subnet, B/C Supernet||/12||255.240.0.0||1,048,574||2^12=4,096|
|13||A Subnet, B/C Supernet||/13||255.248.0.0||524,286||2^13=8,192|
|14||A Subnet, B/C Supernet||/14||255.252.0.0||262,142||2^14=16,384|
|15||A Subnet, B/C Supernet||/15||255.254.0.0||131,070||2^15=32,768|
|16||A Subnet, B Normal, C Supernet||/16||255.255.0.0||65,534||2^16=65,536|
|17||A/B Subnet, C Supernet||/17||255.255.128.0||32,766||2^17=131,072|
|18||A/B Subnet, C Supernet||/18||255.255.192.0||16,382||2^18=262,144|
|19||A/B Subnet, C Supernet||/19||255.255.224.0||8,190||2^19=524,288|
|20||A/B Subnet, C Supernet||/20||255.255.240.0||4,094||2^20=1,048,576|
|21||A/B Subnet, C Supernet||/21||255.255.248.0||2,046||2^21=2,097,152|
|22||A/B Subnet, C Supernet||22||255.255.252.0||1,022||2^22=4,194,304|
|23||A/B Subnet, C Supernet||/23||255.255.254.0||510||2^23=8,388,608|
|24||A/B Subnet, C Normal||/24||255.255.255.0||254||2^24=16,777,216|
So with classless subnetting, you can choose the number of networks and hosts to suit the environment. If you are restricted to a specific prefix but need to segment it, you can do it with classless subnetting. Alternatively, you can also do what’s called super-netting by removing bits from a subnet mask which has can have the effect of adding classful subnets together. The following combination ‘192.168.40.2 255.255.254.0’ or ‘192.168.40.2/23’ results in the two, class C subnets ‘192.168.40.0’ and ‘192.168.41.0’ being joined in a contiguous network from ‘192.168.40.0’ through to ‘192.168.41.255’
Of course, if you’re just allocating a few private IP address ranges for a home network you might not want to worry about non-default subnets and just stick with one class C or if you want to access a home server from the Internet and choose to have a DMZ (demilitarized zone), perhaps two or more class C networks.
If you do choose to subnet, you can use a subnet calculator, even if it’s only to confirm that your choices and calculations are valid and that you haven’t selected something that isn’t going to work.
There are a number of such programs developed for iPhones (such as Subnet Calculator +) and for Android (ipv4 subnet calculator or IP network calculator), I’m currently using Subnet Calculator by Mecbe.
Most often though, I use an excel spreadsheet on my computer. It also works with google sheets, although it’s missing some sliders, so while it is possible to use it with a phone, I wouldn’t recommend it.
I’m making the spreadsheet available online as a freebie if it’s of use to anyone, and I’ll put up some screenshots and pointers here.
The Techiedoodah IPv4 Excel Subnet Calculator
The Techiedoodah Excel IPv4 subnet calculator is shown below. It is open on the Calcs sheet where you enter the IP address and subnet mask you wish to work with.
Most of the cells are locked. You can change the Subnet bits (1) either by typing in a value or clicking on the sliders to the right. Changing the subnet bits/prefix value will change the Subnet mask and the red bar below the “Classless network” title will move accordingly. It will also change the values in “Subnet Address” and “Broadcast Address” if they would be affected by the prefix change.
In the image above the sheet is showing that the current subnet prefix results in a “Supernet” since the classful default for a 172 address is to use a 16-bit mask, so we have 16 contiguous class networks encompassed by the above /12 prefix and they cover from 172.16.0.0 to 172.31.255.255. We can also see how many networks and how many hosts per network we can have, although the number of networks is the theoretical maximum since it includes public address space.
You can also change the IP address (2) which will alter the values of the Binary and Hexadecimal addresses at 3. Using the sliders at point 3. will also change the Binary and Hexadecimal addresses as well as the IP addresses in the sheet.
The image below shows what happens when we change the prefix to 19 from 12. The subnet mask has changed from 255.240.0.0 to 255.255.224.0, the subnet address has changed as well as the broadcast address, the number of networks and hosts, wildcard mask and the red bar below “Classless network”. Notice also that the “Supernet” tag has disappeared.
The image below shows what happens if we use a subnet mask that is not restrictive enough and includes address space from private, public and “zero-configuration” space.
The Allocation sheet shows what problems might be found in the address range included by the currently selected prefix and address combination. Note that the bar on the left shows which IP ranges are included. This would be green if there were no problems.
Going to the Subnets sheet we can see the subnet addresses for our subnet (in black) together with the other available subnet ranges. In the case of a /19 prefix, we have eight possible subnets if we keep the first two octets the same.
The Address Ranges sheet just includes links to RFC pages and to the Wikipedia page about classful network ranges. It’s included for reference. The data included are subject to change.
The spreadsheet does require the Analysis ToolPak Add-In for the Binary address and Hexadecimal address sections to work so if you have problems with those cells please read the instructions in the Subnet Calculator text box.
This spreadsheet is provided by Techiedoodah “as is” and “with all faults.” Techiedoodah makes no representations or warranties of any kind concerning the safety, suitability, lack of viruses, inaccuracies, typographical errors, or other harmful components of this spreadsheet. There are inherent dangers in the use of any files downloaded from the Internet, and you are solely responsible for determining whether this spreadsheet is compatible with your equipment and other software installed on your equipment. You are also solely responsible for the protection of your equipment and backup of your data, and Techiedoodah will not be liable for any damages you may suffer in connection with using, modifying, or distributing this spreadsheet.
Do virus check the spreadsheet, it’s not macro enabled and does not contain macros so if you get the spreadsheet with a .xlsm instead of a .xlsx extension then be wary.
While the sheets in the spreadsheet are protected, you can turn off that protection, there is no password.
You are free to make any changes to the spreadsheet as desired and distribute as you wish but please keep the links in for the Techiedoodah website.
The SHA256 checksum for the file is 173BEA8F7FE4F8CF5176FF25DE8B7C9E23F2C1119DBB355A81542BD287F12872
To cut a long story short, a summary.
Despite the fact that RIPE has run out of public IPv4 addresses for allocation, IPv4 still needs to be managed and configured in the real world. Whether it’s using private address space for a home network, or something larger, it helps to know how the IP address relates to the subnet mask and which parts belong to the network and which parts are available for host addresses.
To aid the choice and creation of subnets we can make use of IPv4 subnet calculators. There are apps and programs available for iPhone, Android as well as for Linux and Windows such as the Free Solarwinds tool.
There’s also the Techiedoodah IPv4 subnet calculator spreadsheet available for free by subscribing to the newsletter in the form above.
If you’re a network engineer and you get a lot of time hands on rackside and need a tray to put your laptop on, let us know what you think of the Portable Rack Mount Laptop Tray and sign up if you want one. Type with two hands instead of one, be more comfortable, improve your productivity and get out of the server room sooner, (or wherever the rack happens to be).
Techiedoodah blogs are created in the hope that they can help others by giving real-life examples. If this has been useful to you please feel free to leave a comment. If you’re reading this post on the home page, you won’t be able to post comments here, so follow this link to the blog, and then scroll to the comments section at the bottom of the page.