Learn IPv4 and Subnet Masking: The Beginner's Guide


“There are 10 types of people in this world, those who understand binary and those who don't.” ~ a wise sage
Understanding Binary
The computer and the human brain work differently, you and I know that. While humans think about numbers using the decimal system, the computers convert everything into binary to understand them. When talking about IPs, one of the first things that you have to understand is that each IP address is subdivided into four 8-bit parts known as octets.
Therefore when you see an IP such as
76.240.249.145
your computer will read it as
01001100.11110000.11111001.10010001
When it comes to the octet the minimum value you could have is 0 = 00000000 but as an IP cannot be 0.0.0.0 unless it’s a wildcard, somewhere within the four parts it would have to be 1 = 00000001.
The maximum value you could have in the octet would be 11111111 = 255. So, an IP with 255.0.1.255 = 11111111.00000000.00000001.11111111.
Converting Decimal to Binary & Vice Versa
When converting decimal to binary what you need to know is that binary increases in the number of digits for each increment to the power of 2, after 0 & 1 of course.
Eg:
1 = 1 + 4 = 5
0 = 0
2 = 2^1 = 10
4 = 2^2 = 100
8 = 2^3 = 1000
Therefore if you want to convert decimal 5 to binary you would pick the value with the exponent of 2 which is just below the number you would want to get the decimal of. In our case is 4 which is equal to 00000100.
From their you would want to take the remainder of 5 - 4 = 1, and the binary of 1 as an octet would be 00000001. Finally when you add the binary numbers for 4 & 1 together, you get
**00000100** + **00000001** = **00000101**
We then conclude that decimal number 5 in binary is 00000101.
Network & Host IDs
These 8-bit octets are further divided into 2 main parts, known as the Network-ID, and the Host-ID.
The Network ID - Computers on the same network will share the same Network-ID which would be a certain set of number as the first part of your IP address.
Eg: 76.240.249.145, the highlighted numbers could be your network ID. We don’t know this for certain since we have not specified a subnet mask.
The greater the length of the network ID, the lesser the number of assignable host IDs.
Host ID - The host ID would be the last part of your IP address. This is a unique identifier which is assigned to each computer that’s on your network.
💡 Note: The Network ID & the Host ID do not have to be divided equally — It’s not always the case that two parts make up the network ID and two address parts make up the host ID.
Subnet Mask
The splitting of an IP address into the Network section and the Host section is done via what is known as a subnet mask.
This is done by what is known as a Classless Inter-Domain Routing (CIDR) notation. The IPv4 address represented by a CIDR notation is known as a network mask and specifies the number of bits in the prefix to the address after a forward slash (/) separator. Eg:
192.168.10.64/24
When converted to binary the above IP address would look like:
11000000.10101000.00001010.01000000/24
Therefore the subnet mask specifies that the first 3 octets are going to be the network ID, and the last octet is going to be the host ID.
Now that we know the subnet mask, we can calculate what IPs are available to assign to our hosts.
Starting with
11000000.10101000.00001010.00000001 = 192.168.10.1
and ending with
11000000.10101000.00001010.11111110 = 192.168.10.254
Now you must be wondering why the last assigned host ID is 254 (11111110) and not 255 (11111111), which is the max range of the octet right? Or didn’t even think about it. 😅 Well this is because the last one is reserved as a broadcast ID. The last ID, the broadcast ID is assigned for communication purposes between your router and computer, which enables your network to even be a network! Eg: DHCP - Dynamic Host Configuration Protocol.
Subscribe to my newsletter
Read articles from Ranindu Abeyratne directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
