home       basis       routing       switching       advanced       security       overig       testen       english      

IPv4 Netmask

Purpose of the Netmask ...

A telephone number contains an area code and a subscriber number:
example: WZNV-customer-service -- (02) 6371108
where in the above example the (02) is the area code for Brussels
and the 6371108 is the subscribernumber (this number does not exist)
 
In the same way, an IP address is split into a network prefix also called network identifier
or just short: net-ID or net-prefix, and a host identifier, short: host‑ID.
Some literature also uses the terms network number and host number.

The division of an IP address into a net‑ID and a host‑ID depends on the size of the network,
every IP address is always accompanied by its netmask: indicating the network-size.

Consider the example below:

ipv4-addr_n_mask

ip addr decimal notation:     192 168 11 201
netmask decimal notation:  255 255 255 0
netmask slash notation: /24 (there are indeed 24 'one' bits and 8 'zero' bits)
the ONEs are always on the left side, the ZEROes are always on the right

boolean algebra:

1 = true
0 = false
1 & 1 => 1  
1 & 0 => 0  
0 & 1 => 0  
0 & 0 => 0
 
true and true = true
true and false = false
false and true = false
false and false = false

 
How to Split an ipv4-address into Net‑ID and Host‑ID , using the Netmask
 
Suppose we have the following address: 192.168.11.201 netmask 255.255.255.0

  • The part where the netmask is binary 1 becomes the net‑ID.
  • The part where the netmask is binary 0 becomes the host‑ID.

See the figure above ...
 

Net‑ID = NET-prefix

 
To find the Net‑ID:

  • Take the binary portion that is fixed by the network.
  • Fill the remaining bits on the right with zeros.
  • Convert the result back to decimal.
     
    The NET-id is the first (unused) possible address inside a given network.
    Every net‑ID must always include the netmask;
    otherwise, the size of the network is still unknown.
     
    In our example, the net‑ID is:
    192.168.11.0 mask 255.255.255.0
    [ In practice, the host‑ID is almost never calculated.
    In our example it would be 0.0.0.201.]
     
    CIDR (“Slash”) Notation
    If we write 255.255.255.0 in binary, we get:
    11111111 11111111 11111111 00000000
    This contains 24 ones.
    The slash notation is simply the number of binary ones in the netmask, preceded by a slash.
     
    For 255.255.255.0, this is /24
     
    Our example address + netmask can therefore also be written as:
    192.168.11.201/24
    Officially, this is called CIDR notation.

Broadcast Address

The very last address in a network is used to broadcast within that network.
The NET-BC is the last (unused) possible address inside a given network.
 
To find the broadcast address:

  • Take the binary portion fixed by the network.
  • Fill the remaining bits on the right with "ones".
  • Convert the result back to decimal.
    In 192.168.11.0/24, the broadcast address is: 192.168.11.255

Number of Hosts in a Network

In an IP network:
  • The first IP address is always the net‑prefix.
  • The last IP address is always the broadcast address.
To determine the number of IP addresses in a network:
  • Count the number of zeros in the netmask — this is your exponent.
  • The number of IP addresses is then 2^{number\ of\ zeros}}.
In our example:
  • There are 24 ones, so 8 zeros.
  • The number of IP addresses is 2^8 = 2 x 2 x 2 x 2 x 2 x 2 x 2 x 2 = 256

The number of usable IP addresses for hosts is in this case: 256 − 2 = 254
(because the net-ID and the net-BC cannot be used for hosts)