CIDR notation writes a network as an address, a slash and the number of leading bits that are fixed: 192.0.2.0/24 fixes 24 of 32 bits, leaving 8 bits and so 256 addresses. Subtract the prefix from 32 (IPv4) or 128 (IPv6) and raise 2 to that power to get the size. Check the arithmetic with the subnet calculator.
DNSVerdict’s Subnet Calculator takes an IPv4 or IPv6 prefix in your browser and shows the network address, range, mask and address count, with no network request.
Reading a prefix
RFC 4632 §3.1 defines the notation: an address, then ”/”, then a decimal number between 0 and 32 that gives the count of significant bits, the network part. The rest are host bits. A longer prefix means a smaller network.
| Prefix | Mask | Addresses | Usable hosts (traditional) |
|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 254 |
| /26 | 255.255.255.192 | 64 | 62 |
| /28 | 255.255.255.240 | 16 | 14 |
| /30 | 255.255.255.252 | 4 | 2 |
| /31 | 255.255.255.254 | 2 | 2 (point-to-point, RFC 3021) |
| /32 | 255.255.255.255 | 1 | 1 (a single host) |
Computing network, broadcast and hosts
Take 192.0.2.100/26. The prefix leaves 32 - 26 = 6 host bits, so the block holds 2^6 = 64 addresses and starts on a multiple of 64 in the last octet.
Address 192.0.2.100
Prefix /26 (mask 255.255.255.192)
Block size 64
Network 192.0.2.64 (lowest address of the block)
Broadcast 192.0.2.127 (highest address of the block)
Hosts 192.0.2.65 - 192.0.2.126 (62 addresses)
The method: find the block size (256 minus the last non-255 mask octet, here 256 - 192 = 64), round the address down to a multiple of it for the network address, and add the size minus one for the last address. In the traditional model the first address names the network and the last is the broadcast, so usable hosts are 2^n - 2. A route or firewall rule for 192.0.2.64/26 still covers all 64 addresses.
/31 and /32
A /31 has one host bit, so the “network” and “broadcast” addresses of the traditional model would use up both addresses. RFC 3021 §2.1 says that on a point-to-point link with a 31-bit mask the two addresses “MUST be interpreted as host addresses”, and §2.2 adds that the limited broadcast address is then used for broadcast traffic. It halves the address space spent on router-to-router links. Whether a device supports /31 depends on the vendor, so check the documentation before you configure one.
A /32 is exactly one address. You see it in routing tables for a loopback or a service address, and as the default meaning of an SPF ip4: mechanism without a prefix (see below).
Private ranges and CGNAT
RFC 1918 §3 reserves three blocks for private networks:
| Block | Range | Addresses |
|---|---|---|
| 10.0.0.0/8 | 10.0.0.0 - 10.255.255.255 | 16,777,216 |
| 172.16.0.0/12 | 172.16.0.0 - 172.31.255.255 | 1,048,576 |
| 192.168.0.0/16 | 192.168.0.0 - 192.168.255.255 | 65,536 |
RFC 6598 adds a fourth block that is not RFC 1918 space: the Shared Address Space 100.64.0.0/10 (§7), reserved for carrier-grade NAT (CGN) deployment. Per RFC 6598 it is not globally routable, and it is for use between a provider’s CGN device and customer equipment. If the address your router reports as its WAN IP is in 100.64.0.0/10, your provider is doing CGNAT, and the address that websites see is a different, shared one. Compare both with What is my IP. The practical consequence is that inbound connections, port forwarding and hosting a mail server from that connection usually will not work.
IPv6 prefix sizes
IPv6 uses the same notation with 128 bits. The conventions are:
- /128 is one address, as
/32is in IPv4. RFC 6177 §1 says it is no longer recommended to give out /128s to end sites. - /64 is the subnet size. RFC 7421 describes the 64-bit interface identifier as the boundary “for almost every case”, and the IETF consensus there is that keeping the length fixed at 64 bits outweighs the arguments for change. Give each LAN a /64.
- /56 is the common home-site assignment. RFC 6177 §2 suggests “a default assignment of less than /48, such as a /56” for home users, which gives 256 /64 subnets.
- /48 is the traditional site assignment. A /48 holds 65,536 /64 subnets, and RFC 6177 §2 notes that handing one to every site “has also been widely criticized as being wasteful”. RFC 6177 §5 states that “anything of length /64 or shorter works from a standards perspective”.
A /64 has 2^64 addresses, so you do not count hosts; you plan subnets. The IPv6 tools expand, compress and inspect IPv6 addresses.
Why SPF uses CIDR
SPF lists the addresses allowed to send mail for a domain, and a sender rarely has one address. RFC 7208 §5.6 defines ip4:<network>[/<prefix>] and ip6:<network>[/<prefix>]. If the prefix is omitted, it is “taken to be /32” for ip4 and “/128” for ip6. The mechanism matches when the high-order prefix bits of the sending IP equal those of the network. The RFC does not allow shortened addresses: ip4:192.0.2 is invalid and must be written ip4:192.0.2.0/24.
v=spf1 ip4:192.0.2.64/26 ip4:203.0.113.5 ip6:2001:db8:1::/48 -all
This record authorises 64 addresses, one single address and an IPv6 /48. Two points follow from the RFC:
- Wider is not safer. Everyone in the prefix can send as you. Use the narrowest prefix that covers your servers. A /24 you do not control entirely lets other tenants of that range pass SPF.
ip4andip6cost no DNS lookups. RFC 7208 §4.6.4 says they cause no DNS queries during evaluation, so “their use is not subject to” the limit of 10. When a record is near the limit, replacing aninclude:with the provider’s published ranges can help, at the price of maintaining them yourself; too many lookups covers the trade-off.
Check a record with the SPF check, and see setting up SPF for the whole record. If a mail server must use a specific IP, find the outbound address first, for instance with What is my IP from a browser on that network, or from the Received headers of a message it sent.
FAQ
How many usable hosts are in a /24?
A /24 has 8 host bits, so 2^8 = 256 addresses. In the traditional model the first is the network address and the last the broadcast, which leaves 254 usable hosts. Routing and firewall rules still match all 256 addresses, so a rule for 192.0.2.0/24 covers the network and broadcast addresses too.
Can I use a /31 for a link between two routers? Often yes. RFC 3021 §2.1 allows two-address /31 subnets on point-to-point links, with both addresses treated as hosts. It saves half the addresses compared with a /30. Not every device or operating system supports it, so check the vendor’s documentation, and use a /30 where support is missing.
Why is the IPv6 subnet always a /64? RFC 7421 documents the 64-bit boundary between the subnet prefix and the interface identifier. The IETF consensus is that keeping it fixed outweighs the arguments for change. The RFC analyses what would break if the boundary became variable, so a LAN prefix other than /64 is a departure from the norm that you have to justify.
What prefix should I put in SPF for my mail server?
Use the narrowest prefix that covers the servers that really send: a single address as ip4:203.0.113.5 (an omitted prefix means /32, RFC 7208 §5.6), or a range you own entirely. A wide prefix lets every host in it pass SPF. The ip4 and ip6 mechanisms do not count toward the 10-lookup limit.
Sources
- RFC 4632, Classless Inter-domain Routing (CIDR) (§3.1): https://www.rfc-editor.org/rfc/rfc4632
- RFC 3021, Using 31-Bit Prefixes on IPv4 Point-to-Point Links (§2.1, §2.2): https://www.rfc-editor.org/rfc/rfc3021
- RFC 1918, Address Allocation for Private Internets (§3): https://www.rfc-editor.org/rfc/rfc1918
- RFC 6598, IANA-Reserved IPv4 Prefix for Shared Address Space (§7): https://www.rfc-editor.org/rfc/rfc6598
- RFC 6177, IPv6 Address Assignment to End Sites (§1, §2, §5): https://www.rfc-editor.org/rfc/rfc6177
- RFC 7421, Analysis of the 64-bit Boundary in IPv6 Addressing (abstract, §2): https://www.rfc-editor.org/rfc/rfc7421
- RFC 7208, Sender Policy Framework (§4.6.4, §5.6): https://www.rfc-editor.org/rfc/rfc7208
Related: SPF too many lookups, reverse DNS for mail servers, IP blacklist removal.