I would like read netmask, network and broadcast address from an IP address. Basically I’m confused with netmask, CIDR, network and Broadcat terms, could anyone please help me to understand these terms.
Thanks, Thomman
There is no intrinsic netmask, network and broadcast address for a given IP address. The three terms, combined with an IP address describe a network
.
The (CIDR) netmask gives the number of bits that all IPs in the network share. For example, /15
means the first 15 bits are fixed. Because an IPv4 address has 32 bits, the next 32-15=17 bits are then variable. Since every number in an IPv4 address corresponds to 8 bits, that means the following addresses are in the network 1.2.0.0/15 (binary: 00000001.00000010.0.0/15
):
1.2.0.1
1.2.0.2
1.2.0.255
1.2.1.2
1.2.255.255
1.3.1.1 # in binary: 00000001.00000011.0.0, i.e. the first 15 bits match
1.3.255.255
but not 1.4.1.1 (00000001.00000100.1.1)
or 2.2.1.1 (00000010.10.1.1)
, since their first 15 bits differ from 00000001.0000001
.
You can also express the netmask of a /x CIDR network in binary form by setting the first x bits. In our case, the first 15:
11111111.11111110.00000000.00000000 # binary
255. 254. 0. 0 # decimal
A network address is then the logical AND of any address in the network and the network mask, you set all the variable bits to zero. You can also think of it as the lowest address in the network. In our case: 1.2.0.0
.
A broadcast address is the logical OR with the complement of the netmask. You set all the variable bits to one. You can also think of it as the highest address in the network. In our case: 1.3.255.255
.
This terminology is equivalent for IPv6 addresses, although you'll usually specify only address and CIDR netmask. Also, a block between two colons now describes 16, not 8 bit. For example, 0001:0002:abcd::/48
contains 0001:0002:abcd::1
and 0001:0002:abcd:12::
, but not 0001:0002:abce
. You could express the netmask of this network as ffff:ffff:ffff:0
or even 1111111111111111:1111111111111111:1111111111111111::0
, but /48
is shorter and easier to read. This network has 48 fixed and 128-48=80 variable bits.