An IPv4 address is a 32-bit number written as four decimal octets, each from 0 to 255, so 192.168.1.42 is the bit pattern 11000000 10101000 00000001 00101010. The 32 bits allow 2^32 = 4,294,967,296 addresses, of which blocks are set aside for private use, loopback and broadcast, and a mask divides every address into a network part and a host part. Learn to convert an octet to binary by hand, because every subnet calculation rests on it.

Part of Networking

The bit-level layout of the 32-bit IPv4 address, dotted decimal notation, and the special addresses every network reserves.

An Address Is Four Bytes Written In Decimal

Packet Structure shows that an IPv4 header carries a 32-bit source address and a 32-bit destination address, and Network Addressing gives the dotted form. Four bytes are written as four decimal numbers separated by dots. A byte holds eight bits, so each number runs from 0 (00000000) to 255 (11111111). A number above 255 is not an octet: 192.168.1.256 and 300.1.1.1 are invalid.

The address space is 2 to the power 32. To compute it by hand: 2^10 = 1,024; 2^30 = 1,024 x 1,024 x 1,024 = 1,073,741,824; 2^32 = 4 x 1,073,741,824 = 4,294,967,296. A settlement never comes near this number, and an IPv6 address of 128 bits (Packet Structure) is unnecessary for a private network. The private blocks are already large: 2^24 = 16,777,216 addresses in 10.0.0.0/8 and 2^16 = 65,536 in 192.168.0.0/16 (Private Ranges).

What You Need

  • Powers of two by heart, or on a card: 128, 64, 32, 16, 8, 4, 2, 1
  • Pencil and paper — the method works by subtraction

Method: Convert An Octet To Binary

Step 1: Write the eight place values 128 64 32 16 8 4 2 1, left to right.

Step 2: Subtract from the left Take the largest place value that fits, write 1 under it, subtract it, and continue with the remainder. Write 0 under every place value you skip.

Step 3: Check by adding the 1s back up The place values under the 1s must add to the original number.

For the reverse direction, add the place values that carry a 1.

Worked Example: Two Addresses In Both Directions

192.168.1.42.

  • 192 = 128 + 64, so 11000000 (128 and 64 are 1, the rest 0)
  • 168 = 128 + 32 + 8, so 10101000
  • 1 = 1, so 00000001
  • 42 = 32 + 8 + 2, so 00101010

The full address is 11000000 10101000 00000001 00101010. Checking back: 128 + 64 = 192; 128 + 32 + 8 = 168; 1; 32 + 8 + 2 = 42.

10.20.30.40.

  • 10 = 8 + 2, so 00001010
  • 20 = 16 + 4, so 00010100
  • 30 = 16 + 8 + 4 + 2, so 00011110
  • 40 = 32 + 8, so 00101000

Giving 00001010 00010100 00011110 00101000.

Special Addresses That Are Not For Machines

  • All host bits zero — the network address, which names the network, not a machine
  • All host bits one — the broadcast address, which reaches every machine in the network (Network Addressing)
  • 0.0.0.0/0 — the default route, which matches every destination (Routing Basics)
  • 127.0.0.0/8 — loopback, addresses that refer to the machine itself
  • 169.254.0.0/16 — addresses a machine gives itself when it asks for an address and no server answers; seeing one on a machine means automatic addressing failed (DHCP)

The last two blocks are from general knowledge, not from the other articles in this section; check them against the documentation of the operating system you actually run.

Common Mistakes

  • Reading an address as a number instead of four numbers — the dots separate bytes, so 1.2.3.4 is not “one thousand two hundred and thirty-four”
  • Padding with leading zeros — some software reads a leading zero as octal, so write 10.1.0.5, not 010.001.000.005; this is general knowledge, not from the other articles
  • Assigning a network or broadcast address to a machine — they are 2 addresses lost from every subnet (Subnet Masks)

What’s Next

  • Learn next: Subnet Masks — splitting the 32 bits into network and host
  • Combine with: IP Addressing — turning the arithmetic into a plan