A Introduction to IPv4 Addressing

A Introduction to IPv4 Addressing

IP addresses consist of 4 bytes of data. Each byte (or octet) can range from a value of 0 to 255, resulting in a total number of 4,294,967,296 different IP address combinations. This was considered to be a perfectly scalable number of unique addresses in 1977, however the Internet proved more successful than anticipated and we began to run out of IP addresses. IPv6 was invented in 1996 to provide more unique combinations, however over two decades later it still suffers from minimal adoption.


Subnet Masks

Every IP address is a part of a network, and the scope of the network is calculated by the subnet mask. A subnet mask, like an IP address, is a 32-bit value. Where IP addresses use these 32-bits to create a unique address value, subnet masks use these 32-bits to define where the network boundaries of the IP address lie. Let's look at an example:

192.168.1.1
255.255.255.0

This address is a common "private" IP address (which you will likely find in use on most public wifi networks). The subnet mask has 3 octets of 255 (meaning all bits equal 1), and a final octet of zero. This zero octet shows where the network address finishes and the host addressing begins. From this, we can understand that this 192.169.1.1 address is a part of the 192.168.1.0 network, of which it has the host address of 1. We can also understand that because the final octet of the subnet mask is 0, there can be 255 unique addresses within the 192.168.1.0 network. This is known as a Class C network, and is the smallest Classful network.

Let's Look at this same address in converted to binary:

11000000.10101000.00000001.00000001 = 192.168.1.1
11111111.11111111.11111111.00000000 = 255.255.255.0
<-----------network------><--host-->

Now the IP address itself is simply a unique number, but it is the subnet mask that defines the network. This Class C network has a 24-bit subnet mask, which allows for 8 bits of host addressing, or 255 unique host addresses within this network.

In the early days of the Internet, IP addresses were in abundance. Any network applying for their own IP addresses would be given either a Class A, B or C, depending of the size of their network and their requirements. This was an inefficient method of allocating IP address. If a network had a requirement for 300 addresses, they would need to be given two Class C networks (total of 510 addresses) just to cover their requirements.

Altering the subnet masks can be used to divide traditional Classful networks into smaller, more efficient network domains. This practise is called Classless-Inter-Domain-Routing (CIDR), and is used to create subnets, or sub-networks.

We can change the subnet mask to split this /24 in half:

11000000.10101000.00000001.00000001
11111111.11111111.11111111.10000000
<-----------network-------><-host-->

We have now defined a 25-bit subnet mask. While the IP address 192.168.1.1 has not changed, we can now see that this network can only have 127 unique host addresses, as we have a maximum of 7 host bits.

We have successfully carved 192.168.1.0/24 in half, and as a result we have created networks 192.168.1.0/25 and 192.168.1.128/25.


Broadcast Operation

A lot of protocols utilise broadcast communication to direct signalling messages to a group of devices. ARP uses MAC address broadcasting to resolve the a known IP address to that devices corresponding MAC address. DHCP uses IP broadcasting when joining a new network to locate the local DHCP server when it's address is unknown.

On Ethernet, MAC Address FF:FF:FF:FF:FF:FF is used to broadcast a message throughout the local domain. IPv4 is similarly able to use IP Address 255.255.255.255 for local broadcasts, however this is an unroutable address restricted to local routing domains. Because of this, a broadcast address is reserved in every subnet by default, and this is the last address of the subnet.

Let's look at our example network:

Network:                   192.168.1.0/25
Network Address:           192.168.1.0
Broadcast Address:         192.168.1.127
Usable Host Addresses:     192.168.1.1-126

Now first of all, our subnet begins at 192.168.1.0. This is the Network Address, and is used by routers to identify the subnet prefix installed in their routing tables. Therefore this address is not able to be assigned to hosts, as a router needs to be able to differentiate between a host address and a network prefix.

This network's subnet mask allows for 7 hosts bits, meaning 127 unique addresses can reside within this subnet. Because the next consecutive network begins at 192.168.1.128, the very last address in our subnet will be 192.168.1.127. This is the Broadcast Address, and a packet sent to this address will be delivered to every host addresses within the 192.168.1.0/25 network.


Related Article