A simple guide to IPv4 addressing

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.

A simple guide to IPv4 addressing, example output from the windows "ipconfig" command
Example “ipconfig” output from the command prompt of a Windows 10 computer

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
1286432168421
000010108+2=10
11111010128+64+32+16+8+2=250
0001010116+4+1=21
0001111116+8+4+2+1=31

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 128.0.0.0 to 191.255.255.255.
Class C networks used decimal values from 192.0.0.0 to 223.255.255.255.
Class D networks used decimal values from 224.0.0.0 to 239.255.255.255.

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 valuesClass
00000000-011111110-127A
10000000-10111111128-191B
11000000-11011111192-223C
11100000-11101111224-239D
11110000-11111111240-255E

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.

ClassNumber of network bitsSubnet mask dot decimalSubnet mask CIDR
A8255.0.0.0/8
B16255.255.0.0/16
C24255.255.255.0/24

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 192.250.21.31 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 bitsClass equivalentCIDRDot decimal valueNo of hostsNo of networks
2^(32-no of subnet bits)-22^(no of subnet bits)
1All Supernet/1128.0.0.02,147,483,6462^1=2
2All Supernet/2192.0.0.01,073,741,8222^2=4
3All Supernet/3224.0.0.0536,870,9102^3=8
4All Supernet/4240.0.0.0268,435,4542^4=16
5All Supernet/5248.0.0.0134,217,7262^5=32
6All Supernet/6252.0.0.067,108,8622^6=64
7All Supernet/7254.0.0.033,554,4302^7=128
8A Normal, B/C Supernet/8255.0.0.016,777,2142^8=256
9A Subnet, B/C Supernet/9255.128.0.08,388,6062^9=512
10A Subnet, B/C Supernet/10255.192.0.04,194,3022^10=1,024
11A Subnet, B/C Supernet/11255.224.0.02,097,1502^11=2,048
12A Subnet, B/C Supernet/12255.240.0.01,048,5742^12=4,096
13A Subnet, B/C Supernet/13255.248.0.0524,2862^13=8,192
14A Subnet, B/C Supernet/14255.252.0.0262,1422^14=16,384
15A Subnet, B/C Supernet/15255.254.0.0131,0702^15=32,768
16A Subnet, B Normal, C Supernet/16255.255.0.065,5342^16=65,536
17A/B Subnet, C Supernet/17255.255.128.032,7662^17=131,072
18A/B Subnet, C Supernet/18255.255.192.016,3822^18=262,144
19A/B Subnet, C Supernet/19255.255.224.08,1902^19=524,288
20A/B Subnet, C Supernet/20255.255.240.04,0942^20=1,048,576
21A/B Subnet, C Supernet/21255.255.248.02,0462^21=2,097,152
22A/B Subnet, C Supernet22255.255.252.01,0222^22=4,194,304
23A/B Subnet, C Supernet/23255.255.254.05102^23=8,388,608
24A/B Subnet, C Normal/24255.255.255.02542^24=16,777,216
25A/B/C Subnet/25255.255.255.1281262^25=33,554,432
26A/B/C Subnet/26255.255.255.192622^26=67,108,864
27A/B/C Subnet/27255.255.255.224302^27=134,217,728
28A/B/C Subnet/28255.255.255.240142^28=268,435,456
29A/B/C Subnet/29255.255.255.24862^29=536,870,912
30A/B/C Subnet/30255.255.255.25222^30=1,073,741,824
31A/B/C Subnet/31255.255.255.25402^31=2,147,483,648
32A/B/C Subnet/32255.255.255.25502^32=4,294,967,296

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’

Subnet Calculators

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.

An image showing the Techiedoodah IPv4 subnet calculator excel .xlsx spreadsheet open on the Calcs sheet.
The Techiedoodah IPv4 subnet calculator .xlsx spreadsheet.

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.

Changing the subnet prefix in the Techiedoodah IPv4 subnet calculator excel .xlsx spreadsheet.
Changing the subnet prefix on the Techiedoodah IPv4 subnet calculator .xlsx spreadsheet.

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 Techiedoodah IPv4 subnet calculator showing conflicting address space in a single subnet.
The Techiedoodah IPv4 subnet calculator showing conflicting address space in a single subnet.

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.

The Techiedoodah IPv4 subnet calculator showing subnet problems on the allocation sheet.
The Techiedoodah IPv4 subnet calculator showing subnet problems on the allocation sheet.

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 Techiedoodah IPv4 subnet calculator showing the Subnet sheet.
The Techiedoodah IPv4 subnet calculator showing the Subnet sheet.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *