Understanding IP Addressing – Network and Host, CIDR, and Address Calculations
When we look at an IP address like 192.168.1.20, it just looks like a bunch of numbers. But the truth is, that address is made up of two parts: one part tells us which network it belongs to, and the other part tells us which device (or host) it is within that network.
The tricky thing is – you can’t tell which part is which just by looking at the IP. You also need something called a subnet mask or CIDR value to make sense of it.
Network Part and Host Part
An IP address is a 32-bit number. Some bits are used to identify the network, and the remaining bits are used to identify the host inside that network.
For example:
- IP: 192.168.1.20
- Mask: 255.255.255.0 (or /24 in CIDR)
In this case, the first 24 bits are in network part and the last 8 bits are in host part, so:
- The network part is 192.168.1
- The host part is 20
(This IP belongs to the network 192.168.1.0, and the device number is 20 within that network.)
CIDR Value and Mask – How They Work
Both CIDR Value and mask tell us how many bits are reserved for identifying the network part.
- You might have seen IP addresses written like 192.168.1.1/24 – here, /24 means that the first 24 bits are used for the network part. This way of showing how many bits are in the network portion is called CIDR notation.
- The mask 255.255.255.0 is just another way of saying that 24 bits are in the network part. In this format, to understand how many bits are used for the network, you need to convert the mask to binary and count the number of 1s. For example, 255.255.255.0 in binary is 11111111.11111111.11111111.00000000 – if you count the number of 1s, there are 24. That means 24 bits are used for the network part.
How to Convert CIDR to Subnet Mask
CIDR notation (like /24) tells us how many bits are used for the network part. The rest is for the host part.
Each IP address has 32 bits, divided into 4 blocks of 8 bits (called octets).
To convert a CIDR value to a subnet mask, you start by writing that many 1s from the left (based on the CIDR number), then fill the remaining bits with 0s to complete 32 bits. Group them into 8-bit blocks to get the 4 octets of the mask.
Let’s look at some examples:
- /24 → 24 bits for network
So the first 3 octets are full 1s:
11111111.11111111.11111111.00000000
→ Mask: 255.255.255.0 - /26 → 26 bits for network
That’s 3 full octets and 2 extra bits in the 4th octet:
11111111.11111111.11111111.11000000
→ Mask: 255.255.255.192 - /30 → 30 bits for network
3 full octets and 6 bits in the last one:
11111111.11111111.11111111.11111100
→ Mask: 255.255.255.252
You don’t have to memorize the binary, just remember:
- Each 8 bits of 1s = 255
- 7 bits = 254, 6 bits = 252, 5 bits = 248, 4 bits = 240, and so on
| CIDR Value | Subnet Mask | Number of IPs in Network |
|---|---|---|
| /30 | 255.255.255.252 | 4 |
| /29 | 255.255.255.248 | 8 |
| /28 | 255.255.255.240 | 16 |
| /27 | 255.255.255.224 | 32 |
| /26 | 255.255.255.192 | 64 |
| /25 | 255.255.255.128 | 128 |
| /24 | 255.255.255.0 | 256 |
| /23 | 255.255.254.0 | 512 |
| /22 | 255.255.252.0 | 1024 |
| /21 | 255.255.248.0 | 2048 |
| /20 | 255.255.240.0 | 4096 |
| /19 | 255.255.224.0 | 8192 |
| /18 | 255.255.192.0 | 16384 |
| /17 | 255.255.128.0 | 32768 |
| /16 | 255.255.0.0 | 65536 |
Why CIDR or Mask is Important
You can’t tell if two IPs are in the same network just by comparing the first few numbers. Here’s an example:
- IP1: 10.1.1.5
- IP2: 10.1.1.200
Are these two in the same network?
- If the mask is /24 (i.e., 255.255.255.0), then yes, both are in the network : 10.1.1.0/24
- But if the mask is /25 (i.e., 255.255.255.128), then:
- 10.1.1.5 is in the network: 10.1.1.0/25
- 10.1.1.200 is in the network: 10.1.1.128/25
- So, they’re in different networks if the mask is 25 and they’re in same network if mask is 24.
That’s why the CIDR value or mask is essential for understanding IP addressing.
How to Check if Two IPs Are in the Same Network
If you’re given two IP addresses and a subnet mask or CIDR value, here’s how to check whether they belong to the same network.
Steps:
- Convert each IP address to binary.
- Convert the subnet mask (or CIDR) to binary.
- Do a bitwise AND between the IP and the mask. This gives you the network address.
- If the network address of both IPs is the same, they are in the same network.
Example:
- IP1: 192.168.1.10
- IP2: 192.168.1.100
- Mask: /24 → 255.255.255.0
Binary:
- IP1 → 11000000.10101000.00000001.00001010
- IP2 → 11000000.10101000.00000001.01100100
- Mask → 11111111.11111111.11111111.00000000
Now apply bitwise AND:
- IP1 AND Mask → 11000000.10101000.00000001.00000000 → 192.168.1.0
- IP2 AND Mask → 11000000.10101000.00000001.00000000 → 192.168.1.0
Result: Both IPs are part of the 192.168.1.0/24 network.
If their results were different, they’d be in different networks.
A Quicker Way to Check – Compare Network Part Bits
The previous method is the proper and accurate way to check if two IPs are on the same network – apply the mask and compare the network addresses.
But here’s a quicker way that gives the same result:
- Convert both IPs to binary.
- Check only the first n bits, where n is the number of bits in the network part (CIDR value).
- If these n bits are the same in both IPs → they are in the same network.
- If they differ → they’re in different networks.
Example using /24:
- IP1: 192.168.1.10 → 11000000.10101000.00000001.00001010
- IP2: 192.168.1.100 → 11000000.10101000.00000001.01100100
For /24, look at the first 24 bits. In both cases, the first 24 bits are the same, so they’re in the same network.
This is a handy mental trick when you get familiar with binary notation.
Network Address, Host Address, and Broadcast Address
In any IP network, you’ll always have three types of addresses:
- Network address – Identifies the network itself. It’s the first address in the range and cannot be assigned to any device.
- Broadcast address – The last address in the range. It’s used to send data to all hosts in that network.
- Host addresses – All the IPs in between. These are assignable to devices like PCs, routers, etc.
How to Find the Network Address
To find the network address:
- Convert the given IP address to binary.
- Identify the host part based on the subnet mask or CIDR.
- Change all the bits in the host part to 0.
- Convert the binary back to decimal – that’s your network address.
Example 1:
IP: 192.168.1.10
CIDR: /24 → means first 24 bits are network part
Binary of IP:
11000000.10101000.00000001.00001010
Now, set all the last 8 bits (host part) to 0:
11000000.10101000.00000001.00000000
Convert back to decimal:
Network Address = 192.168.1.0
How to Find the Broadcast Address
To find the broadcast address:
- Convert the IP to binary.
- Set all the bits in the host part to 1.
- Convert back to decimal – that’s your broadcast address.
Using the same example:
Set the last 8 bits to 1:
11000000.10101000.00000001.11111111
Convert to decimal:
Broadcast Address = 192.168.1.255
Example 2:
IP: 10.0.8.45
CIDR: /22 → first 22 bits are network, remaining 10 are host
Binary of IP:
00001010.00000000.00001000.00101101
Network part (first 22 bits):
00001010.00000000.000010
Host part (last 10 bits):
0000101101
Set host part to 0:
00001010.00000000.00001000.00000000 → Network Address = 10.0.8.0
Set host part to 1:
00001010.00000000.00001011.11111111 → Broadcast Address = 10.0.11.255
How Many IPs in a Network?
The formula to calculate the number of usable IPs:
Usable IPs = 2^n – 2
Where n = number of bits in the host part.
Examples:
- /24 → 32 – 24 = 8 bits for host → 2^8 = 256 → 256 – 2 = 254 usable IPs
- /30 → 2 bits for host → 2^2 = 4 → 4 – 2 = 2 usable IPs
The subtraction of 2 is because:
- One IP is reserved for the network address
- One IP is reserved for the broadcast address
Practice Questions
Question 1.
IP Address: 192.168.10.34, CIDR: /24
What is the network address and the broadcast address?
Show Answer
CIDR /24 means the last octet is for host.
Broadcast address = 192.168.10.255
Network address = 192.168.10.0
Question 2.
IP Address: 172.16.5.200, CIDR: /20
- How many usable IPs are available in this network?
- What is the network address?
Show Answer
/20 leaves 12 bits for host → 2^12 = 4096 IPs
→ Usable = 4096 – 2 = 4094
Network address = 172.16.0.0
Question 3.
You need to create a subnet that supports at least 60 devices.
What CIDR should you use, and what will be the subnet mask?
Show Answer
You need at least 60 usable IPs → 2^6 = 64
Subnet mask = 255.255.255.192
CIDR = /26
Question 4.
Given subnet mask: /25
You have the following IPs:
- 192.168.1.65
- 192.168.1.80
- 192.168.1.129
Which of these IPs are in the same subnet?
Show Answer
/25 means ranges:
192.168.1.0 – 192.168.1.127
192.168.1.128 – 192.168.1.255
So, 65 and 80 are in the same subnet
129 is in a different one
Question 5.
CIDR: /29
- How many usable IP addresses are there in this network?
- What is the subnet mask?
Show Answer
/29 → 3 bits for host
Total = 2^3 = 8
Usable = 6
Subnet mask = 255.255.255.248
Question 6.
IP Address: 10.0.16.25, CIDR: /20
What is the broadcast address of this network?
Show Answer
/20 leaves 12 bits for host
Binary of 10.0.16.25 = 00001010.00000000.00010000.00011001
Set host bits to 1 → 00001010.00000000.00011111.11111111
→ Broadcast address = 10.0.31.255
We’d love to hear your feedback and suggestions about this article. Feel free to reach out to us using the WhatsApp number below.
About The Author:
Sajith Achipra has been a trainer and testing consultant at Zframez Technologies since 2009. With 15+ years of experience, he specializes in networking, Python, development, and testing. He conducts online courses to help students and professionals enhance their skills. You can reach him on WhatsApp at +91 8884 884 844 for your training and testing requirements.