Techie Talks

Thursday, March 09, 2006

Translate BitMask to NetMask for class C networks

Given a network address in the form of IPAddress/Bitmask, how would one get the netmask (or subnetmask) and the number of IP addresses available? This question cropped up when I was told that our company has been assigned a /29 ip address by NTS.

Note: In a 32-bit IP address, the number of bits used to identify the network and the host vary according to the network class of the address. In a Class C network, the first 3 bits, or the high-order bits, are always "110." The next 21 bits are used to define the Class C network, and the final eight bits are used to identify the host. The IP address is represented in dotted decimal notation of four 8-bit fields, or octets, that have been converted from binary to decimal numbers. (Source: http://www.webopedia.com/TERM/C/Class_C_network.html)

Answer: Every IP address of the form XYZ.XYZ.XYZ.XYZ (where 0 <= XYZ <= 255) can be represented by 32bits (4 bytes, 1 byte per group). If the bitmask of the class C network is /BM and the starting IP is ABC.DEF.GHI.JKL, then, Number of computers in the subnet (NC)= 2^(32-BM). IP Range = ABC.DEF.GHI.JKL to ABC.DEF.GHI.JKL + 2^NC - 1
Subnet mask = A binary string with all but the (32-BM) lower order bits as zero. (in the four octect form).

Example: A 215.179.162.224 /29 subnet has
2^ (32 - 29) = 2 ^ 3 = 8 Ip address
IP adresses range: from 215.179.162.224 to 215.179.162.231
Subnet mask: (1111 1111)2.(1111 1111)2.(1111 1111)2.(1111 1000)2 = 255.255.255.248

0 Comments:

Post a Comment

<< Home