Binary and Number Systems¶
From AWS Re/Start (June 2025) — the foundation underneath IP addresses, permissions, and everything digital.
Ultra-Short Summary¶
Everything in computing is binary (base 2) at the lowest level. Understanding binary lets you decode IP addresses, subnet masks, file permissions, and bit flags. Hexadecimal (base 16) is a shorthand that makes long binary strings readable. These are not abstract maths — they show up directly in AWS work.
Number Systems¶
| System | Base | Digits Used | Example |
|---|---|---|---|
| Binary | 2 | 0, 1 | 1010 |
| Decimal | 10 | 0-9 | 10 |
| Hexadecimal | 16 | 0-9, A-F | 0xA |
| Octal | 8 | 0-7 | 012 |
Why hex? One hex digit = exactly 4 bits. Two hex digits = one byte. Hex makes binary compact:
Binary — How It Works¶
Each position is a power of 2, doubling left to right:
Converting Binary to Decimal¶
Binary: 1 1 0 0 1 0 1 0
|_|_|_|_|_|_|_|
128+64+0+0+8+0+2+0 = 202
Binary: 1 0 1 0 1 0 1 0
128+0+32+0+8+0+2+0 = 170
Converting Decimal to Binary¶
Repeatedly divide by 2, record remainders (read bottom to top):
Convert 42 to binary:
42 / 2 = 21 remainder 0
21 / 2 = 10 remainder 1
10 / 2 = 5 remainder 0
5 / 2 = 2 remainder 1
2 / 2 = 1 remainder 0
1 / 2 = 0 remainder 1
Read remainders bottom to top: 101010
Verify: 32 + 8 + 2 = 42 ✓
Why This Matters for IP Addresses¶
An IPv4 address is 32 bits — 4 groups of 8 bits (octets):
192 . 168 . 1 . 100
11000000 . 10101000 . 00000001 . 01100100
Convert 192 to binary:
128 + 64 = 192
= 11000000
Convert 168 to binary:
128 + 32 + 8 = 168
= 10101000
Subnet Mask — Binary AND¶
CIDR notation uses binary AND to separate network from host:
IP: 192.168.1.100 = 11000000.10101000.00000001.01100100
Mask: 255.255.255.0 = 11111111.11111111.11111111.00000000
────────────────────────────────────
AND: 11000000.10101000.00000001.00000000
= 192.168.1.0 (network address)
The 0s in the mask mark the host bits -- everything in .0 to .255 is on this network
CIDR /24 Means¶
/24 = 24 network bits + 8 host bits
= 11111111.11111111.11111111.00000000
= 255.255.255.0
Available addresses: 2^8 = 256 (0-255)
Usable hosts: 254 (subtract network address .0 and broadcast .255)
File Permissions in Binary¶
Linux chmod permissions are 3-bit binary per user group:
chmod 755 file.sh
7 = 111 = rwx (owner: read + write + execute)
5 = 101 = r-x (group: read + execute, no write)
5 = 101 = r-x (other: read + execute, no write)
chmod 600 key.pem
6 = 110 = rw- (owner: read + write, no execute)
0 = 000 = --- (group: nothing)
0 = 000 = --- (other: nothing)
Each permission is a bit:
- r (read) = 4 = 100
- w (write) = 2 = 010
- x (execute) = 1 = 001
Add them together: rwx = 4+2+1 = 7.
Hexadecimal in Practice¶
Where you'll see hex:
MAC addresses: 00:1A:2B:3C:4D:5E
Colour codes: #FF5733 = RGB(255, 87, 51)
Memory addresses: 0x7FFF5FBFF8C8
Git commit hashes: 3a4b5c6d
S3 ETags (MD5): d41d8cd98f00b204e9800998ecf8427e
Hex to Decimal¶
Each position is a power of 16:
0xFF = (15 * 16^1) + (15 * 16^0) = 240 + 15 = 255
0x10 = (1 * 16^1) + (0 * 16^0) = 16 + 0 = 16
0x1A = (1 * 16) + 10 = 26
Hex digits A-F = 10-15 in decimal.
Bitwise Operations¶
Operations on individual bits — used in networking, security, and low-level programming:
AND (&): Both bits must be 1
1010 & 1100 = 1000
OR (|): Either bit must be 1
1010 | 1100 = 1110
XOR (^): Bits must differ
1010 ^ 1100 = 0110
NOT (~): Flip all bits
~1010 = 0101
Left shift (<<): Multiply by 2 per shift
0001 << 3 = 1000 (1 -> 8)
Right shift (>>): Divide by 2 per shift
1000 >> 2 = 0010 (8 -> 2)
Subnet mask calculation uses AND: IP AND MASK = NETWORK ADDRESS.
Powers of 2 — Worth Memorising¶
2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
2^7 = 128
2^8 = 256
2^10 = 1,024 (1 KB)
2^16 = 65,536 (a /16 VPC has this many IPs)
2^20 = 1,048,576 (1 MB)
2^30 = 1,073,741,824 (1 GB)
2^32 = 4,294,967,296 (total IPv4 addresses)
Mental Model¶
Binary = the language of hardware
Transistors are switches -- on (1) or off (0)
Everything complex is patterns of 1s and 0s at scale
Hex = binary for humans
Too tedious to read 32-bit addresses in binary
Hex groups 4 bits at a time -- more compact, still exact
Subnet maths = binary AND in disguise
A /24 mask is 24 ones followed by 8 zeros
AND with the IP gives the network address
Permissions = 3 bit flags per user class
rwx = 111 = 7
r-x = 101 = 5
rw- = 110 = 6
Self-Quiz¶
- Convert 192 to binary. Show your working.
- What is
11001100in decimal? - Convert
0xFFfrom hex to decimal. - A subnet mask is
/26— what is it in dotted decimal? How many hosts? chmod 644— what are the permissions for owner, group, other?- Why is hexadecimal useful for representing binary data?
192.168.1.50 AND 255.255.255.0— what is the result and what does it represent?- How many total IPv4 addresses exist, and why?