Friday, September 28, 2012

CIDR notation

This might help you understand CIDR notation.

IPv4 version:

IP / Bit Mask - 0.0.0.0/32

IP / Bit Mask represents a pool of IP addresses.

Bit mask is a number from  0 to 32

example: 192.168.1.1 / 32

Think IP as a string of thirty two 1s or 0s, eight bits in each section.

1111 1111.1111 1111.1111 1111.1111 1111 (255.255.255.255)

so 10.0.0.1 / 32 could be seen as
0000 1010.0000 0000.0000 0000.0000 0001 / 32
(I put a space between every 4 bit just to make it easier to read)

bit mask means the number of bits must match to this 32 bits representation of the IP.

so /32 here means all IP addresses in this pool must match all 32 bits of this IP 
i.e. 10.0.0.1/32 represents one ip address: 10.0.0.1

10.0.0.1/31 means only first 31 bits must match/be same. The last bit is free to be anything. 
00001010.00000000.00000000.0000000 1
00001010.00000000.00000000.0000000 0

so the IP pool represented by 10.0.0.1/31 contains two IPs. 10.0.0.0 and 10.0.0.1

another example: 

10.0.0.1/24 requires the first 24 bits match 10.0.0.1 so leave last 8 bits free which creates a pool of 256 IP address (28 IP) i.e. 10.0.0.0 ~ 10.0.0.255

example from Wikipedia:





References:

http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
http://en.wikipedia.org/wiki/IPv4_subnetting_reference

No comments:

Post a Comment