Deep Dive into IP Subnetting and Subnet Masks, Binary to Decimal Conversion
Deep Dive into IP Subnetting and Subnet Masks
1. Introduction to IP Addressing
An IP address is a unique identifier for a device on a network. IPv4 addresses are 32-bit numbers, typically represented in dotted decimal notation (e.g., 192.168.1.1).
Each IP address consists of:
  • Network Portion – Identifies the network.
  • Host Portion – Identifies a specific device within the network.
To determine which part belongs to the network and which belongs to the host, we use a subnet mask.
2. Understanding Subnet Masks
A subnet mask is a 32-bit value that separates the network and host portions of an IP address.
  • It consists of contiguous ones (1s) for the network part and zeros (0s) for the host part.
  • Example of a subnet mask:
255.255.255.0
In binary:
11111111.11111111.11111111.00000000
  • The ones (1s) define the network.
  • The zeros (0s) define the hosts.
This means all IP addresses in the subnet share the same network part, while the host part varies.
3. Converting Dotted Decimal to Binary
Since IP addresses and subnet masks are actually binary, let's break it down.
Example:
Convert 255.255.255.252 to binary:
Decimal
Binary
255
11111111
255
11111111
255
11111111
252
11111100
Subnet mask in binary:
11111111.11111111.11111111.11111100
Here, 30 bits are network bits, and 2 bits are host bits.
4. Finding the Number of Networks and Hosts
We use these formulas:
Number of Hosts per Subnet
2h−22^h - 22h−2
Where:
  • hhh = number of host bits (0s in the subnet mask).
  • Subtract 2 because: The first address is reserved as the network address. The last address is reserved as the broadcast address.
Example (255.255.255.252 or /30)
  • Subnet mask: 11111111.11111111.11111111.11111100
  • Host bits: 2
  • Hosts per subnet: 22−2=4−2=2 usable hosts2^2 - 2 = 4 - 2 = 2 \text{ usable hosts}22−2=4−2=2 usable hosts (Perfect for a point-to-point link!)
Number of Subnets Created
2s2^s2s
Where:
  • sss = number of subnet bits (1s beyond the default network mask).
Example (Splitting a /24 into /30 subnets)
  • Original /24 mask: 255.255.255.0 → 11111111.11111111.11111111.00000000
  • New /30 mask: 255.255.255.252 → 11111111.11111111.11111111.11111100
  • Extra subnet bits: 30 - 24 = 6
  • Total subnets: 26=642^6 = 6426=64
So, a /30 subnetting scheme divides a /24 network into 64 subnets.
5. Example of Subnetting a Class C Network
Assume we have 192.168.1.0/24, and we want to subnet it into /26 subnets.
Step 1: Determine New Subnet Mask
  • /24 Mask: 255.255.255.0
  • /26 Mask: 255.255.255.192
11111111.11111111.11111111.11000000
Step 2: Identify the Changes
  • Subnet bits: 26 - 24 = 2
  • New subnets: 22=42^2 = 422=4 subnets
  • Host bits: 6
  • Usable hosts per subnet: 26−2=622^6 - 2 = 6226−2=62
Step 3: List the Subnet Ranges
Since we borrowed 2 bits, our subnet increments by 64 in the last octet:
  • 192.168.1.0/26 → 192.168.1.0 - 192.168.1.63
  • 192.168.1.64/26 → 192.168.1.64 - 192.168.1.127
  • 192.168.1.128/26 → 192.168.1.128 - 192.168.1.191
  • 192.168.1.192/26 → 192.168.1.192 - 192.168.1.255
Each subnet has 62 usable hosts.
6. CIDR Notation and VLSM
  • CIDR (Classless Inter-Domain Routing) allows flexible subnetting by defining subnet masks with a slash (/) notation.
  • VLSM (Variable-Length Subnet Masking) allows different-sized subnets within the same network, optimizing address usage.
Example:
  • /30 for point-to-point links (2 hosts).
  • /26 for office LANs (62 hosts).
  • /24 for larger subnets (254 hosts).
7. Summary of Important Points
Subnet Mask
CIDR
Host Bits
Usable Hosts
Subnets from /24
255.255.255.0 (/24) 11111111.11111111.11111111.0 = 8bits.8bits.8.bit.0bits =24bits
8. Conclusion
  • Subnetting breaks a large network into smaller subnets.
  • Subnet masks define network vs. host portions.
  • Binary calculations help determine available subnets and hosts.
  • Choosing the right subnet size ensures efficient IP allocation.
================================================
Binary to Decimal and Vice Versa in IP Subnetting
--------------------------------------------------------------------------------
In subnetting, IP addresses and subnet masks are represented in both binary and decimal. To understand how subnets work, it's crucial to know how to convert between binary and decimal representations.
1. Understanding IPv4 Address Representation
----------------------------------------------------------------------------
An IPv4 address consists of four octets (32 bits total), separated by dots. Each octet is an 8-bit binary number that can be converted to decimal.
For example, the IP address 192.168.1.1 in binary:
11000000.10101000.00000001.00000001
Similarly, subnet masks follow the same rule:
255.255.255.0 → 11111111.11111111.11111111.00000000
2. Converting Binary to Decimal in Subnetting
-------------------------------------------------------------------------
To convert a binary IP address or subnet mask to decimal, break each 8-bit octet and convert it separately.
Example 1: Convert 11000000.10101000.00000001.00000001 (Binary IP) to Decimal
Break it into four octets:
11000000 → 192
10101000 → 168
00000001 → 1
00000001 → 1
Decimal Equivalent: 192.168.1.1
Example 2: Convert 11111111.11111111.11111111.00000000 (Subnet Mask) to Decimal
11111111 → 255
11111111 → 255
11111111 → 255
00000000 → 0
Decimal Equivalent: 255.255.255.0
3. Converting Decimal to Binary in Subnetting
------------------------------------------------------------------------
To convert a decimal IP address or subnet mask to binary, convert each octet separately.
Example 3: Convert 172.16.254.1 (IP Address) to Binary
Convert each octet to 8-bit binary:
Decimal
Binary
172
10101100
16
00010000
254
11111110
1
00000001
Binary Equivalent: 10101100.00010000.11111110.00000001
Example 4: Convert 255.255.255.252 (Subnet Mask) to Binary
Decimal
Binary
255
11111111
255
11111111
255
11111111
252
11111100
Binary Equivalent: 11111111.11111111.11111111.11111100
4. Understanding CIDR Notation (/x) in Binary
-----------------------------------------------------------------------
CIDR (Classless Inter-Domain Routing) notation represents subnet masks using a slash (/) followed by the number of 1s in the mask.
Example:
  • /24 = 11111111.11111111.11111111.00000000 (255.255.255.0)
  • /30 = 11111111.11111111.11111111.11111100 (255.255.255.252)
Example 5: Convert /27 (CIDR Notation) to Decimal Subnet Mask
11111111.11111111.11111111.11100000
Breaking into decimal:
255.255.255.224
Thus, /27 = 255.255.255.224.
5. Determining Number of Hosts and Subnets Using Binary
---------------------------------------------------------------------------------------------
The number of host bits (0s) determines the number of usable hosts, and the number of borrowed bits (subnet bits) determines the number of subnets.
Formula for Hosts per Subnet:
2h−22^h - 22h−2
(where hhh = number of host bits)
Formula for Number of Subnets:
2s2^s2s
(where sss = number of subnet bits beyond the default network mask)
Example 6: Calculating Hosts for a /30 Subnet (255.255.255.252)
Binary Subnet Mask:
11111111.11111111.11111111.11111100
  • Host Bits: 2
  • Usable Hosts: 22−2=4−2=2 (Only 2 usable hosts per subnet)2^2 - 2 = 4 - 2 = 2 \text{ (Only 2 usable hosts per subnet)}22−2=4−2=2 (Only 2 usable hosts per subnet)
Example 7: Finding the Number of /27 Subnets in a /24 Network
  • /24 Mask: 255.255.255.0 → 11111111.11111111.11111111.00000000
  • /27 Mask: 255.255.255.224 → 11111111.11111111.11111111.11100000
  • Subnet Bits Borrowed: 27 - 24 = 3
  • Subnets Created: 23=8 (We now have 8 subnets instead of 1)2^3 = 8 \text{ (We now have 8 subnets instead of 1)}23=8 (We now have 8 subnets instead of 1)
6. Quick Reference Table for Subnets
----------------------------------------------------------
CIDR
Subnet Mask
Hosts per Subnet
Subnets from /24
/24
255.255.255.0
254
1
/25
255.255.255.128
126
2
/26
255.255.255.192
62
4
/27
255.255.255.224
30
8
/28
255.255.255.240
14
16
/29
255.255.255.248
6
32
/30
255.255.255.252
2
64
7. Summary
----------------------
  • Binary helps in subnetting calculations by allowing clear separation of network and host portions.
  • Subnet masks define network size, and CIDR notation simplifies representation.
  • Using binary conversions, we can determine usable hosts and subnets.
1
0 comments
Fouad Ahmed
6
Deep Dive into IP Subnetting and Subnet Masks, Binary to Decimal Conversion
CISSP Study Group
skool.com/cybersecurity-study-group
Share resources, get advice, and connect with peers studying cybersecurity. Join our CISSP study group and connect with fellow professionals today!
Leaderboard (30-day)
Powered by