An Interest In:
Web News this Week
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
IPv4 CIDR Address to IP Range Using Boolean Logic and Binary Addition
Given an IPv4 address in CIDR notation (e.g. 192.168.100.10/23
), we can find the IP range using boolean logic and binary addition.
Procedure
IPv4 Address in CIDR Notation
192.168.100.10/23
Find Number of Addresses in Range
- There are 32 bits in an IPv4 address.
- We know the netmask is 23 bits. Therefore, the address space is
32-23 = 9
bits. - Each of those
9
bits can be a0
or1
. We find the total number of addresses in the space with the power function.
base = 2
power = 9
2^9 = 512 addresses (including network and broadcast)
We subtract
2
to find the number of available addresses, since the network and broadcast addresses are reserved.512 - 2 = 510 addresses (network and broadcast excluded)
Find Netmask Bits
- We were given the netmask as
23
bits. That is 23
1
's followed by nine0
's.11111111.11111111.11111110.00000000
- We were given the netmask as
Find Wildcard Bits
- The wildcard bits are the opposite of the netmask bits.
- Where there is a
0
, replace it with a1
. - Where there is a
1
, replace it with a0
. - That is 23
0
's followed by nine1
's.
- Where there is a
The wildcard bits can also be found by taking
Total Addresses in Range - 1 = 511 (decimal)
.00000000.00000000.00000001.11111111
- The wildcard bits are the opposite of the netmask bits.
Convert IPv4 Address to Binary
We take each decimal octet and convert it to binary.
192 (decimal) = 11000000 (binary)168 (decimal) = 10101000 (binary)100 (decimal) = 01100100 (binary) 10 (decimal) = 00001010 (binary)11000000.10101000.01100100.00001010
Logical
AND
the IP Address with the Netmask to find the Network Address11000000.10101000.01100100.00001010 // 192.168.100.1011111111.11111111.11111110.00000000 // netmask----------------------------------- // logical AND11000000.10101000.01100100.00000000 // network address192 .168 .100 .0 // back to decimal
Find the Broadcast Address
We use binary addition to add the network address to the wildcard bits.
00000000.00000000.00000001.11111111 // wildcard bits11000000.10101000.01100100.00000000 // network address----------------------------------- // binary addition11000000.10101000.01100101.11111111 // broadcast address192 .168 .101 .255 // back to decimal
Range
192.168.100.0 // network addr
192.168.100.1 // first avail ip
192.168.101.254 // last avail ip
192.168.101.255 // broadcast addr
Confirmation
Using the IPv4 Calculator link from the Resources section below, we can check that we applied the procedure properly.
Address: 192.168.100.10 11000000.10101000.0110010 0.00001010Netmask: 255.255.254.0 = 23 11111111.11111111.1111111 0.00000000Wildcard: 0.0.1.255 00000000.00000000.0000000 1.11111111=>Network: 192.168.100.0/23 11000000.10101000.0110010 0.00000000 (Class C)Broadcast: 192.168.101.255 11000000.10101000.0110010 1.11111111HostMin: 192.168.100.1 11000000.10101000.0110010 0.00000001HostMax: 192.168.101.254 11000000.10101000.0110010 1.11111110Hosts/Net: 510 (Private Internet)
Resources
IPv4 Calculator
Books
I found the IPv4 Calculator link in IPv4 Subnetting section of the Unix and Linux System Administration Handbook.
Nemeth, Evi, et al. Unix and Linux System Administration Handbook. 5th ed., Pearson Education, Inc., 2018.
Original Link: https://dev.to/thomaskcode/ipv4-cidr-address-to-ip-range-using-boolean-logic-and-binary-addition-25bf
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To