Decimal to octal, explained with Unix permissions
This decimal to octal converter rewrites base-10 numbers using only the digits 0–7. Octal is less common than hex today, but it is still the native language of Unix file permissions and of octal escape sequences, so it pays to be able to move between the two quickly.
How octal works
Each octal position is worth eight times the one to its right: 1, 8, 64, 512, 4096. Since 8 = 2^3, one octal digit always stands for exactly three bits, which is what makes it so convenient for permissions.
Repeated division by 8
Divide by 8, keep the remainder, and repeat with the quotient. Read the remainders from last to first.
493 ÷ 8 = 61 remainder 5
61 ÷ 8 = 7 remainder 5
7 ÷ 8 = 0 remainder 7
493 = 755 in octal
Fractions use multiplication instead: 0.75 × 8 = 6, so 3.75 becomes 3.6. Repeating fractions are cut off after 20 octal places.
Example
Input Output
10 12
255 377
420 644
493 755
33188 100644
3.75 3.6
Why you might have a permission in decimal
Many APIs report a file's mode as a plain integer. Python's os.stat() and Node's fs.statSync() give st_mode values such as 33188, and JSON has no octal literals at all. Converting 33188 gives 100644: the leading 100 marks a regular file and 644 is the permission part, read as rw-r--r--.
Likewise, 493 is 755 (rwxr-xr-x), the usual mode for executables and directories, and 420 is 644, the usual mode for ordinary files.
The classic chmod mistake
Passing permissions as a decimal number is one of the most common bugs in scripts. In Python, os.chmod(path, 755) looks right but 755 is read as decimal, and decimal 755 is octal 1363:
755 ÷ 8 = 94 remainder 3
94 ÷ 8 = 11 remainder 6
11 ÷ 8 = 1 remainder 3
1 ÷ 8 = 0 remainder 1
755 (decimal) = 1363 (octal) → sticky bit, -wx rw- -wx
The file ends up with the sticky bit set and nonsense permissions. Write 0o755 in Python and in Node's fs.chmodSync(), or the decimal 493 if an API only takes plain integers. The same trap exists when parsing: in JavaScript, parseInt('755', 8) returns 493, while parseInt('0755') returns 755 because a leading zero no longer means octal.
Other places octal appears
- Escape sequences: in C, shells and many other languages,
\033is the escape character, decimal 27. - Number literals: Python 3 and modern JavaScript write octal as
0o755; C still uses a leading zero (0755). - Teaching: octal is a gentle introduction to bases before hexadecimal.
Tips
The result never carries a prefix, so add the one your language expects. Negative numbers keep a minus sign, and integers of any size convert exactly. To go back, use octal to decimal; to see all bases at once, open the all number converter. If you want to see the three bits behind each digit, decimal to binary shows the full bit pattern.