Sunday, February 11, 2024

Networks and Subnetting in IPv4

 Even though IPv4 is getting older, it's still in use in a lot of places right now. Understanding the basics is important. So let us explore the basics. First, let's check out the anatomy of an IPv4 address. An IPv4 address is a number sequence comprised of 4 octets. Octets is a fancy way of saying each number is one byte, which is made of 8 binary digits, thus octet. An octet means you have 256 possible values, 0 through 255. The values are broken down into 4 numbers connected by periods, like There are some special addresses in that total list, so let's start with the two big ones.

An IP address of is a special default of "everything goes." You may see this in a server configuration to accept connections from any host or on any address. Then you have, which is a broadcast address. This is basically a "send this to everyone."

Now let's talk about what all the other network information means.

An IP address is a specific address associated to a device on the network.

A Network ID is the information used to tell what is used to identify what is a part of the same network along side a Subnet Mask.

A CIDR (Classless inter-domain routing) is used as a way to represent a subnet usually as a / after the Network ID.

A Default Gateway is the address assigned to a device that usually handles how traffic is going in, out, and routing around a network.

A broadcast address is a special address used to notify everything within a specific network.

That being said, let's take a basic network:

With this, the following information can be seen immediately:

Network ID =

CIDR = 24

The CIDR is a handy number to have because it can tell us how many usable IP addresses exist in that network space. To understand how, let's explore the subnet mask. So as mentioned before, an IP address is 4 octets, an octet is 8 binary digits. This means 8 digits times 4, because it's 4 octets total is 32 binary digits. A CIDR is how many digits in the address are part of the Network ID. So a CIDR can be from 0 to 32. This means that the Network ID is the first 24 binary digits (bits) and the remaining for the network is 32-24, or 8 bits. To get the number of possible values, we keep in mind we are working with binary, use the equation:





There are 256 possible values. However, this number is actually still technically wrong. Within that range, there are two special addresses I will explain why further down. Just know for now that those are the Network ID ( and the Broadcast address ( So the number of usable address equation in full is:

2^(32-CIDR) - 2

2^(32-24) - 2

2^8 - 2

256 - 2


There are 254 usable addresses you can assign to devices on the network. Let's turn the CIDR into what a subnet mask looks like. For this, you need to understand binary. There are 24 Network ID bits, they start at the beginning. We will divide it into octets with periods starting from the beginning with 1s until we hit the CIDR, then fill the rest of the 32 with 0s, like so:


You then can take each octet and convert it from binary to decimal, giving you the following:

A subnet mask is important for identifying the network compared to the Network ID. What needs to be understood at this point is that when we look at the network, all those 1s are what cannot change on the IP to be on the same network, and the 0s are the ones we can change an use. So how does this all work? Let's start with any 192.168.1.X address (


We then take that binary value and run it through a process called "Anding" with a subnet mask. This means we compare each bit, if both are 1 we get 1, otherwise we get 0.





Now that we have that answer, we would then compare it for equality against the Network ID, in which case the binary value there and the Network ID of are the same. While we as people may be able to make the comparison a little faster without the anding, but a computer needs to do it for the comparison to be fast and easy. When it comes to computers, they can do binary operations far faster than looking at a number string arbitrarily like a human would do. This is also where we get the broadcast address from.

So now let's use the numbers to find the broadcast address. To get the broadcast address we need to take the binary of the network ID and fill in the remaining portion that would be 0 by the subnetmask with 1s. It would look as follows:


When we convert this back into a human readable form, it becomes Keep in mind that not everything will all work out this cleanly, it's just that a /24 is very common because it is easier to work with. The main thing to keep in mind is that the numbers may appear strange, but that is because everything is working in binary. All of it really boils down to binary logic and understanding.

Tag Cloud

.NET (2) A+ (5) ad ds (1) addon (4) Android (4) anonymous functions (1) application (9) arduino (1) artificial intelligence (1) backup (1) bash (6) camera (2) certifications (3) comptia (5) css (2) customize (11) encryption (3) error (13) exploit (5) ftp (1) funny (4) gadget (4) games (3) GUI (5) hardware (16) haskell (6) help (14) HTML (3) imaging (2) irc (1) it (1) java (2) javascript (13) jobs (1) Linux (19) lua (1) Mac (4) malware (1) math (6) msp (1) network (13) perl (2) php (3) plugin (2) powershell (8) privacy (2) programming (24) python (10) radio (2) regex (3) repair (2) security (16) sound (2) speakers (2) ssh (1) story (5) Techs from the Crypt (5) telnet (1) tools (13) troubleshooting (11) tutorial (9) Ubuntu (4) Unix (2) virtualization (2) web design (6) Windows (16) world of warcraft (1) wow (1) wx (1)