Step-by-Step Algorithm Using the “Magic Number” Method
-
Identify the subnet mask
- Convert the CIDR prefix (e.g.,
/21) to a dotted decimal subnet mask.
- Convert the CIDR prefix (e.g.,
-
Find the “Magic Number”
- Subtract the interesting octet from 256:
Magic Number = 256 − Subnet Mask in the interesting octet
- The “interesting octet” is the first non-255 octet in the subnet mask.
- Subtract the interesting octet from 256:
-
Determine the Network Address
- Find the largest multiple of the magic number less than or equal to the given IP’s value in the interesting octet.
- Keep other octets unchanged.
-
Determine the Broadcast Address
- Add (Magic Number - 1) to the network address in the interesting octet.
- Change all host bits (remaining octets) to 255.
-
Find the Valid IP Range
- First usable IP = Network Address +1
- Last usable IP = Broadcast Address -1
Example: Find the subnet details for 172.23.16.0/21
Step 1: Identify the subnet mask
- CIDR: /21
- Subnet mask: 255.255.248.0
- The interesting octet is 248 (third octet).
Step 2: Find the Magic Number
- Magic Number =
256 - 248 = 8 - This means subnet blocks are in multiples of 8 in the third octet.
Step 3: Find the Network Address
- Look at the third octet in
172.23.16.0. - The largest multiple of 8 that is ≤ 16 is 16.
- So, the network address is:
172.23.16.0
Step 4: Find the Broadcast Address
- Add (Magic Number - 1) = 8 - 1 = 7 to the third octet of the network address:
16+7=23 - The broadcast address is:
172.23.23.255 (last octet is 255 because all host bits are set to 1)
Step 5: Find the Valid IP Range
- First Usable IP: 172.23.16.1 (Network Address +1)
- Last Usable IP: 172.23.23.254 (Broadcast Address -1)
Final Answer
| Parameter | Value |
|---|---|
| Network Address | 172.23.16.0 |
| Broadcast Address | 172.23.23.255 |
| First Usable IP | 172.23.16.1 |
| Last Usable IP | 172.23.23.254 |
Summary of the Magic Number Process
- Magic Number =
256 - subnet mask in the interesting octet - Network Address:
- Largest multiple of the Magic Number ≤ given IP in the interesting octet.
- Broadcast Address:
- Network address + (Magic Number - 1), with all host bits set to 1.
- Valid Range:
- First Usable IP = Network Address +1
- Last Usable IP = Broadcast Address -1