IPv4 Addresses: Dotted Quads, Binary and the Old Address Classes
What an IPv4 address really is: a 32-bit number written as a dotted quad, how to convert it to binary and back, the odd forms some tools still accept, and the original class A, B and C system that CIDR replaced.
kvi5hnuCode Sprout team member13 min readOn this page
Every packet IP sends carries two addresses: where it came from and where it's going. Routers read the destination address to decide where to send the packet next, and the receiver reads the source address to know where to reply. So before you can understand routing, subnets or firewalls, you need to be able to read an IP address the way a router does, as a string of bits.
This article covers IPv4 addresses: how they're written, how to convert them, and the original "class" system that divided them up. That system is obsolete, but its vocabulary (class C, /24, "a class B network") is still everywhere. Article 10 does the same for IPv6.
What an address identifies
An IP address identifies a network interface, not a computer. A laptop with Wi-Fi and Ethernet has an address on each, and a router has one on every network it connects to. Most hosts have several addresses at once: a loopback address (one that leads back to the same machine, such as 127.0.0.1), one or more on each interface, and often both IPv4 and IPv6. When people say "the server's IP", they mean the address of the interface clients reach it through.
Addresses must be unique within the network where they're used. On the public Internet, a hierarchy of registries hands out address blocks so no two organizations get the same ones (article 13 explains how). Inside a private network, its administrators must avoid duplicates themselves. Most people rarely see addresses, because the Domain Name System (DNS) lets them use names instead (article 4 introduces it). You meet raw addresses when you set up a network, read a log or a capture, or when DNS is broken.
An address is a 32-bit number
An IPv4 address is a single 32-bit unsigned integer, from 0 to 4,294,967,295. That's about 4.3 billion addresses in total, which turned out to be far too few (article 13 covers the consequences).
Thirty-two bits are hard to read, so people write them as dotted-quad (or dotted-decimal) notation: split the 32 bits into four 8-bit bytes, write each byte as a decimal number from 0 to 255, and join them with dots.

To convert one byte to binary, use the place values 128, 64, 32, 16, 8, 4, 2, 1. For 10: it's 8 + 2, so the bits under 8 and 2 are 1, giving 00001010. To go back, add up the place values of the 1 bits. Hexadecimal is even easier, because each byte is exactly two hex digits: 192 is c0 (12 × 16 + 0, and hex digit c is 12), 0 is 00, 2 is 02, 10 is 0a.
To get the single integer, give each byte its place value as a whole byte: the first byte counts 2²⁴ = 16,777,216, the second 2¹⁶ = 65,536, the third 2⁸ = 256 and the last 1. For 192.0.2.10 that's 192 × 16,777,216 + 0 × 65,536 + 2 × 256 + 10 = 3,221,225,472 + 0 + 512 + 10 = 3,221,225,994.
Here are a few addresses converted in the lab with Python's ipaddress module. The columns are the dotted quad, the four bytes in binary, the same value as one integer, and in hexadecimal:
0.0.0.0 00000000 00000000 00000000 00000000 0 0x00000000
192.0.2.10 11000000 00000000 00000010 00001010 3221225994 0xc000020a
198.51.100.255 11000110 00110011 01100100 11111111 3325256959 0xc63364ff
203.0.113.77 11001011 00000000 01110001 01001101 3405803853 0xcb00714d
255.255.255.255 11111111 11111111 11111111 11111111 4294967295 0xffffffff
Seeing your own addresses
On Linux, ip addr lists each interface's addresses. Here's the lab's client host. Its interface eth0 has one IPv4 address, written as an address followed by /24 (article 6 explained the other fields):
12: eth0@if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link-netns r1
inet 192.0.2.10/24 scope global eth0
valid_lft forever preferred_lft forever
The /24 is the prefix length. It says that the first 24 bits (192.0.2) identify the network and the last 8 bits identify this interface on it. Article 8 is entirely about that split.
Odd forms that some tools still accept
The dotted quad isn't the only form the C library understands. The old inet_aton() function, which ping and many other tools use, accepts several legacy shorthands:
- Fewer than four parts, where the last part fills the remaining bytes:
127.1means127.0.0.1. - A single number for the whole address:
2130706433means127.0.0.1, because 127 × 16,777,216 + 1 = 2,130,706,433. - Hexadecimal parts with a
0xprefix, and octal parts with a leading0:0177.0.0.1means127.0.0.1, because 0177 in octal is 127.
Here's ping in the lab resolving each form to the same address (only the first line of each is shown):
PING 127.1 (127.0.0.1) 56(84) bytes of data.
PING 2130706433 (127.0.0.1) 56(84) bytes of data.
PING 0x7f000001 (127.0.0.1) 56(84) bytes of data.
PING 0177.0.0.1 (127.0.0.1) 56(84) bytes of data.
The octal rule causes real bugs. 192.0.2.010 means 192.0.2.8 to inet_aton() (octal 10 is 1 × 8 + 0 = 8), but a person (or a stricter parser) reads it as 192.0.2.10. Python's ipaddress module rejects all these forms, and since 2021 it also rejects leading zeros (an earlier version accepted them, and that mismatch was treated as a security vulnerability):
ipaddress '127.1' rejected: Expected 4 octets in '127.1'
ipaddress '0177.0.0.1' rejected: At most 3 characters permitted in '0177' in '0177.0.0.1'
ipaddress '192.0.2.010' rejected: Leading zeros are not permitted in '010' in '192.0.2.010'
inet_aton '127.1' -> 127.0.0.1
inet_aton '0177.0.0.1' -> 127.0.0.1
inet_aton '192.0.2.010' -> 192.0.2.8
Network and host parts
From the start, IPv4 addresses had two parts:
- The network part (also called the network number or prefix), at the left, identifies the network the interface is on. All interfaces on one network share it.
- The host part, the remaining bits on the right, identifies one interface on that network.
This split is what makes routing on the Internet possible. A router doesn't need to know where each of billions of hosts is. It only needs to know where each network is, and it can read the network part straight from the destination address. Inside the destination network, the host part picks the interface.
The question is where the split goes. Some networks need millions of addresses and others need a handful. The original answer was address classes.
Classful addressing
Under the original scheme, the first few bits of an address said which class it belonged to, and the class fixed how many bits were network and how many were host:

| Class | Leading bits | First byte | Network / host bits | Networks | Addresses per network | Share of all addresses |
|---|---|---|---|---|---|---|
| A | 0 | 0–127 | 8 / 24 | 128 | 16,777,216 | 1/2 |
| B | 10 | 128–191 | 16 / 16 | 16,384 | 65,536 | 1/4 |
| C | 110 | 192–223 | 24 / 8 | 2,097,152 | 256 | 1/8 |
| D | 1110 | 224–239 | none | (multicast) | 1/16 | |
| E | 1111 | 240–255 | none | (reserved) | 1/16 |
Classes A, B and C were for unicast addresses, which identify a single interface. Class D is for multicast (one packet to a group of receivers, covered in article 12), and class E was reserved for future use. Some class A networks were special from the start: network 0 and network 127 (loopback) were never assigned to anyone, which is why you'll see 126 usable class A networks in some sources.
The real counts of usable host addresses are also two less than the table suggests: the first address of a network (all host bits 0) names the network itself, and the last (all host bits 1) is its broadcast address. A class C network has 256 addresses but only 254 for hosts. Article 8 explains both special addresses.
Here's the lab classifying some addresses by their first byte. Compare the start of each binary first byte with the leading bits in the table: 0 gives class A, 10 class B, 110 class C, and so on. The last column is the network each would have belonged to under the class rules:
10.1.2.3 first byte 10 = 00001010 class A classful network 10.0.0.0/8
172.16.5.4 first byte 172 = 10101100 class B classful network 172.16.0.0/16
192.0.2.10 first byte 192 = 11000000 class C classful network 192.0.2.0/24
198.51.100.10 first byte 198 = 11000110 class C classful network 198.51.100.0/24
224.0.0.251 first byte 224 = 11100000 class D classful network (no network/host split)
240.0.0.1 first byte 240 = 11110000 class E classful network (no network/host split)
Why classes failed
The class system was simple, because the network size was written into the first bits of every address, but it scaled badly in three ways:
- The sizes were wrong for most organizations. A class C (254 hosts) was too small for a university or company, and a class B (65,534 hosts) was far too big for most of the organizations that got one. Many class B networks used only a small fraction of their addresses.
- Class B ran out. By 1994, more than half of the 16,384 class B networks had been handed out, and the rest were expected to be gone within about a year.
- Routing tables grew. Every organization that got several class C networks instead of one class B added several entries to the routing table of every router on the Internet.
The first fix, subnetting, let an organization divide its own network internally (article 8). The real fix, CIDR (Classless Inter-Domain Routing, 1993), removed classes altogether: any prefix length from /0 to /32 became allowed, and every route says its own prefix length explicitly. Article 9 covers CIDR.
Common questions
Why can't a part of a dotted quad be bigger than 255?
Because each part is one byte, and 8 bits can hold only the values 0 to 255. An address such as 192.0.2.300 is simply invalid.
Is the address 192.0.2.10 the same as 192.0.2.010?
Not necessarily. Python's ipaddress rejects the second form, but the C library's inet_aton(), used by ping and many other tools, reads 010 as octal and gets 192.0.2.8. Never write leading zeros in addresses.
Does a computer have one IP address?
Usually several. Each interface has its own addresses, every host has the loopback address 127.0.0.1, and IPv6 hosts normally have several IPv6 addresses per interface. Servers and routers often have many.
Are classes still used anywhere?
Not for routing or addressing decisions. A few very old protocols, such as RIP (the Routing Information Protocol) version 1, assumed classful network sizes, which is why they can't work with modern subnets. What survives is the vocabulary and the multicast range (old class D). Some ranges, like the private range 172.16.0.0/12, look odd unless you know they were sets of class B networks.
How many IPv4 addresses are there, really?
2³² = 4,294,967,296. But large blocks can't be used for ordinary hosts: multicast and the reserved old class E take 1/8 of the space, and private, loopback, documentation and other special ranges take more. Article 11 lists them.
Why is IPv4 written in decimal while IPv6 is written in hex?
Convention and length. Four decimal numbers are short enough to read. IPv6 addresses are 128 bits, and hex makes it easy to see bit boundaries, because each hex digit is exactly four bits. The cost is that you can't do IPv4 bit math in your head as easily, which is why the next article practices it.
Summary
- An IPv4 address is a 32-bit number identifying a network interface. It's written as four decimal bytes (0–255) joined by dots.
- Convert a byte with the place values 128, 64, 32, 16, 8, 4, 2, 1. Hex is two digits per byte.
inet_aton()accepts legacy forms such as127.1, a single integer, hex parts and octal parts with a leading zero. Strict parsers reject them. Never use leading zeros.- Every address has a network part and a host part. Routers forward on the network part.
- The original classes fixed the split by the leading bits: A (/8), B (/16), C (/24), plus D (multicast) and E (reserved).
- Classes wasted addresses, exhausted class B and bloated routing tables. Subnetting and then CIDR replaced them. Today "class C" just means /24.
Practice questions
1. Convert 203.0.113.77 to binary and to hexadecimal.
Answer
203 = 128+64+8+2+1 = 11001011 (cb), 0 = 00000000 (00), 113 = 64+32+16+1 = 01110001 (71), 77 = 64+8+4+1 = 01001101 (4d). So it's 11001011 00000000 01110001 01001101, or 0xcb00714d. That matches the lab table above.
2. Which dotted quad is the binary value 11000110 00110011 01100100 00001010?
Answer
128+64+4+2 = 198, 32+16+2+1 = 51, 64+32+4 = 100, 8+2 = 10. It's 198.51.100.10, the lab's server.
3. Under the old class rules, what class was 172.20.1.1, and what was its classful network?
Answer
The first byte, 172, is between 128 and 191, so class B. The classful network was the first 16 bits, 172.20.0.0/16. (Today it's part of the private range 172.16.0.0/12, which is 16 consecutive old class B networks.)
4. A tool prints PING 0300.0.2.1 (192.0.2.1). Explain the result.
Answer
inet_aton() treats a part with a leading zero as octal. 0300 in octal is 3×64 = 192, so 0300.0.2.1 is 192.0.2.1.
5. A class C network had 256 addresses. Why could only 254 be assigned to hosts?
Answer
The address with all host bits 0 (for example 192.0.2.0) identifies the network itself, and the address with all host bits 1 (192.0.2.255) is the network's broadcast address. Neither can be given to an interface.
6. Give two reasons classful addressing was abandoned.
Answer
Any two of: the fixed sizes didn't fit real organizations, so addresses were wasted (especially in class B networks); the class B space was running out by 1994; and organizations using many class C networks instead made Internet routing tables grow fast. CIDR fixed all three by allowing any prefix length.
Previous: Tools of the Trade: ip, ss, ping, dig, tcpdump and Reading a Packet Capture
Next: Subnetting: Masks, Prefix Lengths, VLSM and Broadcast Addresses

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.