Skip to main content
Beginnerconceptual

What is a subnet mask, and how is it used to find the network and host parts of an IP address?

ReportedSource: GeeksforGeeks interview experience: TCS Ninja

Quick answer

A 32-bit mask whose 1-bits mark the network portion; IP AND mask = network address. /24 = 255.255.255.0 gives 254 usable hosts; borrowing bits (e.g. /26) creates smaller subnets.

Definition. A subnet mask is a 32-bit value (for IPv4) that marks which bits of an IP address are the network part (1s) and which are the host part (0s). Written as dotted decimal (255.255.255.0) or CIDR prefix length (/24).

Network address. Bitwise AND of IP and mask.

  • IP 192.168.10.37, mask 255.255.255.0 (/24)
  • Network: 192.168.10.0; broadcast: 192.168.10.255; usable hosts: .1 to .254 (2^8 - 2 = 254).

Subnetting example. Splitting 192.168.10.0/24 into four subnets borrows 2 host bits: /26 (mask 255.255.255.192), each with 64 addresses (62 usable): .0, .64, .128, .192.

Why it matters. Hosts use the mask to decide if a destination is on the local network (deliver directly) or remote (send to the default gateway). Subnetting reduces broadcast traffic and organises address space.

Discussion