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 …


This content originally appeared on DEV Community and was authored by Thomas Kanabay

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 a 0 or 1.
    • 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 nine 0's.

      11111111.11111111.11111110.00000000
      
  • Find Wildcard Bits

    • The wildcard bits are the opposite of the netmask bits.
      • Where there is a 0, replace it with a 1.
      • Where there is a 1, replace it with a 0.
      • That is 23 0's followed by nine 1's.
    • The wildcard bits can also be found by taking Number of Addresses in Range - 1 = 511 (decimal).

      00000000.00000000.00000001.11111111
      
  • 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 Address

    11000000.10101000.01100100.00001010 // 192.168.100.10
    11111111.11111111.11111110.00000000 // netmask
    ----------------------------------- // logical AND
    11000000.10101000.01100100.00000000 // network address
    192     .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 bits
      11000000.10101000.01100100.00000000 // network address
      ----------------------------------- // binary addition
      11000000.10101000.01100101.11111111 // broadcast address
      192     .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.00001010
    Netmask:   255.255.254.0 = 23    11111111.11111111.1111111 0.00000000
    Wildcard:  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.11111111
    HostMin:   192.168.100.1         11000000.10101000.0110010 0.00000001
    HostMax:   192.168.101.254       11000000.10101000.0110010 1.11111110
    Hosts/Net: 510                   (Private Internet)
    

Resources

  • http://jodies.de/ipcalc
  • 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. 
    


This content originally appeared on DEV Community and was authored by Thomas Kanabay


Print Share Comment Cite Upload Translate Updates
APA

Thomas Kanabay | Sciencx (2022-04-14T06:40:19+00:00) IPv4 CIDR Address to IP Range Using Boolean Logic and Binary Addition. Retrieved from https://www.scien.cx/2022/04/14/ipv4-cidr-address-to-ip-range-using-boolean-logic-and-binary-addition/

MLA
" » IPv4 CIDR Address to IP Range Using Boolean Logic and Binary Addition." Thomas Kanabay | Sciencx - Thursday April 14, 2022, https://www.scien.cx/2022/04/14/ipv4-cidr-address-to-ip-range-using-boolean-logic-and-binary-addition/
HARVARD
Thomas Kanabay | Sciencx Thursday April 14, 2022 » IPv4 CIDR Address to IP Range Using Boolean Logic and Binary Addition., viewed ,<https://www.scien.cx/2022/04/14/ipv4-cidr-address-to-ip-range-using-boolean-logic-and-binary-addition/>
VANCOUVER
Thomas Kanabay | Sciencx - » IPv4 CIDR Address to IP Range Using Boolean Logic and Binary Addition. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/14/ipv4-cidr-address-to-ip-range-using-boolean-logic-and-binary-addition/
CHICAGO
" » IPv4 CIDR Address to IP Range Using Boolean Logic and Binary Addition." Thomas Kanabay | Sciencx - Accessed . https://www.scien.cx/2022/04/14/ipv4-cidr-address-to-ip-range-using-boolean-logic-and-binary-addition/
IEEE
" » IPv4 CIDR Address to IP Range Using Boolean Logic and Binary Addition." Thomas Kanabay | Sciencx [Online]. Available: https://www.scien.cx/2022/04/14/ipv4-cidr-address-to-ip-range-using-boolean-logic-and-binary-addition/. [Accessed: ]
rf:citation
» IPv4 CIDR Address to IP Range Using Boolean Logic and Binary Addition | Thomas Kanabay | Sciencx | https://www.scien.cx/2022/04/14/ipv4-cidr-address-to-ip-range-using-boolean-logic-and-binary-addition/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.