Subnetting IPv4 – TL;DR

Estimated difficulty: 💜💜💜🤍🤍

Every time I attend a course and someone tries to explain subnetting to me, they pretty much un-teach me it and I have to go away and re-learn how it works. To keep this post short and simple, I’m just going to cover how subnetting works, and not delve much into other networking concepts.

So firstly, a subnet is a small unit of a network (subnetwork, if it helps) – we pretty much want to carve a network up into smaller blocks to make it easier to route packets, transmit data, troubleshoot issues, build in a bit of resilience, or separate assets for security reasons and so on. A common analogy for this is to think of IP addresses and subnets in the same way you would as a physical address or a postcode (ZIP code in the US). Here’s a fake address (broken down into four parts so you can see the parallel) as an example:

House number: 102 
Street name: Terrick Road
Town: Elmley Castle
Postcode: WR10 0TJ

Postcodes nowadays can usually pinpoint the street or building, so all you really need is the house or apartment number, but basically, a subnet is just a way to logically separate an IP (Internet Protocol) network in this same way.

IP Addressing

In case you’re not totally familiar with IP addressing, IPv4 addresses consist of four binary octets (bytes). (If you don’t understand binary and want to read more about it, I wrote this a little while ago.) To make them easier for humans to read, we represent them in denary (decimal), with separators like this:

Binary: 00000110000001100000011000000110
Denary: 10.10.10.10

This shows you how they’re broken down:

Image credit: iTT Systems

IPv4

There are five classes of IPv4 addresses, for the purposes of this post we’ll focus on the most common – classes A, B and C.

ClassIP RangeUse
Class A1.0.0.1 – 126.255.255.254127 networks with up to 16 million hosts each
Class B128.1.0.1 – 191.255.255.25416000 networks with up to 65000 hosts each
Class C192.0.1.1. – 223.255.254.2542 million networks with up to 254* hosts each
IP’s beginning 127. (between Class A and Class B) are reserved for loopback IP addresses.

*As a side note, a number of IP addresses on a network can’t be assigned to hosts because they’re reserved for other purposes – there’s usually a network IP and a broadcast IP (e.g. x.x.x.0 – the network number/IP, and the final IP in the range e.g. x.x.x.255 – which will broadcast to every other host in that IP range). This is why even though theoretically a network could support up to 256 hosts, the number of usable IP addresses is less.

At a simple level, for Class A, the first octet is reserved for the network address, and the next three octets are host addresses. For Class B, the first two octets are reserved for the network address, and the third and fourth octet are the host addresses. For Class C, the first three octets refer to the network address, and the final octet refers to the host addresses.


Subnetting IPv4

If we stick to these conventions, the structure of IPv4 is quite inefficient because of the rigidity of network/host splits in addresses – if you only need 50 hosts on a network (or a portion of a network), you’d be wasting about 200 IP addresses on a standard Class C network. So we divide these networks into subnets, by splitting out the last octet into subnets and host IDs.

For 50 hosts, we’d only need 6 bits of the last octet for host IPs – which frees up 2 bits of the octet and allows us to create 4 subnets, which can each support up to 62 hosts (64 minus the network and broadcast addresses).

11000000101010000000000101000000
The subnet mask here would be 192.168.1.64/26 or 255.255.255.192

The problem with this is that by default a computer will try to read all 8 bits of the last octet as a host address, so we need a subnet mask to tell the computer that we’ve used 2 bits of the host octet for a subnet.

The subnet mask for a subnet of this size would be 255.255.255.192 – we’re basically feeding in a note to say; “We’re using these bits for the network address” – and 256 (total addresses) – 192 (the final part of the subnet mask) = 64 (total addresses, including network and broadcast addresses).

CIDR (Classless Inter-Domain Routing) notation for this is /26 – which shows that the first 26 bits of the 32-bit IP are reserved for the network address, and the final 6 are used for the host IP’s.

Here’s a cheat sheet (kindly provided by ZephrFish) to show you some examples.

IP addressing is about 40 years old – IPv4 was formally standardised in 1981, and because of the structure the maximum number of IPv4 addresses available globally is just under 4.3 billion. That sounds like a lot, but think about how many more devices than people there now are in the world – you won’t be surprised that 4.3 billion IP’s hasn’t been enough. This is where IPv6 comes in (1998) – we’ll cover this in a separate post, in the interest of keeping this one a sub-5 minute read.


Subnetting can be quite difficult to get your head around, so if this explanation didn’t help – I quite liked this reddit thread, and this article on iTT Systems might be helpful for an explanation of IPv4.

Thank you for reading!

Morgan x

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.