Introduction
One configuration screen may ask for /21 while another asks for 255.255.248.0. Both encode the same boundary. Converting between them helps reconcile an address plan with a device configuration.
Formula and calculation
wildcard = 2^32 − 1 − subnet mask; prefix = count of leading 1 bitsA valid subnet mask has contiguous leading one bits followed by zero bits. The wildcard has the inverse bits and is shown here as a reference calculation.
- subnet mask · bits
- 32-bit contiguous mask interpreted as an unsigned integer
Method and concepts
A CIDR subnet mask contains a single run of one bits followed by a single run of zero bits. Count the leading ones to recover the prefix length. To build the mask, write that many ones, pad on the right to 32 bits, and read the result eight bits at a time. The result also shows the 32-bit wildcard mask, the exact inverse of the subnet mask; in common access-list matching, zero bits require agreement and one bits are variable.
- Supply a dotted mask or a prefix length. For a dotted mask, inspect the octets from left to right.
- After the first zero bit, every remaining bit must be zero. Check this before counting ones.
- Read both the dotted subnet mask and its wildcard complement. Use the notation required by the destination form and preserve all four octets when recording either value.
IPv4 addresses and packet headers diagram
- IP packet · 1,500 bytes
- IPv4 header · 20 bytes
- IP payload · 1,480 bytes
- TCP data · 1,460 bytes
Worked examples
Translate a mask with a partial third octet
- Split 255.255.248.0 into 11111111, 11111111, 11111000 and 00000000.
- Count eight plus eight plus five leading ones. This gives /21. The eleven zero positions allow 2,048 addresses per block; their complement is wildcard 0.0.7.255.
- As a cross-check, 256 − 248 gives a third-octet increment of eight. A block beginning at 10.2.8.0/21 therefore ends at 10.2.15.255.
IPv4 addresses and packet headers: Read the first IPv4 byte 0x45
- Split 0x45 into the high hex digit 4 and low digit 5. The upper four bits identify version 4. The lower four encode an IHL of five words.
- Multiply 5 by 4 bytes to obtain the 20-byte header. With Total Length 1,500, the IP payload contains 1,480 bytes.
- If Protocol is 6 and the TCP header also occupies 20 bytes, the segment carries 1,460 application bytes. Adding IPv4 or TCP options reduces that amount at the same packet size.
Reference table
| Third mask octet | Bits | Prefix in 255.255.x.0 |
|---|---|---|
| 224 | 11100000 | /19 |
| 240 | 11110000 | /20 |
| 248 | 11111000 | /21 |
| 252 | 11111100 | /22 |
Reading the result
Only nine octet values can occur in a contiguous mask: 0, 128, 192, 224, 240, 248, 252, 254 and 255. Their placement also matters. Once a partial octet occurs, every following octet must be zero. The wildcard output is the bitwise inverse for this contiguous prefix; some matching systems also allow non-contiguous wildcard patterns, which this converter does not accept as input.
Common mistakes
- Accepting 255.0.255.0 because all its individual octets look familiar.
- Using an inverted wildcard where a subnet mask is required.
Frequently asked questions
Is 255.255.250.0 a /22?
No. The octet 250 is 11111010. A one appears after a zero, so no single CIDR length represents that mask.
Which masks represent the two extremes?
0.0.0.0 fixes zero bits and gives /0. The all-ones mask 255.255.255.255 fixes every bit and gives /32.
How does the wildcard output differ from a subnet mask?
It flips every bit. In common access-list matching, a zero requires that address bit to match the reference, while a one lets it vary. This converter reports the complement of a contiguous subnet mask.
What does /32 mean on a route?
All 32 address bits must match. The route represents exactly one IPv4 value and can identify a loopback or another specific destination.
Is the IPv4 Protocol number the service port?
No. The protocol number selects a payload format, for example UDP 17. A UDP header then carries source and destination port numbers.
How many bytes are in the minimum IPv4 header?
The minimum header is 20 bytes. The IHL field counts 32-bit words, so a value of five represents 20 bytes; options can make it longer.
Does IPv4 Total Length include Ethernet framing?
No. It counts the IPv4 header and IPv4 payload. Link-layer framing is outside that length field.
What happens when an IPv4 packet is larger than an outgoing MTU?
Depending on the Don't Fragment setting and path behavior, it may be fragmented or dropped with an ICMP message. Path MTU discovery uses this feedback to find a usable packet size.
Does an IPv4 Protocol number identify a TCP or UDP port?
No. The Protocol field identifies the payload protocol, such as TCP or UDP. A TCP or UDP header then contains the service ports.
What does TTL protect against?
IPv4 Time To Live bounds how many forwarding hops a packet can survive. Routers decrement it so a packet cannot circulate forever in a forwarding loop.
Is the IPv4 header checksum an end-to-end payload checksum?
No. It covers the IPv4 header only and is recomputed when mutable header fields such as TTL change. Transport protocols have separate integrity fields.
Can IPv4 fragmentation be reassembled at every router?
No. Fragmentation can occur during forwarding when permitted, but fragments are normally reassembled by the destination host, not each intermediate router.
Why use documentation IPv4 ranges in examples?
The designated documentation blocks avoid using a real organization's address in examples. They should not be treated as ordinary public service addresses.
What is the difference between limited broadcast and directed broadcast?
The limited broadcast address is 255.255.255.255 and is confined to the local link. A directed broadcast targets the all-ones host part of a particular IPv4 subnet and is commonly filtered by routers.
Can two routers advertise the same IPv4 prefix?
They can provide alternative routes to the same prefix. Routing policy and metrics determine whether one is preferred or both are installed for load sharing.
Why is classful addressing considered historical?
The original A, B, and C boundaries fixed network sizes at coarse octet edges. CIDR allows a prefix boundary at any bit and is used for modern allocation and routing.
What is the IPv4 header checksum recalculated over?
It covers the IPv4 header, not the payload. Because forwarding changes TTL, a router updates the checksum as the packet traverses the path.
When can a /31 IPv4 prefix be useful?
On a point-to-point link, RFC 3021 allows both addresses to be assigned to the two endpoints. It avoids reserving separate network and broadcast values where those functions are not needed.
Further learning and references
- RFC 1878, Variable Length Subnet Table for IPv4
Reference source for the concepts and service described in this guide.
- RFC 791 · IPv4 header and address format
- RFC 1191 · IPv4 path MTU discovery
- IANA · Protocol numbers

