What is Subnet mask?

A 32-bit value that shows how many upper bits of an IP address represent the network (the network part). Written like 255.255.255.0, which means the same as /24 in CIDR notation.

Japanese name: サブネットマスク

Subnet mask appears in 7 practice questions across 1 topic, including Computer Networking Basics.

Field: Computer Networking Basics

Network part and host part

The 32 bits of an IPv4 address are split into a network part, which identifies the network, and a host part, which identifies the device within it. A subnet mask has 1s over the network part and 0s over the host part. A bitwise AND of an IP address and its subnet mask gives the network address, which a host uses to decide whether a destination is on the same network (and can be reached directly) or must be handed to the default gateway.

Calculating how many hosts fit

With h host bits there are 2^h addresses, but the network address (host part all 0s) and the broadcast address (host part all 1s) cannot be assigned to devices, so 2^h − 2 are usable. For example, 255.255.255.192 (/26) has 6 host bits, giving 64 − 2 = 62, and 255.255.254.0 (/23) has 9 host bits, giving 512 − 2 = 510.

Relation to CIDR notation

The number of 1s in the subnet mask, written after a slash, is the prefix length in CIDR notation: 255.255.255.0 is /24 and 255.255.240.0 is /20. Because the 1s in a mask always run contiguously from the top, the prefix length alone carries the same information. IPv6 does not use the subnet mask style and writes prefix lengths, as in 2001:db8::/64.

Try it: questions about Subnet mask

A host has IP address 192.168.1.10 and subnet mask 255.255.255.0. What is the network address of the network it belongs to?

  1. A192.168.0.0
  2. B192.168.1.0
  3. C192.168.1.255
Show answer and explanation

Answer: B. 192.168.1.0

A subnet mask is a 32-bit value showing how many upper bits of an IP address represent the network (the network part): the run of 1s is the network part and the 0s are the host part. 255.255.255.0 has its upper 24 bits set, so in CIDR notation it is written "/24", as in 192.168.1.0/24. A bitwise AND of the IP address and the subnet mask clears the host part and gives the network address 192.168.1.0. 192.168.1.255, with the host part all 1s, is the broadcast address and is not assigned to hosts.

Which subnet mask is equivalent to /20 in CIDR notation?

  1. A255.255.240.0
  2. B255.255.255.240
  3. C255.255.248.0
Show answer and explanation

Answer: A. 255.255.240.0

/20 is a mask with the upper 20 bits set to 1. The first 16 bits give 255.255, and the remaining 4 bits fill the upper 4 bits of the third octet. Binary 11110000 is 128 + 64 + 32 + 16 = 240, so the subnet mask is 255.255.240.0. The host part is 12 bits, holding 2^12 − 2 = 4094 hosts. 255.255.255.240 has the upper 28 bits set (/28), and 255.255.248.0 has the upper 21 bits set (/21).

FAQ

How many hosts can a 255.255.255.0 subnet mask hold?

The host part is 8 bits, so 2^8 − 2 = 254. The network address (ending in 0) and the broadcast address (ending in 255) cannot be assigned to devices.

How do you find the network address from a subnet mask?

AND the IP address and the subnet mask bit by bit. For 192.168.10.77 with 255.255.255.224, the fourth octet becomes 77 AND 224 = 64, so the network address is 192.168.10.64.

Subnet mask in the explanations

Questions that mention Subnet mask (7)

  1. A host has IP address 192.168.1.10 and subnet mask 255.255.255.0. What is the network address of the network it belongs to?
  2. Which subnet mask is equivalent to /20 in CIDR notation?
  3. In the network 192.168.5.0/26, how many IP addresses can be assigned to hosts (end devices or router interfaces)?
  4. A host has IP address 192.168.10.77/27. What is the broadcast address of its subnet?
  5. You want to fit 500 hosts in one subnet. Of the subnets that can do this, which is the smallest (has the longest prefix)?
  6. A host (192.168.1.10/24, default gateway 192.168.1.1) sends a packet to server 203.0.113.80 on a different network. With an empty ARP cache, whose MAC address does the host look up with ARP?
  7. When a device obtains an IP address with DHCP, what is the correct order of messages?

Books on Computer Networking Basics Ad

As an Amazon Associate I earn from qualifying purchases.

Semiconductor, Electronics and Computing Calculators

Related terms

CIDR Default gateway ARP MAC address DHCP DNS (Domain Name System) CSMA/CA NAT (Network Address Translation) OSI reference model Port number

Back to the glossary