Octal System Guide
Octal Number System
The octal system uses 8 digits: 0-7. Each octal digit represents exactly 3 binary bits. That's why 64₁₀ = 100₈. Historically used in UNIX/Linux file permissions (chmod 755 = rwxr-xr-x) and memory addressing in older 8-bit systems.
File Permissions in Linux
Linux access rights (chmod) use 3 octal digits: owner, group, others. Each digit is the sum of permissions: read=4, write=2, execute=1. For example chmod 755 = rwxr-xr-x (7=r+w+x, 5=r+x, 5=r+x). chmod 644 = rw-r--r--.
Practical Applications
File permissions: chmod 400 (read only), chmod 755 (full), chmod 600 (private). Used rarely in Python and Java. In older IBM System/360 used for disk addressing. Conversion: 64₁₀ = 100₈, 255₁₀ = 377₈.
Octal survives because 755 is exactly nine permission bits
Octal has almost vanished from computing, with one conspicuous exception: Unix file permissions. That is not habit. Three permission flags fit exactly into one octal digit, and three classes of user make nine bits — so a mode is precisely three digits, with no padding and nothing left over.
How it works
- Converts between octal, decimal, binary and hexadecimal.
- Reads file permission modes, where each digit encodes read, write and execute for one class.
- Makes the three-bits-per-digit correspondence visible, which is the whole reason the notation persists.
1 octal digit = 3 bits = 8 values (0–7) permissions: r = 4, w = 2, x = 1 7 = 4+2+1 = rwx 5 = 4+0+1 = r-x 6 = 4+2+0 = rw- mode = owner digit, group digit, other digit → 9 bits, 512 possible modes
Worked example
Reading the common modes as their symbolic equivalents.
- 755 → rwxr-xr-x, the usual mode for a directory or executable
- 644 → rw-r--r--, the usual mode for a file
- 600 → rw-------, readable only by its owner
- 777 → rwxrwxrwx, writable by anyone
Each digit is independently the sum of 4, 2 and 1. 755 grants the owner everything and gives group and others read and execute but not write — which is why it is the default for anything that needs to be run or entered but not modified.
Reading the result
- 777 is almost always a mistake. It permits any user on the system to modify the file, and it is usually reached for when a permission problem is not understood rather than when world-write is genuinely wanted.
- A directory needs execute to be entered at all. Read on a directory lists its names; execute allows access to what is inside. That is why 644 on a directory produces the confusing situation of seeing filenames you cannot open.
- The umask subtracts rather than sets. With the common umask of 022, a new file starts from 666 and becomes 644, while a new directory starts from 777 and becomes 755 — which is exactly where those two familiar modes come from.
- A fourth leading digit sets setuid, setgid and the sticky bit — 4755 rather than 755. It is rarely needed and worth understanding before it is used, since setuid on the wrong binary is a genuine privilege-escalation hazard.
Common questions
- Why octal rather than hex for permissions?
- Because permissions come in groups of three bits and octal is exactly three bits per digit. Hex would split a three-bit group across digit boundaries, so the tidy one-digit-per-class mapping would be lost.
- What should I actually use?
- 644 for ordinary files, 755 for directories and executables, 600 for anything containing secrets such as keys or credentials. Reach past those only when you can say precisely which additional access you are granting and to whom.