100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What is a Subnet Mask?

Learn what a subnet mask is, how it splits network and host bits, and how to calculate usable hosts — with interview Q&A.

easyQ124 of 224 in Computer Networks Est. time: 5 minsLast updated:
Open Code Lab

Expected Interview Answer

A subnet mask is a 32-bit value paired with an IPv4 address that tells a device which bits of the address identify the network and which bits identify the specific host, so it can determine whether a destination is on the local network or must be reached through a router.

Written in the same dotted-decimal form as an IP address (e.g., 255.255.255.0) or as a CIDR prefix length (e.g., /24), the subnet mask has contiguous 1 bits covering the network portion and contiguous 0 bits covering the host portion; a bitwise AND of the IP address and the mask yields the network address. For example, with IP 192.168.1.10 and mask 255.255.255.0 (/24), the network is 192.168.1.0 and the host portion is the final octet, giving 254 usable host addresses (256 total minus the network and broadcast addresses). When a device needs to send a packet, it applies its own subnet mask to both its own IP and the destination IP: if they land in the same network, the packet is delivered directly on the local segment (resolved via ARP); if not, the device forwards the packet to its default gateway for routing. Longer masks (like /26 or /30) create smaller subnets with fewer hosts, which is the basis of subnetting and VLSM (Variable Length Subnet Masking) for efficient address allocation.

  • Lets a device split an IP address into network and host portions
  • Determines whether a destination is local or needs a gateway
  • Enables subnetting to size networks appropriately (fewer wasted addresses)
  • Maps directly to CIDR prefix notation for concise configuration

AI Mentor Explanation

A subnet mask is like the rule that says the first two digits of a seat code identify the stand and the last two digits identify the exact seat within it — an usher applies that same rule to any ticket to instantly know whether a fan belongs in this stand or needs directing elsewhere. Applying the rule consistently is what lets an usher sort thousands of fans quickly instead of checking every seat individually. A device applying its subnet mask to an IP address works exactly the same way, splitting it into network and host portions. Getting the digit-split rule wrong would send fans to the wrong stand, just as a wrong mask misroutes packets.

Step-by-Step Explanation

  1. Step 1

    Pair mask with IP

    A subnet mask (e.g., 255.255.255.0 or /24) is assigned alongside a device's IP address.

  2. Step 2

    Bitwise AND

    The device ANDs its IP with the mask to determine its own network address.

  3. Step 3

    Compare destinations

    For any destination IP, the same mask determines if it falls in the same network (local) or a different one (remote).

  4. Step 4

    Route or deliver locally

    Local destinations are resolved via ARP and delivered directly; remote destinations are sent to the default gateway.

What Interviewer Expects

  • Correct definition: separates network bits from host bits in an IP address
  • Can convert between dotted-decimal mask and CIDR prefix notation
  • Can calculate network address, broadcast address, and usable hosts for a given mask
  • Explains how the mask decides local delivery vs default gateway routing

Common Mistakes

  • Forgetting to subtract network and broadcast addresses when counting usable hosts
  • Confusing subnet mask with a wildcard mask (used in ACLs, which is inverted)
  • Assuming all networks default to a /24 (255.255.255.0)
  • Not knowing the mask determines local-vs-gateway forwarding decisions

Best Answer (HR Friendly)

A subnet mask is like the rule that tells you which part of a street address is the neighborhood and which part is the house number — it lets a computer figure out whether another device is on the same local network or needs to be reached through a router. Without it, a device would not know whether to deliver data directly or send it out to the wider network.

Code Example

Inspecting subnet mask and computing the network address
# Show this machine’s IP address and subnet mask (Linux)
ip -4 addr show eth0
# inet 192.168.1.10/24 brd 192.168.1.255 scope global eth0

# Convert /24 to dotted-decimal and inspect network/broadcast/hosts
ipcalc 192.168.1.10/24
# Netmask:   255.255.255.0 = 24
# Network:   192.168.1.0/24
# HostMin:   192.168.1.1
# HostMax:   192.168.1.254
# Broadcast: 192.168.1.255

Follow-up Questions

  • How do you calculate the number of usable hosts from a subnet mask?
  • What is the difference between a subnet mask and a wildcard mask?
  • How does a device decide to use its default gateway based on the mask?
  • What is VLSM and why does it need variable-length masks?

MCQ Practice

1. What does a subnet mask primarily determine?

A subnet mask separates the network portion of an IP address from the host portion.

2. What is the dotted-decimal form of a /24 subnet mask?

A /24 prefix corresponds to 255.255.255.0, leaving the last octet for host addresses.

3. How many usable host addresses does a /24 subnet have?

A /24 has 256 total addresses; subtracting the network and broadcast addresses leaves 254 usable hosts.

Flash Cards

What is a subnet mask?A 32-bit value that separates the network portion of an IP address from the host portion.

/24 in dotted decimal?255.255.255.0.

How is the network address computed?By bitwise ANDing the IP address with the subnet mask.

What decides local delivery vs gateway routing?Comparing the destination IP against the local network using the subnet mask.

1 / 4

Continue Learning