What is Octal? The Base-8 Number System Explained
Octal may be the most underrated number system in computing. It powers Unix file permissions, appears in programming language literals, and provides an elegant bridge between binary and human-readable numbers.
Table of Contents
What is Octal?
Octal (also called base-8) is a positional number system that uses eight digits: 0 through 7. Just as the decimal system you use daily has ten digits (0–9) and hexadecimal has sixteen (0–F), octal uses exactly eight.
In computing, octal numbers are typically prefixed with a 0 or 0o to distinguish them from decimal. For example, 0o17 in octal equals 15 in decimal.
While hexadecimal gets more attention today, octal has a unique strength: each octal digit maps perfectly to exactly 3 binary bits. This makes it an extraordinarily clean shorthand for binary, which is why it became the foundation of Unix file permissions and was the preferred base in early computing.
How Octal Works
Like any positional system, each digit's value depends on its position. In decimal, positions represent powers of 10. In octal, positions represent powers of 8:
| Position | Power of 8 | Decimal Value |
|---|---|---|
| Position 0 (rightmost) | 8⁰ | 1 |
| Position 1 | 8¹ | 8 |
| Position 2 | 8² | 64 |
| Position 3 | 8³ | 512 |
| Position 4 | 8⁴ | 4096 |
So the octal number 375 means:
3 × 8² = 3 × 64 = 192
+ 7 × 8¹ = 7 × 8 = 56
+ 5 × 8⁰ = 5 × 1 = 5
─────
253 (decimal)The Octal–Binary Connection
The reason octal is useful in computing comes down to one elegant fact: 8 = 2³. This means each octal digit represents exactly 3 binary bits, with no wasted space:
| Octal | Binary | Decimal |
|---|---|---|
| 0 | 000 | 0 |
| 1 | 001 | 1 |
| 2 | 010 | 2 |
| 3 | 011 | 3 |
| 4 | 100 | 4 |
| 5 | 101 | 5 |
| 6 | 110 | 6 |
| 7 | 111 | 7 |
This means you can convert between octal and binary digit by digit. No arithmetic needed — just substitute each octal digit with its 3-bit binary equivalent:
Octal: 7 5 3
Binary: 111 101 011
So octal 753 = binary 111101011
And going back:
Binary: 1 010 110 100
Octal: 1 2 6 4
So binary 1010110100 = octal 1264Converting Between Octal, Decimal, and Binary
Octal → Decimal
Multiply each digit by its power of 8 and add:
Octal 755:
7 × 8² = 7 × 64 = 448
5 × 8¹ = 5 × 8 = 40
5 × 8⁰ = 5 × 1 = 5
─────
493 (decimal)Decimal → Octal
Divide by 8 repeatedly and collect the remainders (read bottom to top):
Convert 493 to octal:
493 ÷ 8 = 61 remainder 5 ↑
61 ÷ 8 = 7 remainder 5 ↑ Read upward: 755
7 ÷ 8 = 0 remainder 7 ↑
493 decimal = 755 octal ✓Octal ↔ Binary
Simply substitute each octal digit with its 3-bit group (or vice versa):
Octal to Binary:
0o755 → 7=111 5=101 5=101 → 111 101 101
Binary to Octal:
110100011 → group by 3 from right: 110 100 011
6 4 3 → 0o643Octal in Unix File Permissions
This is where octal truly shines. Unix/Linux file permissions use three groups of three bits — one group each for the owner, group, and others. Each group has three permission flags:
| Permission | Symbol | Binary Bit | Octal Value |
|---|---|---|---|
| Read | r | 100 | 4 |
| Write | w | 010 | 2 |
| Execute | x | 001 | 1 |
Since each permission group is exactly 3 bits, one octal digit encodes all three permissions for one group. The classic chmod 755 breaks down as:
chmod 755 file.sh
7 = 4+2+1 = rwx → Owner: read + write + execute
5 = 4+0+1 = r-x → Group: read + execute
5 = 4+0+1 = r-x → Others: read + execute
Binary: 111 101 101
Symbol: rwx r-x r-xCommon permission patterns you'll see everywhere:
| Octal | Symbolic | Typical Use |
|---|---|---|
755 | rwxr-xr-x | Executables, scripts, directories |
644 | rw-r--r-- | Regular files, config files |
600 | rw------- | Private files (SSH keys, credentials) |
777 | rwxrwxrwx | Full access for everyone (avoid in production!) |
400 | r-------- | Read-only for owner (deployed secrets) |
Octal in Programming Languages
Most languages support octal literals, though the syntax varies:
JavaScript
// Modern octal (ES6+) — recommended
const permissions = 0o755; // 493 in decimal
const mask = 0o022; // 18 in decimal
// Parse octal string to number
parseInt("755", 8); // 493
// Convert decimal to octal string
(493).toString(8); // "755"
// ⚠️ Legacy: leading zero (strict mode forbids this)
// const old = 0755; // Don't use — ambiguous!Python
# Octal literal
permissions = 0o755 # 493 in decimal
# Convert decimal to octal string
oct(493) # '0o755'
# Parse octal string to int
int("755", 8) # 493
# Set file permissions
import os
os.chmod("script.sh", 0o755)C / C++
// Octal literals use a leading 0
int perms = 0755; // 493 in decimal
int mask = 022; // 18 in decimal
// Print in octal
printf("%o\n", 493); // Prints: 755
// ⚠️ Common bug:
int x = 010; // This is 8, NOT 10!⚠️ The Classic Octal Trap in C/C++
In C and C++, any number starting with 0 is interpreted as octal. This means 010 equals 8, not 10. It's one of the most common gotchas for beginners, especially when zero-padding numbers.
A Brief History of Octal
Octal has a deeper history than most people realize:
- Pre-computer era — Some cultures, including the Yuki people of Northern California, used base-8 counting systems (counting the spaces between fingers rather than the fingers themselves).
- 1950s–60s — Early computers like the IBM 7090 and PDP-8 used word sizes that were multiples of 3 bits (12, 18, 24, 36 bits), making octal a perfect fit. Programmers read memory dumps in octal.
- 1969 — Unix was created at Bell Labs.Ken Thompson and Dennis Ritchie chose octal for file permissions because the 9-bit permission model (rwx × 3 groups) maps naturally to three octal digits.
- 1970s onward — As 8-bit bytes became standard, hexadecimal (where each digit = 4 bits) started replacing octal for most purposes. But Unix permissions kept octal alive.
Octal vs Hexadecimal
Both are shorthand for binary, but they divide bits differently:
| Feature | Octal (Base-8) | Hexadecimal (Base-16) |
|---|---|---|
| Digits used | 0–7 | 0–9, A–F |
| Bits per digit | 3 | 4 |
| Best for | Permissions, 3-bit groups | Bytes, colors, memory addresses |
| 1 byte (8 bits) | 3 digits (with overflow) | 2 digits (perfect fit) |
| Modern usage | Unix permissions, some legacy code | Dominant in most contexts |
Hex won for general computing because modern hardware is byte-oriented (8 bits), and 8 bits divide evenly into two hex digits but not evenly into octal digits. However, for anything involving 3-bit groupings — especially Unix permissions — octal remains the natural choice.
Convert Octal Numbers Instantly
Use our free Octal Converter tool to convert between octal, decimal, binary, and hexadecimal — right in your browser with no data uploaded to any server.
Try Octal Converter →References
- Ritchie, D.M. & Thompson, K. (1974). The UNIX Time-Sharing System. Communications of the ACM, 17(7). https://dsf.berkeley.edu/cs262/unix.pdf
- IEEE & The Open Group. chmod — change the file modes. POSIX.1-2017. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/chmod.html
- Mozilla Developer Network. parseInt() — JavaScript. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
- Python Software Foundation. Built-in Functions: oct(). https://docs.python.org/3/library/functions.html#oct
- Knuth, D.E. (1997). The Art of Computer Programming, Volume 2: Seminumerical Algorithms. Addison-Wesley Professional.