What a subnet is
A subnet (subnetwork) is a slice of an IP network. An IPv4 address is 32 bits long, written as four numbers from 0 to 255, such as 192.168.1.10. Part of those 32 bits names the network and the rest names the device on it. Where the split falls is set by the subnet mask or prefix length. Devices in the same subnet can talk to each other directly. To reach another subnet they go through a router.
People subnet to keep networks a sensible size, to separate groups of machines such as servers and guest Wi-Fi, and to hand out address blocks without waste.
CIDR notation
CIDR (Classless Inter-Domain Routing) writes an address and its prefix length together, like 192.168.1.0/24. The number after the slash says how many of the first bits are the network part. In a /24, the first 24 bits are the network and the last 8 bits are for hosts. CIDR replaced the old fixed classes A, B and C. The class shown in the results above is for information only, because routing today uses the prefix, not the class.
Subnet mask and wildcard mask
The subnet mask is the same idea written as an address: ones for the network bits, zeros for the host bits. A /24 is 24 ones then 8 zeros, which is 255.255.255.0. To find the network address, a device does a bitwise AND of the IP and the mask. A valid mask is always ones followed by zeros, so 255.255.0.255 is not a real mask.
The wildcard mask is the mask flipped: zeros for the network bits, ones for the host bits. A /24 has the wildcard 0.0.0.255. Router access lists on some equipment use wildcard masks. The broadcast address is the network address with all the host bits set to one, which is the same as the network address OR the wildcard.
The formula for hosts
With prefix length p, there are 2(32 − p) addresses in the subnet. The first is the network address and the last is the broadcast address, and neither can be given to a normal host. So the usable hosts are:
usable hosts = 2^(32 - p) - 2 (for /30 and shorter) /31 = 2 usable (RFC 3021) /32 = 1 (a single host)
For a /24 that is 28 − 2 = 254 usable hosts.
Common prefixes, /8 to /32
| Prefix | Subnet mask | Total addresses | Usable hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 |
| /9 | 255.128.0.0 | 8,388,608 | 8,388,606 |
| /10 | 255.192.0.0 | 4,194,304 | 4,194,302 |
| /11 | 255.224.0.0 | 2,097,152 | 2,097,150 |
| /12 | 255.240.0.0 | 1,048,576 | 1,048,574 |
| /13 | 255.248.0.0 | 524,288 | 524,286 |
| /14 | 255.252.0.0 | 262,144 | 262,142 |
| /15 | 255.254.0.0 | 131,072 | 131,070 |
| /16 | 255.255.0.0 | 65,536 | 65,534 |
| /17 | 255.255.128.0 | 32,768 | 32,766 |
| /18 | 255.255.192.0 | 16,384 | 16,382 |
| /19 | 255.255.224.0 | 8,192 | 8,190 |
| /20 | 255.255.240.0 | 4,096 | 4,094 |
| /21 | 255.255.248.0 | 2,048 | 2,046 |
| /22 | 255.255.252.0 | 1,024 | 1,022 |
| /23 | 255.255.254.0 | 512 | 510 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
| /31 | 255.255.255.254 | 2 | 2 (RFC 3021) |
| /32 | 255.255.255.255 | 1 | 1 (single host) |
Private ranges (RFC 1918)
Three blocks are set aside for private networks and are not routed on the public internet:
10.0.0.0/8, from 10.0.0.0 to 10.255.255.255.172.16.0.0/12, from 172.16.0.0 to 172.31.255.255.192.168.0.0/16, from 192.168.0.0 to 192.168.255.255.
Home and office networks use these, and a router with NAT lets them reach the internet. Two other ranges are worth knowing. 100.64.0.0/10 is shared address space for carrier-grade NAT (RFC 6598), used by some internet providers. 169.254.0.0/16 is link-local: a device gives itself such an address when it cannot get one from a DHCP server. The tool above labels these, plus loopback (127.0.0.0/8) and multicast (224.0.0.0/4).
Why /31 and /32 are special
By the usual formula a /31 would have 2 − 2 = 0 hosts, which is useless. RFC 3021 changed that for point-to-point links, such as the link between two routers: both addresses are usable and there is no broadcast address. That saves one address per link compared with a /30. A /32 is one address on its own. It is used for a single host route, a loopback address, or to name exactly one machine in a firewall rule.
Worked example: 192.168.1.0/26
- The prefix is 26, so 6 bits are left for hosts: 26 = 64 addresses.
- The mask is 26 ones then 6 zeros:
255.255.255.192. The wildcard is0.0.0.63. - The network address is
192.168.1.0and the broadcast address is192.168.1.63. - The usable hosts run from
192.168.1.1to192.168.1.62, which is 62 hosts (64 − 2). - The next /26 starts at
192.168.1.64, and then.128and.192. A /24 splits into four /26 subnets. Try it with the split tool above.
Subnets and your server's IP
If you run a server, you meet subnets when you set a firewall rule, a private network or a route. Every RapidServer VPS comes with its own Indian IPv4 address, plus an IPv6 /64, and plans start at ₹581/mo plus 18% GST. Read why a business wants a dedicated IP, or what an IP address is in Hinglish. More free tools are on the calculators page.
Every VPS gets a dedicated IPv4 address, in our Mumbai or Delhi data center.
See VPS plans