Calculate subnet masks and addresses for given CIDR notation.

CIDR notation consists of an IP address and a prefix length separated by a forward slash ("/"). The IP address represents the network, and the prefix length indicates the number of bits used for the network portion of the address.

Example CIDR Notation: 192.168.1.0/24

Here, "192.168.1.0" is the network address, and "/24" means that the first 24 bits are reserved for the network portion.

  1. Convert the CIDR prefix length to binary:
    • In our example, the prefix length is 24. Convert it to binary:
      • 24 in binary is 11111111 11111111 11111111 00000000.
  2. Determine the subnet mask:
    • The subnet mask is created by setting the first 24 bits to "1" and the remaining bits to "0".
    • Using our binary representation from step 1:
      • Subnet Mask: 11111111 11111111 11111111 00000000
      • Convert this back to decimal: 255.255.255.0
  3. Identify the number of subnets and hosts:
    • The remaining bits in the address (32 - prefix length) indicate the number of bits available for host addresses.
    • In our example: 32 - 24 = 8 bits available for hosts.
    • This allows for 2^8 (256) possible host addresses in each subnet.
  4. Calculate subnet addresses:
    • The subnet addresses can be calculated by incrementing the last octet of the network address by the number of hosts.
    • In our example:
      • Subnet 1: 192.168.1.0
      • Subnet 2: 192.168.1.1 * 256 = 192.168.2.0
      • Subnet 3: 192.168.1.2 * 256 = 192.168.3.0
      • and so on...
  5. Determine the range of usable IP addresses in each subnet:
    • The first address in the subnet is the network address, and the last address is reserved for broadcast. So, usable IP addresses are between the first and last addresses.
    • In our example, for the first subnet (192.168.1.0/24):
      • Network address: 192.168.1.0
      • Usable IP range: 192.168.1.1 to 192.168.1.254
      • Broadcast address: 192.168.1.255