Help
QueryExplanation
24 CIDR
255.255.255.192 Mask
192.168.1.1 255.255.0.0 IP & mask
192.168.1.1/30 IP & CIDR
128.42.5.17 ~ 128.42.5.18 Find the max mask for 2 IPs
192.168.1.0/26 1,7,29,2,6 VLSM (divide a network into subnets)
128.42.3.20 in 128.42.3.17/29 Check if an IP belongs to a network
Special-purpose IP attributes
  • S - (source) an address is valid when used as the source address of an IP datagram that transits 2 devices.
  • D - (destination) an address is valid when used as the destination address of an IP datagram that transits 2 devices.
  • F - (forwardable) a router may forward an IP datagram whose destination address is drawn from this allocated block between external interfaces.
  • G - (global) an IP datagram whose destination address is drawn from this address block is forwardable beyond a specified administrative domain.
CIDR Host bits Subnet mask Addresses in subnet
/32 0 255.255.255.255 1 = 20
/31 1 255.255.255.254 2 = 21
/30 2 255.255.255.252 4 = 22
/29 3 255.255.255.248 8 = 23
/28 4 255.255.255.240 16 = 24
/27 5 255.255.255.224 32 = 25
/26 6 255.255.255.192 64 = 26
/25 7 255.255.255.128 128 = 27
/24 8 255.255.255.  0 256 = 28
/23 9 255.255.254.  0 512 = 29
/22 10 255.255.252.  0 1024 = 210
/21 11 255.255.248.  0 2048 = 211
/20 12 255.255.240.  0 4096 = 212
/19 13 255.255.224.  0 8192 = 213
/18 14 255.255.192.  0 16384 = 214
/17 15 255.255.128.  0 32768 = 215
/16 16 255.255.  0.  0 65536 = 216
/15 17 255.254.  0.  0 131072 = 217
/14 18 255.252.  0.  0 262144 = 218
/13 19 255.248.  0.  0 524288 = 219
/12 20 255.240.  0.  0 1048576 = 220
/11 21 255.224.  0.  0 2097152 = 221
/10 22 255.192.  0.  0 4194304 = 222
/9 23 255.128.  0.  0 8388608 = 223
/8 24 255.  0.  0.  0 16777216 = 224
def cidr host_bits
  32 - host_bits
end

def subnet_mask cidr
  '%3d.%3d.%3d.%3d' %
    1.upto(32).map {|bit| bit <= cidr ? 1 : 0 }
    .each_slice(8)
    .map {|val| val.join.to_i 2 }.to_a
end

def subnet_addr host_bits
  2**host_bits
end

rows = 0.upto(24).map do |idx|
  ["/#{cidr idx}", idx, subnet_mask(cidr idx), subnet_addr(idx)]
end

https://github.com/gromnitsky/cidr.rb