Binary uses digits 0 and 1. Each position in an octet (8 bits) has the value:
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|
Decimal to binary: 192 = 128 + 64 = 11000000. 172 = 128 + 32 + 8 + 4 = 10101100.
Binary to decimal: 00001010 = 8 + 2 = 10.
Hexadecimal (base 16) uses 0-9 and A-F; each hex digit is 4 bits (A = 1010, F = 1111).
Why binary matters for IP addressing
Every IPv4 address and every subnet mask is really a pattern of 32 bits. Decimal (192.168.1.10) is only a human-friendly view. Subnetting, VLSM and CIDR all mean "count bits and draw a line between the network part and the host part". If you can convert one octet between decimal and binary, you can check any mask by hand.
Place values in one octet
| Bit position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Place value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
To convert decimal to binary, subtract the largest place value that still fits, write 1, and continue; write 0 where it does not fit.
- 192 = 128 + 64 →
11000000 - 168 = 128 + 32 + 8 →
10101000 - 10 = 8 + 2 →
00001010
To convert binary to decimal, add the place values of every 1 bit: 10101100 = 128+32+8+4 = 172.
Hexadecimal shortcuts
Each hex digit is exactly 4 bits, so two hex digits make one byte. That is why MAC addresses are written in hex (00:1A:2B) and why IPv6 uses hex groups. Useful nibble values:
| Hex | Binary | Decimal |
|---|---|---|
| 0 | 0000 | 0 |
| 9 | 1001 | 9 |
| A | 1010 | 10 |
| C | 1100 | 12 |
| F | 1111 | 15 |
Try it: convert 255 and 128 to binary, then convert 11000000 and 00001111 to decimal. You should get 11111111, 10000000, 192 and 15.
Remember
- One octet = 8 bits; place values are 128, 64, 32, 16, 8, 4, 2, 1.
- Subnetting is bit arithmetic dressed up as decimal numbers.
- Hex is a short way to write binary; one hex digit = 4 bits.