Decimal to octal: the base hiding behind file permissions
What this conversion does
It writes a base 10 number in base 8, using the digits 0 to 7. Octal has largely retreated to a few niches, but one of those niches is very busy: Unix file permissions, where a mask such as 755 or 644 is octal and is read as three independent digits rather than as a single number.
Three bits per digit, which is the whole point
One octal digit covers exactly three binary digits, so a nine-bit permission field splits neatly into three groups: owner, group and others. That is why the notation stuck for permissions long after it stopped being used for arithmetic. Each group is built from 4 for read, 2 for write and 1 for execute, so a 7 means all three and a 5 means read plus execute.
Decimal to octal conversion table
The decimal values behind the file modes and small masks you meet most often. The permission rows are worth learning by sight, since chmod takes the octal form and reports take the decimal one.
| Decimal | Octal |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 7 | 7 |
| 8 | 10 |
| 10 | 12 |
| 15 | 17 |
| 16 | 20 |
| 31 | 37 |
| 64 | 100 |
| 100 | 144 |
| 127 | 177 |
| 200 | 310 |
| 255 | 377 |
| 1000 | 1750 |
Where octal came from and where it survives
Octal was a natural fit for machines with word sizes that were multiples of three bits, and early minicomputers such as the PDP-8 were built that way. When 8-bit bytes and 16-bit words became standard, hexadecimal took over because four divides eight and three does not. File permissions are the main survivor, kept alive by decades of habit and by the fact that three permission bits divide perfectly by three.
Reading a permission digit
Treat each octal digit of a mode as a small sum: 4 is read, 2 is write and 1 is execute, added together for the digit you see. So 755 is read-write-execute for the owner, then read-execute for group and others, and 644 is read-write for the owner and read-only for everyone else.
Frequently asked questions
How do I convert a decimal number to octal by hand?
Divide by 8 and record the remainder, then repeat with the quotient until it reaches zero, and read the remainders from last to first. For 493: 493 ÷ 8 is 61 remainder 5, 61 ÷ 8 is 7 remainder 5, and 7 ÷ 8 is 0 remainder 7, giving 755.
Why are file permissions written in octal?
Because three permission bits per class of user divide exactly into one octal digit, so the whole mode reads as three short digits instead of nine bits. 755 means read-write-execute, then read-execute, then read-execute — a format you can decode without any arithmetic.
What does chmod 755 actually grant?
The owner may read, write and execute; group members and everyone else may read and execute but not modify. In decimal that is 493. Directories use the same three bits with a different meaning for execute, which is why a directory usually needs it set to be entered at all.
Is octal still used for anything else?
Occasionally. Some languages let you write octal literals with a leading zero, and a few file formats and network masks use it. Outside those cases hexadecimal has replaced it, because a byte splits cleanly into two hex digits whereas three does not divide eight.
Can this handle negative values and fractions?
Yes to both. A negative number keeps its sign in front of the octal digits, which is a sign-and-magnitude form rather than two's complement. Fractions convert digit by digit, and if the expansion does not terminate the result is marked as truncated rather than being rounded without comment.