Usable hosts
Take the number of addresses and remove two: the network address and the broadcast address. A /27 has 32 addresses and 30 usable hosts.
Every route, firewall rule and design I write depends on getting Internet Protocol (IP) addresses right. This page covers binary, masks and Classless Inter Domain Routing (CIDR), a complete mask table, a calculator that shows its working, and IPv6, with animated worked examples you can step through.
Subnetting stops being hard once the binary is clear. Every mask, range and summary on this page comes from the same idea: some bits name the network and the rest name the host.
Swipe sideways to see the whole diagram.
Each bit in an octet has a value, doubling from right to left: 1, 2, 4 and so on up to 128. To read an octet, I add up the values of the bits that are 1. Here 128 + 64 makes 192.
The same method gives 168: 128 + 32 + 8. With eight bits, one octet can hold any value from 0 to 255.
An IPv4 address is 32 bits, written as four octets in decimal with dots between them. 192.168.10.77 is really one 32 bit number.
The mask marks which bits are the network and which are the host. A /24 mask has 24 ones, so 192.168.10 is the network and 77 is the host.
Click a bit to switch it on or off, or type a number from 0 to 255.
IPv4 addresses are not all equal. Some ranges are private, some are reserved for documentation or loopback, and some tell me straight away that something has gone wrong.
Swipe sideways to see the whole diagram.
Classes. The first bits of an address used to fix its class and its mask. Class A started with a 0 bit, B with 10, C with 110, D (multicast) with 1110 and E (reserved) with 1111. Since CIDR, any mask can go with any address, but the Routing Information Protocol (RIP) version 1 still behaves classfully, which is why the history matters.
Special ranges. Some blocks never appear on the public internet. Seeing one tells me something at once: 169.254 means a client never reached a Dynamic Host Configuration Protocol (DHCP) server, 100.64 means carrier grade network address translation (NAT), and 127 is the host talking to itself.
| Range | Purpose | What it tells me |
|---|---|---|
| 10.0.0.0/8 | Private, from Request for Comments (RFC) 1918 | Inside an organisation. Large estates and data centres use it most. |
| 172.16.0.0/12 | Private (RFC 1918) | Covers 172.16 to 172.31, not the whole of 172. |
| 192.168.0.0/16 | Private (RFC 1918) | Homes and small sites. Clashes often appear after mergers and virtual private network (VPN) links. |
| 100.64.0.0/10 | Shared address space (RFC 6598) | Carrier grade NAT. VMware NSX also uses it inside its gateways by default. |
| 127.0.0.0/8 | Loopback | The host talking to itself. |
| 0.0.0.0/8 | This network | Only valid as a source, for example a DHCP Discover. |
| 169.254.0.0/16 | Link local (Automatic Private IP Addressing, APIPA) | The client asked for DHCP and nobody answered. |
| 224.0.0.0/4 | Multicast | 224.0.0.0/24 is link local and never routed, for Open Shortest Path First (OSPF), the Hot Standby Router Protocol (HSRP) and similar. |
| 240.0.0.0/4 | Reserved | Not used on networks. |
| 198.18.0.0/15 | Benchmark testing (RFC 2544) | Lab and test traffic. |
| 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 | Documentation (RFC 5737) | Safe for examples, like the ones on this site. |
This is the table I use most. The highlighted rows are the common ones: /8, /16 and /24 for plans and summaries, /25 to /29 for real subnets, /30 and /31 for links, and /32 for loopbacks.
| Prefix | Mask | Wildcard | Addresses | Usable hosts | Block size |
|---|---|---|---|---|---|
| /0 | 0.0.0.0 | 255.255.255.255 | 4,294,967,296 | the default route | whole address space |
| /1 | 128.0.0.0 | 127.255.255.255 | 2,147,483,648 | 2,147,483,646 | 128 in the 1st octet |
| /2 | 192.0.0.0 | 63.255.255.255 | 1,073,741,824 | 1,073,741,822 | 64 in the 1st octet |
| /3 | 224.0.0.0 | 31.255.255.255 | 536,870,912 | 536,870,910 | 32 in the 1st octet |
| /4 | 240.0.0.0 | 15.255.255.255 | 268,435,456 | 268,435,454 | 16 in the 1st octet |
| /5 | 248.0.0.0 | 7.255.255.255 | 134,217,728 | 134,217,726 | 8 in the 1st octet |
| /6 | 252.0.0.0 | 3.255.255.255 | 67,108,864 | 67,108,862 | 4 in the 1st octet |
| /7 | 254.0.0.0 | 1.255.255.255 | 33,554,432 | 33,554,430 | 2 in the 1st octet |
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,216 | 16,777,214 | 1 in the 1st octet |
| /9 | 255.128.0.0 | 0.127.255.255 | 8,388,608 | 8,388,606 | 128 in the 2nd octet |
| /10 | 255.192.0.0 | 0.63.255.255 | 4,194,304 | 4,194,302 | 64 in the 2nd octet |
| /11 | 255.224.0.0 | 0.31.255.255 | 2,097,152 | 2,097,150 | 32 in the 2nd octet |
| /12 | 255.240.0.0 | 0.15.255.255 | 1,048,576 | 1,048,574 | 16 in the 2nd octet |
| /13 | 255.248.0.0 | 0.7.255.255 | 524,288 | 524,286 | 8 in the 2nd octet |
| /14 | 255.252.0.0 | 0.3.255.255 | 262,144 | 262,142 | 4 in the 2nd octet |
| /15 | 255.254.0.0 | 0.1.255.255 | 131,072 | 131,070 | 2 in the 2nd octet |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,536 | 65,534 | 1 in the 2nd octet |
| /17 | 255.255.128.0 | 0.0.127.255 | 32,768 | 32,766 | 128 in the 3rd octet |
| /18 | 255.255.192.0 | 0.0.63.255 | 16,384 | 16,382 | 64 in the 3rd octet |
| /19 | 255.255.224.0 | 0.0.31.255 | 8,192 | 8,190 | 32 in the 3rd octet |
| /20 | 255.255.240.0 | 0.0.15.255 | 4,096 | 4,094 | 16 in the 3rd octet |
| /21 | 255.255.248.0 | 0.0.7.255 | 2,048 | 2,046 | 8 in the 3rd octet |
| /22 | 255.255.252.0 | 0.0.3.255 | 1,024 | 1,022 | 4 in the 3rd octet |
| /23 | 255.255.254.0 | 0.0.1.255 | 512 | 510 | 2 in the 3rd octet |
| /24 | 255.255.255.0 | 0.0.0.255 | 256 | 254 | 1 in the 3rd octet |
| /25 | 255.255.255.128 | 0.0.0.127 | 128 | 126 | 128 in the 4th octet |
| /26 | 255.255.255.192 | 0.0.0.63 | 64 | 62 | 64 in the 4th octet |
| /27 | 255.255.255.224 | 0.0.0.31 | 32 | 30 | 32 in the 4th octet |
| /28 | 255.255.255.240 | 0.0.0.15 | 16 | 14 | 16 in the 4th octet |
| /29 | 255.255.255.248 | 0.0.0.7 | 8 | 6 | 8 in the 4th octet |
| /30 | 255.255.255.252 | 0.0.0.3 | 4 | 2 | 4 in the 4th octet |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 | 2 (point to point, RFC 3021) | 2 in the 4th octet |
| /32 | 255.255.255.255 | 0.0.0.0 | 1 | 1 (a host route) | 1 in the 4th octet |
Take the number of addresses and remove two: the network address and the broadcast address. A /27 has 32 addresses and 30 usable hosts.
A wildcard is the mask turned inside out: 255.255.255.255 minus the mask. A 0 bit must match and a 1 bit can be anything. Access lists and OSPF network statements use them, so 0.0.0.255 matches a /24.
In the octet where the mask stops being 255, the block size is 256 minus that octet. A mask of 255.255.255.224 gives blocks of 32: .0, .32, .64 and so on.
Type any address and pick a prefix. The calculator shows the network, broadcast and usable range, and the binary underneath, with network bits and host bits in different colours.
You can also type the prefix with the address, such as 172.16.45.200/21. Examples:
network bits host bits
I checked this calculator against Python’s own ipaddress library for 58 IPv4 cases, including /0, /31 and /32. For a /31, both addresses are usable on a point to point link and there is no broadcast.
I do not convert everything to binary. The block size method gives the network, broadcast and host range in seconds, for any mask, once you know which octet to look at.
Swipe sideways to see the whole diagram.
Write out the mask and find the octet that is not 255 and not 0. For a /27 it is the 4th octet, 224. Everything before it is fixed network; everything after it is host.
Take that octet away from 256. Here 256 − 224 = 32, so the subnets start at 0, 32, 64, 96 and so on in the 4th octet. This is often called the magic number.
Find the multiple of 32 that sits at or below 77. That is 64, and the next block starts at 96, so this block runs from 64 to 95.
The network is the first address, .64, and the broadcast the last, .95. The hosts sit between them, .65 to .94: 30 in all.
For 172.16.45.200/21 the interesting octet is the 3rd, 248, so the block is 8. 45 sits in the block from 40 to 47, so the network is 172.16.40.0 and the broadcast 172.16.47.255, with 2,046 hosts.
Two to the power of the bits borrowed. Four /26s fit in a /24, because 26 − 24 = 2 and 2² = 4. Sixty four /30s fit in a /24.
Two to the power of the host bits, minus two. A /28 has 4 host bits: 2⁴ − 2 = 14 hosts.
Find the smallest power of two that is at least N + 2. Fifty hosts need 52 addresses, so 64, which is a /26.
Variable length subnet masking (VLSM) lets each subnet have the mask it needs. The rule that keeps it tidy is simple: allocate the biggest subnets first, and start every block on a multiple of its own size.
Swipe sideways to see the whole diagram.
Write down every subnet and how many hosts it needs, now and in a few years. Then sort them from biggest to smallest.
One hundred users need 102 addresses, so the next power of two is 128: a /25, from .0 to .127.
Fifty servers need 52 addresses, so 64: a /26 starting at .128.
Twenty printers and cameras need 22, so 32: a /27 starting at .192, which is a multiple of 32.
Ten management interfaces need 12, so 16: a /28 at .224.
Each point to point link needs 2 hosts: a /30 each at .240 and .244 (or /31s). The last 8 addresses stay free as a /29 for growth.
Route summarisation, sometimes called supernetting, advertises one larger prefix in place of many small ones. Smaller routing tables converge faster, and faults stay inside the area they started in.
Swipe sideways to see the whole diagram.
A site uses four contiguous /24s, 10.1.0.0 to 10.1.3.0. Without summarising, every router in the network carries four routes for one site.
Write the changing octet in binary. The first six bits are the same in all four, so the summary keeps 16 + 6 = 22 bits.
10.1.0.0/22 covers exactly those four networks. The site advertises one route, and a flapping subnet inside it no longer disturbs the rest of the network.
A summary must start on a multiple of its own size. 10.1.2.0 to 10.1.5.0 is four networks, but 10.1.2.0 is not a multiple of 4, so it cannot be one /22. It takes two /23s, which is why I plan addresses to summarise from day one.
At OSPF area borders, at the edge of each site or region, and between the data centre fabric and the rest of the network. The commands differ: area 1 range in OSPF, aggregate-address ... summary-only in the Border Gateway Protocol (BGP).
A router that creates a summary also installs a route to Null0 for it. Traffic for a part of the summary that does not exist is dropped there, instead of looping back towards the default route.
A summary can attract traffic for a subnet that is down, and can hide a better path. I accept that in exchange for stability, and keep specific routes only where traffic engineering needs them.
A good plan is boring to read and easy to extend. It is hierarchical, so it summarises; it never overlaps with cloud, partners or future acquisitions; and it lives in an IP address management (IPAM) tool, not a spreadsheet only one person understands.
Swipe sideways to see the whole diagram.
I start with one private block for the whole organisation, usually 10.0.0.0/8, and keep separate blocks for cloud and partners so nothing ever overlaps.
Each region gets a large, summarisable block. Four /12s still leave most of the /8 free for growth and acquisitions.
Each site gets a /16 from its region. A site number that matches the second octet makes every address easy to read.
Inside a site, each function has a fixed place: users, voice, Wi-Fi, Internet of Things (IoT) devices, management, and links and loopbacks. IoT and Wi-Fi pools are sized well ahead of today’s count, often ten times.
Because the plan is hierarchical, each site advertises one /16 and each region one /12. The routing table stays small, and the same layout repeats at every site.
| Item | How I address it | Why |
|---|---|---|
| Loopback 0 | One /32 per switch from a /24 | Router ID and BGP peering |
| Loopback 1 | One /32 per leaf, plus a shared /32 per leaf pair | Virtual Extensible LAN (VXLAN) tunnel endpoint (VTEP) source |
| Spine to leaf links | /31 per link (RFC 3021), or IP unnumbered | Saves half the space of /30s |
| Sizing example | 4 spines × 64 leaves = 256 links = 512 addresses | Exactly a /23 |
| Management | Its own range and virtual routing and forwarding (VRF) instance on the out of band network | Reachable when the fabric is down |
| IPv6 | A /48 per site and a /64 per segment | Room for every segment, always |
Overlapping ranges after a merger or with a cloud provider force NAT between them, which breaks logs, troubleshooting and some applications. I reserve cloud and partner blocks from the start.
A /24 for IoT looks fine until the building adds sensors. I size IoT and Wi-Fi pools for ten times today’s count and plan for IPv6 where devices support it.
The same thinking applies to BGP autonomous system (AS) numbers. The 2 byte private range, 64512 to 65534, has only 1,023 numbers. Large fabrics use the 4 byte private range, 4200000000 to 4294967294.
IPv6 fixes address exhaustion for good. The rules are simpler than IPv4 in many ways: every segment is a /64, there is no broadcast and no NAT is needed. What changes most is how hosts find routers and each other.
Swipe sideways to see the whole diagram.
Anatomy. An IPv6 address is 128 bits, written as eight groups of four hexadecimal digits. The left half is the network: a global prefix and a subnet ID. The right half identifies the interface. Stateless address autoconfiguration (SLAAC) builds it from the media access control (MAC) address in the Extended Unique Identifier (EUI-64) format, or picks it at random.
Writing it short. Leading zeros in each group can be dropped, and one run of all zero groups can become a double colon. Doing it the same way every time (RFC 5952) makes addresses easy to search in logs.
Address types. IPv6 has no broadcast. Multicast does that job, and every interface also has a link local address, which routing protocols use as their next hop.
EUI-64 splits the 48 bit MAC address, puts ff:fe in the middle and flips the seventh bit. Many hosts now use random interface IDs instead, for privacy.
| Prefix | Where | Note |
|---|---|---|
| /32 | An organisation from a registry, or a provider | Room for 65,536 sites of /48 |
| /48 | A site | 65,536 subnets of /64 |
| /56 | A small site, a home, or a data centre pod | 256 subnets of /64 |
| /64 | Every local area network (LAN) segment | SLAAC needs exactly 64 bits of interface ID |
| /127 | Point to point links (RFC 6164) | Like a /31 in IPv4 |
| /128 | Loopbacks | A single address |
The IPv6 header is a fixed 40 bytes. Routers never fragment: only the sender can, and every link must carry at least 1,280 bytes. Internet Control Message Protocol for IPv6 (ICMPv6) packet too big messages must be allowed through.
Every IPv6 interface has an fe80:: address, even with no global address. Routers advertise their link local address as the gateway, and routing protocols peer over it.
ipv6 unicast-routing turns routing on in Cisco IOS. show ipv6 interface brief, show ipv6 neighbors and show ipv6 route are the IPv6 versions of the familiar IPv4 checks.
Neighbour Discovery Protocol (NDP) runs over ICMPv6 and replaces the Address Resolution Protocol (ARP), router discovery and parts of DHCP. Because it is so central, it also needs its own first hop security.
Swipe sideways to see the whole diagram.
Before anything else, the host gives itself a link local address. It needs no router and no server.
The host checks nobody else has the address by sending a neighbour solicitation to a special multicast group. Silence means it is safe to use.
The host asks for routers. Routers also send advertisements every few minutes on their own.
The router answers with the prefix and the flags that say how hosts should get their addresses and other settings.
Stateless address autoconfiguration (SLAAC) builds the global address with no server at all. Stateful DHCP for IPv6 (DHCPv6) is used where the M flag is set and addresses must be tracked.
Neighbour solicitation and advertisement replace ARP, using multicast instead of broadcast, so only the target host is disturbed.
| ICMPv6 type | Message | Purpose |
|---|---|---|
| 133 | Router solicitation (RS) | A host asks routers to announce themselves |
| 134 | Router advertisement (RA) | Prefix, flags, router lifetime and the gateway |
| 135 | Neighbour solicitation (NS) | Address resolution and duplicate address detection |
| 136 | Neighbour advertisement (NA) | The answer: this address is at this MAC |
| 137 | Redirect | A better first hop on the same link |
| RA flags | Address from | Domain Name System (DNS) servers and other settings from |
|---|---|---|
| M off, O off | SLAAC | The RA itself, through its recursive DNS server (RDNSS) option, if the host supports it |
| M off, O on | SLAAC | Stateless DHCPv6 |
| M on | Stateful DHCPv6 (UDP 546 and 547) | DHCPv6 |
A rogue router advertisement can make every host on a virtual LAN (VLAN) send its traffic to an attacker. RA guard on access switches drops advertisements from ports where no router should be.
The IPv6 versions of DHCP snooping and IP source guard stop rogue DHCPv6 servers and spoofed source addresses.
In large fabrics, neighbour discovery and ARP are the main source of flooded traffic. Ethernet VPN (EVPN) can answer them locally at the leaf, which I cover on the VXLAN EVPN page.
Most networks run dual stack for years, not a sudden switch. The design rule is simple: build IPv6 in from day one, and check every rule, route and test twice, once for each protocol. Where an IPv6 only client must reach an IPv4 only server, NAT64 (address translation from IPv6 to IPv4) and DNS64 (a DNS service that builds matching IPv6 answers) bridge the gap.
Swipe sideways to see the whole diagram.
Dual stack. Hosts, routers and servers run IPv4 and IPv6 side by side. It is the approach I recommend, because nothing is translated and each protocol can be checked on its own. Browsers try both and use whichever answers first (Happy Eyeballs), preferring IPv6.
Tunnelling. IPv6 islands are joined across an IPv4 only core by wrapping IPv6 inside IPv4 (6in4 uses IP protocol 41). It is quick to set up, but it hides the real path and lowers the maximum transmission unit (MTU).
Translation. An IPv6 only client reaches an IPv4 only server through NAT64. DNS64 builds a fake AAAA (IPv6 address) record by putting the IPv4 address inside the 64:ff9b::/96 prefix, and the gateway translates the packets. Mobile networks use this widely.
Most addressing faults look like something else: a slow application, a flaky Wi-Fi network or a broken VPN. These six cover the majority of what I find, with the checks that prove each one.
Swipe sideways to see the whole diagram.
Overlapping subnets. Two sites, or a site and a VPN partner, use the same range. Hosts think the far end is local, so they ARP instead of routing. Check the routing table on both sides and the VPN selectors. Fix by readdressing one side; NAT between them is a stopgap, not a cure.
Wrong mask. A /16 on a /24 network makes the personal computer (PC) treat 10.1.20.50 as local. It works only if proxy ARP covers for it. Check ipconfig /all or ip addr against the DHCP scope or the documented plan. Fix the mask, and turn proxy ARP off so the mistake shows up straight away.
Duplicate IP address. Two devices answer for one address, so connections break at random as ARP caches change. Check show ip arp twice and watch the MAC change, Windows duplicate address warnings, or show ip dhcp conflict. Fix the static address, reserve it in DHCP, and use DHCP snooping with IP source guard.
Wrong default gateway. The PC can reach everything in its own subnet but nothing beyond it. Check the gateway setting, then arp -a to see whether it ever resolved. Fix the gateway, usually the first hop redundancy virtual address.
A 169.254 address. The client asked for DHCP and nobody answered. Check the VLAN on the port, the ip helper-address on the gateway, and DHCP snooping trust on the uplinks. Fix whichever link in that chain is broken.
DHCP scope exhausted. Existing clients are fine, new ones get nothing. It often follows a guest or IoT rollout. Check the scope use and lease time on the server, or show ip dhcp pool. Fix by growing the subnet or shortening leases where clients come and go quickly.
The full method, with faults at every layer, is on the troubleshooting page. For DHCP and ARP in more depth, see networking fundamentals.
Addressing decisions outlive the hardware they were made on. These are the places where getting them right, or fixing them, mattered most.
Managed provider IP space and AS numbers with RIPE NCC (the European regional internet registry), including Resource Public Key Infrastructure (RPKI) route origin authorisations, for a Tier 3 data centre serving over 300 customer sites.
Cleaned up regional internet registry records across the merged address space during the reverse merger, and secured the consolidated internet edge with RPKI based BGP origin validation.
Post merger infrastructure integration across a multi site estate, including distribution centres, with warehouse automation segmented from corporate information technology (IT).
Each lab site has its own 10.x range, the provider core uses /29 links, a /30 joins the London router to its core switch, and the ESXi hosts sit on /25 VLANs. See the addressing tables.
Backed by CCNP Enterprise, CCNP Routing and Switching, CCDP and CCNA. See all credentials
Every page follows the same idea: how it works, the choices that matter, and where I have used it. The foundations pages explain the basics the others build on.