LogicGates.org Open the simulatorSimulator

Subnet calculator

Type an IPv4 address with its prefix or mask to get the network and broadcast address, the usable host range and every mask, with the AND that finds the network shown bit by bit.

Any of 192.168.1.10/24, 192.168.1.10 255.255.255.0 or 192.168.1.10 24.

/24 255.255.255.0
Network 192.168.1.0/24 254 usable hosts, 192.168.1.1 to 192.168.1.254, broadcast 192.168.1.255.
Network address
192.168.1.0
Broadcast address
192.168.1.255
First usable host
192.168.1.1
Last usable host
192.168.1.254
Usable hosts
254
Total addresses
256
Netmask
255.255.255.0
Wildcard mask
0.0.0.255
Prefix length
/24
Binary mask
11111111.11111111.11111111.00000000
Class (historic)
C (default /24)
Address type
Private, 192.168.0.0/16 (RFC 1918)

Working: the network address is an AND

Each bit of the mask is 1 over the network part and 0 over the host part. ANDing keeps the network bits of the address and clears the host bits, so what is left is the network address.

Address 192.168.1.10
AND Mask 255.255.255.0
= Network 192.168.1.0

Setting every host bit to 1 instead gives the last address of the block: the network OR the wildcard mask, which is the mask with each bit flipped.

Network 192.168.1.0
OR Wildcard 0.0.0.255
= Broadcast 192.168.1.255

Solid bracket: network bits. Dashed bracket, tinted: host bits. Bold digits are 1s. Check this AND in the binary calculator.

Is another address in this subnet?

No: 192.168.2.10 is not in 192.168.1.0/24. ANDed with the mask it gives 192.168.2.0, which differs from 192.168.1.0 in 2 network bits, underlined.

Check 192.168.2.10
AND Mask 255.255.255.0
= Result 192.168.2.0
≠ Network 192.168.1.0

How a subnet mask works

An IPv4 address is 32 bits, written as four 8-bit octets in decimal. A subnet splits those bits in two: the leading bits say which network the address is on, and the rest say which host on that network it is. The prefix length, the /24 in 192.168.1.10/24, is where the split falls. The mask writes the same split as an address: a 1 for every network bit and a 0 for every host bit, so /24 is 255.255.255.0.

  • Network address. The address AND the mask: host bits all 0. It names the subnet and is the first address in it.
  • Broadcast address. The network OR the wildcard mask: host bits all 1. A packet sent there reaches every host on the subnet. It is the last address.
  • Usable hosts. Everything in between. A block of 2n addresses, where n is the number of host bits, has 2n − 2 usable ones.
  • Same subnet or not. Two addresses are on the same subnet when both give the same result ANDed with the mask. A computer does this check for every packet it sends, to decide between delivering it directly and handing it to the router.

The AND, OR and NOT here are the same operations as the logic gates, applied to 32 bits at once. To see the bits of any number, use the binary converter.

Worked examples

Without converting everything to binary: find the octet where the mask stops being 255, and the block size is 256 minus that mask octet. The network is the multiple of the block size at or below the address's octet.

172.16.45.14/20

Mask 255.255.240.0. Octet 3 of the mask is 240, so the block size is 256 − 240 = 16.

Octet 3 of the address is 45. The block that holds it runs from 32 to 47.

Network   172.16.[32].0
Broadcast 172.16.[47].255
First     172.16.32.1
Last      172.16.47.254
Usable    4,094

Try it

192.168.10.77/27

Mask 255.255.255.224. Octet 4 of the mask is 224, so the block size is 256 − 224 = 32.

Octet 4 of the address is 77. The block that holds it runs from 64 to 95.

Network   192.168.10.[64]
Broadcast 192.168.10.[95]
First     192.168.10.65
Last      192.168.10.94
Usable    30

Try it

10.10.10.130/26

Mask 255.255.255.192. Octet 4 of the mask is 192, so the block size is 256 − 192 = 64.

Octet 4 of the address is 130. The block that holds it runs from 128 to 191.

Network   10.10.10.[128]
Broadcast 10.10.10.[191]
First     10.10.10.129
Last      10.10.10.190
Usable    62

Try it

/31 and /32: the two exceptions

A /30 has 4 addresses and 2 usable ones, which is exactly enough for a link between two routers but spends half its addresses on a network and a broadcast address that a two-ended link never needs. RFC 3021 lets a /31 be used for such a link instead: its 2 addresses are both hosts, there is no broadcast address, and the link takes half the space. Most router software accepts /31 links; a host operating system may not, so they are for router-to-router links.

A /32 is one address on its own. It is used for a route to a single host, a router's loopback address, or an access list entry that matches one machine. It has no network or broadcast address, so its one address is the host.

Subnet mask table: /0 to /32

Every prefix length with its netmask, wildcard mask and size. Each step down the table halves the block.

Prefix Netmask Wildcard Addresses Usable hosts Compared with a /24
/0 0.0.0.0 255.255.255.255 4,294,967,296 4,294,967,294 16,777,216 × /24
/1 128.0.0.0 127.255.255.255 2,147,483,648 2,147,483,646 8,388,608 × /24
/2 192.0.0.0 63.255.255.255 1,073,741,824 1,073,741,822 4,194,304 × /24
/3 224.0.0.0 31.255.255.255 536,870,912 536,870,910 2,097,152 × /24
/4 240.0.0.0 15.255.255.255 268,435,456 268,435,454 1,048,576 × /24
/5 248.0.0.0 7.255.255.255 134,217,728 134,217,726 524,288 × /24
/6 252.0.0.0 3.255.255.255 67,108,864 67,108,862 262,144 × /24
/7 254.0.0.0 1.255.255.255 33,554,432 33,554,430 131,072 × /24
/8 255.0.0.0 0.255.255.255 16,777,216 16,777,214 65,536 × /24
/9 255.128.0.0 0.127.255.255 8,388,608 8,388,606 32,768 × /24
/10 255.192.0.0 0.63.255.255 4,194,304 4,194,302 16,384 × /24
/11 255.224.0.0 0.31.255.255 2,097,152 2,097,150 8,192 × /24
/12 255.240.0.0 0.15.255.255 1,048,576 1,048,574 4,096 × /24
/13 255.248.0.0 0.7.255.255 524,288 524,286 2,048 × /24
/14 255.252.0.0 0.3.255.255 262,144 262,142 1,024 × /24
/15 255.254.0.0 0.1.255.255 131,072 131,070 512 × /24
/16 255.255.0.0 0.0.255.255 65,536 65,534 256 × /24
/17 255.255.128.0 0.0.127.255 32,768 32,766 128 × /24
/18 255.255.192.0 0.0.63.255 16,384 16,382 64 × /24
/19 255.255.224.0 0.0.31.255 8,192 8,190 32 × /24
/20 255.255.240.0 0.0.15.255 4,096 4,094 16 × /24
/21 255.255.248.0 0.0.7.255 2,048 2,046 8 × /24
/22 255.255.252.0 0.0.3.255 1,024 1,022 4 × /24
/23 255.255.254.0 0.0.1.255 512 510 2 × /24
/24 255.255.255.0 0.0.0.255 256 254 1 × /24
/25 255.255.255.128 0.0.0.127 128 126 1/2 of a /24
/26 255.255.255.192 0.0.0.63 64 62 1/4 of a /24
/27 255.255.255.224 0.0.0.31 32 30 1/8 of a /24
/28 255.255.255.240 0.0.0.15 16 14 1/16 of a /24
/29 255.255.255.248 0.0.0.7 8 6 1/32 of a /24
/30 255.255.255.252 0.0.0.3 4 2 1/64 of a /24
/31 255.255.255.254 0.0.0.1 2 2 1/128 of a /24
/32 255.255.255.255 0.0.0.0 1 1 1/256 of a /24

The row for the subnet in the calculator is marked. /31 and /32 count every address as usable, for the reasons above.

Special-use IPv4 ranges

Some ranges are set aside and never appear as ordinary public addresses. The calculator names the range an address falls in.

Range Use Defined in Notes
0.0.0.0/8 "This network"RFC 791, RFC 1122. Only valid as a source while a host learns its address. RFC 791, RFC 1122 Only valid as a source while a host learns its address.
10.0.0.0/8 PrivateRFC 1918. For use inside an organisation; not routed on the internet. RFC 1918 For use inside an organisation; not routed on the internet.
100.64.0.0/10 Shared address space (CGNAT)RFC 6598. Between a carrier-grade NAT and its customers. RFC 6598 Between a carrier-grade NAT and its customers.
127.0.0.0/8 LoopbackRFC 1122. Never leaves the host; 127.0.0.1 is the usual one. RFC 1122 Never leaves the host; 127.0.0.1 is the usual one.
169.254.0.0/16 Link-localRFC 3927. Self-assigned when no DHCP server answers; not forwarded by routers. RFC 3927 Self-assigned when no DHCP server answers; not forwarded by routers.
172.16.0.0/12 PrivateRFC 1918. 172.16.0.0 to 172.31.255.255. RFC 1918 172.16.0.0 to 172.31.255.255.
192.0.0.0/24 IETF protocol assignmentsRFC 6890. Reserved for specific protocols. RFC 6890 Reserved for specific protocols.
192.0.2.0/24 Documentation (TEST-NET-1)RFC 5737. For examples in documents; never on a real network. RFC 5737 For examples in documents; never on a real network.
192.168.0.0/16 PrivateRFC 1918. The usual home and office LAN range. RFC 1918 The usual home and office LAN range.
198.18.0.0/15 BenchmarkingRFC 2544. For testing network equipment. RFC 2544 For testing network equipment.
198.51.100.0/24 Documentation (TEST-NET-2)RFC 5737. For examples in documents; never on a real network. RFC 5737 For examples in documents; never on a real network.
203.0.113.0/24 Documentation (TEST-NET-3)RFC 5737. For examples in documents; never on a real network. RFC 5737 For examples in documents; never on a real network.
224.0.0.0/4 MulticastRFC 5771. One sender, many receivers; the old class D. RFC 5771 One sender, many receivers; the old class D.
240.0.0.0/4 ReservedRFC 1112. The old class E, set aside for future use. RFC 1112 The old class E, set aside for future use.
255.255.255.255/32 Limited broadcastRFC 919. Every host on the local link; never forwarded. RFC 919 Every host on the local link; never forwarded.

Address classes, for history

Before 1993 the first bits of an address fixed its network size. Classless routing (CIDR) replaced the scheme, so a class says nothing about a real network today, but the letters still turn up in courses and exams.

Class Leading bits Range Default mask Use
A 0 0.0.0.0 to 127.255.255.255 /8 Large networks
B 10 128.0.0.0 to 191.255.255.255 /16 Medium networks
C 110 192.0.0.0 to 223.255.255.255 /24 Small networks
D 1110 224.0.0.0 to 239.255.255.255 none Multicast
E 1111 240.0.0.0 to 255.255.255.255 none Reserved

Common mistakes

  • Giving a host the network or broadcast address. In 192.168.1.0/24, .0 and .255 are taken; the hosts are .1 to .254.
  • Assuming a mask from the first octet. 10.1.2.3 is not automatically a /8. The prefix is whatever the network was configured with, which is why this calculator asks for it.
  • Mixing up the netmask and the wildcard. 0.0.0.255 in an access list means the same block as 255.255.255.0 on an interface. Typing one where the other belongs matches the wrong addresses.
  • Counting hosts as 2n. A /26 has 64 addresses but 62 hosts. Need 64 hosts and you need a /25. The VLSM calculator picks the right size for each subnet in a plan.
  • Leading zeros. Some software reads 010 as octal 8, so 192.168.010.1 can mean 192.168.8.1. Write octets without leading zeros.

Questions

What does /24 mean?

It is the prefix length: the first 24 of the address's 32 bits name the network and the remaining 8 name a host on it. Written as a mask that is 255.255.255.0. A /24 holds 256 addresses, of which 254 can be given to hosts, so 192.168.1.10/24 is on the network 192.168.1.0.

How do you work out the network address?

AND the address with the mask, bit by bit: a 1 in the mask keeps the address bit, a 0 clears it. For 192.168.1.10/27 the mask is 255.255.255.224 and the result is 192.168.1.0. The broadcast address is the network with every host bit set to 1, here 192.168.1.31.

Why are two addresses in a subnet not usable?

The first address, with every host bit 0, is the network address, which names the subnet itself. The last, with every host bit 1, is the broadcast address, which reaches every host on it. Neither can belong to one host, so a subnet of n addresses has n − 2 usable ones.

Can you use a /31?

Yes, on a point-to-point link. A /31 has 2 addresses, and taking away a network and a broadcast address would leave none, so RFC 3021 lets both be used as host addresses on a link between two routers, for example 10.0.0.0 and 10.0.0.1. It saves half the addresses a /30 would use for the same link.

How can I tell if two addresses are on the same subnet?

AND each with the mask and compare. With a /24, 192.168.1.10 gives 192.168.1.0 and 192.168.1.200 gives 192.168.1.0, the same, so they are on one subnet; 192.168.2.10 gives 192.168.2.0 and is not. The check in the calculator above does exactly this.

What is a wildcard mask?

The netmask with every bit flipped: 0.0.0.255 for 255.255.255.0. Cisco access lists and OSPF network statements use it, where a 0 bit means "must match" and a 1 means "any value". It is also the number of addresses in the block minus one.

Are address classes still used?

Not for routing. Classes A, B and C fixed the network size by the first bits of the address, which wasted addresses, and classless routing (CIDR) replaced them in 1993. The terms survive in textbooks and in some defaults, which is why this calculator still shows the historic class.