Subnetting - rFronteddu/general_wiki GitHub Wiki

For subnet 255.255.255.0 you have 256-2=254 addresses, the -2 comes from

  • .0 is the network address
  • .255 is the broadcast address

Simple int to binary mapping

Consider

2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
2^7 = 128
2^8 = 256

Each byte is 8 bits...

1   1  1  1  1 1 1 1
128 64 32 16 8 4 2 1

Consider 192:

  • Can you subtract 128? => 1 0 0 0 0 0 0 0
  • 192-128 = 64. Can you subtract 64? => 1 1 0 0 0 0 0 0

CIDR (Classless Inter-Domain Routing)

A subnet like 10.42.3.0 with a subnet mask of 255.255.255.0 is written as 10.42.3.0/24. This single notation includes both the network address and the prefix length.

The number after the slash indicates how many bits of the IP address are used for the network prefix.

Consider 123.12.24.0/23. This means the first 23 bits are the network prefix. To find the number of available hosts:

  • Subtract CIDR prefix from total bits (32): 32 - 23 = 9. This leaves 9 bits for the host portion.
  • Calculate total number of addresses in the subnet: 2^9 = 512.
  • Subtract 2 from total (one address for the network addr, one for the broadcast) => 512 - 2 = 510 usable host addresses.

Consider a /30 network, which provides 32 - 30 = 2 host bits. This results in 2^2 = 4 total addresses, leaving 2 usable addresses (often used for point to point links).