TOOLTIKI Lovable tool, really free

An IP address is a 32-bit number

An IPv4 address is four bytes packed into a single 32-bit integer, and the dots are presentation rather than structure. 192.168.1.1 is 192×2²⁴ + 168×2¹⁶ + 1×2⁸ + 1 = 3232235777. Once you hold that number, subnet membership stops being mask arithmetic and becomes a range comparison — a /24 is 256 consecutive integers.

That reframing is why the integer form turns up in databases, firewalls and geolocation tables. Comparing two integers is something every system does well; comparing two dotted strings is something none of them do at all.

How does the packing work?

Four shift-and-mask operations, and writing them out makes the structure obvious.

Octet Position Multiplier
First Bits 24–31 × 16,777,216
Second Bits 16–23 × 65,536
Third Bits 8–15 × 256
Fourth Bits 0–7 × 1

Unpacking reverses it: shift right by 24, 16, 8 and 0, masking each with 255. Anything above 4,294,967,295 is out of range, because that is the largest 32-bit value and therefore the last IPv4 address — 255.255.255.255.

Why is subnetting taught in binary?

Because a prefix counts leading bits, and only binary makes that visible. 10.20.30.40 is 00001010 00010100 00011110 00101000, and a /24 means the first 24 of those bits identify the network while the last 8 identify the host.

The dotted-decimal mask that expresses the same thing — 255.255.255.0 — is a translation of that bit count, which is why the two notations coexist and why converting between them is a lookup rather than a calculation.

Reading the binary also makes the reserved ranges recognisable on sight. Anything starting 00001010 is 10.x, a full class-A private block. Anything starting 1100 0000 1010 1000 is 192.168.x, the small private block almost every home router uses.

What does the integer form make easy?

Four things that are awkward in dotted notation.

  • Range membership. Is this address inside that subnet becomes a pair of integer comparisons.
  • Counting. The size of a /n is 2^(32−n), so a /24 has 256 addresses and a /16 has 65,536.
  • Sorting. Integers sort correctly; dotted strings sort 10.0.0.2 after 10.0.0.10.
  • Storage. One 32-bit column instead of a string, which matters at the scale where these tables are used.

The sorting point is the one that bites unexpectedly. A list of addresses sorted as text is in an order that looks almost right and is not, and the error is invisible until someone relies on the sequence.

Why does CIDR notation win?

Because it states the boundary as a single number instead of a second address. A /24 says the first 24 bits are the network; 255.255.255.0 says the same thing in a form that has to be decoded before it can be reasoned about.

It also removes an entire class of invalid input. Any prefix from 0 to 32 is well formed, whereas a dotted mask can be written with the ones and zeros interleaved — 255.0.255.0 is a syntactically valid string and a meaningless mask.

The older class system, where the first octet implied the size, disappeared for the same reason: it wasted enormous blocks and could not express anything between its three fixed sizes.

How many addresses are there really?

Four billion nominally, and considerably fewer usable. Whole blocks are reserved: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16 for private use, 127.0.0.0/8 for loopback, 169.254.0.0/16 for link-local, and 224.0.0.0/4 for multicast.

Every subnet also loses two addresses to the network and broadcast identifiers, so a /24 offers 254 usable hosts rather than 256. On a /30 — four addresses, the classic point-to-point link — that overhead is half the block.

Those constraints together are why IPv6 exists, and why the transition has taken so much longer than anyone predicted.

What is a broadcast address for?

Reaching every host on the subnet at once, and it is the last address in the block — 192.168.1.255 on a /24. The first address, 192.168.1.0, identifies the network itself and is not assignable either.

That is the origin of the two-address overhead. It is also why a /31 exists as a special case for point-to-point links: with only two addresses there is no room for a network and broadcast pair, so the rules are relaxed and both addresses are usable.

Questions people ask

Why does an address sometimes appear as a single long number? Because some systems store and display the integer form directly. It is the same address, and a converter turns it back.

Is the integer signed or unsigned? Unsigned, by definition — addresses run 0 to 4,294,967,295. Languages with only signed 32-bit integers represent the top half as negative numbers, which is a common source of confusion in older code.

Does this work for IPv6? The same idea at 128 bits, which is beyond a normal integer type. IPv6 is generally handled as two 64-bit halves or as a byte array rather than a single number.

Why is 127.0.0.1 special? The whole 127.0.0.0/8 block is loopback — sixteen million addresses reserved so a machine can talk to itself, of which almost everyone uses exactly one.

Why do some routers use 192.168.0.x and others 192.168.1.x? Both are inside the same private /16, and the third octet is a vendor default rather than a standard. It is why two routers on the same network can hand out addresses that cannot see each other.

Drop the dots and the awkward operations become arithmetic. IPv4 to integer and integer to IPv4 convert both ways, and IPv4 to binary shows the bit layout a prefix is actually counting.