🌐

IPv4 Subnet Masks

Feb 19, 2025

Classless Subnetting and CIDR

Background

  • Class-based subnetting has been replaced by classless subnetting since 1993.
  • Classless subnetting is also known as Classless Inter-Domain Routing (CIDR).

CIDR Notation

  • Allows subnet masks to be assigned that don't fit class A, B, or C.
  • Instead of decimal form, subnet masks are denoted by the number of bits, known as CIDR block notation.
    • E.g., Decimal 255.0.0.0 = /8 CIDR.
    • IP address example: 192.168.1.44/24.
    • /24 represents the number of bits in a subnet mask equivalent to 255.255.255.0.

Configuration

  • Devices require IP address, subnet mask, default gateway, DNS servers.
  • OS often uses decimal masks, while routers/switches may use CIDR notation.
    • E.g., instead of 255.0.0.0, input /8.
  • Check device documentation for preferred notation.

Subnet Mask Composition

  • Consists of contiguous series of ones (network part) followed by zeros (host part).
  • Conversion of binary subnet masks to decimal and CIDR:
    • Example: 255.255.255.0 in binary has 24 ones, equivalent to /24 CIDR.
    • Network address: 24 bits, host address: 8 bits.

Binary to CIDR Conversion

  • Example: First two octets all ones, last two all zeros = /16 CIDR.
    • Network: 16 bits, Host: 16 bits.
  • Example: Three octets all ones, last octet has two ones and six zeros = /26 CIDR.
    • Network: 26 bits, Host: 6 bits.
  • Example: First octet all ones, second octet four ones, rest zeros = /12 CIDR.
    • Network: 12 bits, Host: 20 bits.

Decimal Representation

  • Binary subnet masks can be converted to decimal:
    • All zeros = 0.
    • 1 followed by zeros = 128.
    • Two 1s = 192, three 1s = 224, etc.
    • Create a chart for conversion.

Example Conversions

  • Subnet mask: All ones in first octet, four ones in second = 255.240.0.0 in decimal, /12 in CIDR.
  • New subnet mask example: All ones first octet, three ones second octet = 255.255.224.0, /19 in CIDR.

Reverse Conversion

  • Given /26 CIDR, binary = all ones in first three octets, two ones in last.
    • Decimal: 255.255.255.192. Network: 26 bits, Host: 6 bits.
  • Given /20 CIDR, first two octets all ones, third four ones = 255.255.240.0.
    • Network: 20 bits, Host: 12 bits.