Skip to content
AgileLogics

Decimal to Octal

Converts a base-10 (decimal) number into its base-8 (octal) equivalent.

How it works

Enter a whole number (e.g. 8) and click Convert.

How do you convert decimal to octal?

Divide the number by 8, note the remainder, and keep dividing each quotient by 8 until you reach 0. The remainders, read in reverse order, form the octal number. Every remainder is between 0 and 7, which are the only digits base 8 uses. For example, 2024 divides down to remainders 0, 5, 7 and 3, so it is 3750 in octal.

Octal is less common than hex today, but it's still the standard notation for Unix file permissions, and that's where most people need this conversion.

Converting with the tool

  1. Type a whole number, like 420.
  2. Click Convert.
  3. Read the result: 644.

Spaces around the number are ignored. The output never has a prefix or padding.

Worked example: 2024

Division Quotient Remainder
2024 ÷ 8 253 0
253 ÷ 8 31 5
31 ÷ 8 3 7
3 ÷ 8 0 3

Read upward: 3750. Check: 3 × 512 + 7 × 64 + 5 × 8 + 0 = 1536 + 448 + 40 = 2024.

Decoding a file mode your code printed in decimal

This is the case that sends most developers looking for a decimal to octal converter. You call fs.statSync(path).mode in Node or os.stat(path).st_mode in Python, log it, and see a number like 33188 that means nothing. File modes are designed to be read in octal, where the low three digits are the permission bits and the higher digits encode the file type (inode(7) lists S_IFREG as 0100000 and S_IFDIR as 0040000).

Printed value Octal File type Permissions
33188 100644 regular file rw-r--r--
16877 40755 directory rwxr-xr-x
493 755 (permissions only) rwxr-xr-x
420 644 (permissions only) rw-r--r--
18 22 a umask of 022 removes write for group and others

Python can do this for you with oct(), which returns '0o100644' for 33188, and stat.filemode() turns the whole thing into -rw-r--r--. The converter is handy when you only have the number from a log line.

The leading-zero trap

The reverse mistake is just as common: writing chmod(path, 755) in code. Without an octal prefix that's decimal 755, which is octal 1363, giving a mode nobody intended. Write the literal in octal (0o755 in Python and JavaScript, 0755 in C) or pass the decimal equivalent, 493.

Languages disagree about bare leading zeros. C treats 0755 as octal. Python 3 rejects it outright as a syntax error (Python's integer literal rules) precisely to avoid this confusion.

Common conversions

Decimal Octal
7 7
8 10
64 100
83 123
292 444
438 666
511 777
1000 1750

Notice the pattern at 8 and 64: powers of eight become 1 followed by zeros, the same way powers of ten do in decimal.

Limits

  • Whole numbers from 0 to 9007199254740991 only; that maximum converts to 377777777777777777.
  • No negative numbers or fractions; both show "Enter a valid decimal number...".
  • No grouping or padding in the output, so add a leading 0 or 0o yourself when you paste the result into code.
  • An empty input simply clears the result.

Related tools

  • Binary to octal explains how each octal digit maps to a read/write/execute triplet.
  • Octal to hexadecimal is useful when comparing modes against a hex dump.
  • Decimal to binary shows every bit if you need to test individual permission flags.
  • The Rust lessons show the 0o, 0x and 0b integer literal prefixes alongside Rust's integer types.

Last updated

Frequently asked questions

How do you convert a decimal number to octal?
Divide by 8 and record the remainder (0 to 7). Divide the quotient by 8 again and repeat until the quotient is 0. The remainders read from last to first are the octal digits, so 2024 becomes 3750.
Why does my program print file permissions as 33188 or 493?
APIs such as Node's fs.stat and Python's os.stat return the mode as an ordinary integer, and printing it shows base 10. Convert it to octal to read it: 33188 is 100644 (a regular file with mode 644) and 493 is 755.
Does the result include an 0o prefix?
No, you get just the digits, such as 755. In Python 3 and modern JavaScript write 0o755 in source code. A bare leading zero like 0755 is a syntax error in Python 3.
Which inputs are rejected?
Anything that isn't a plain run of digits 0 to 9: negative numbers, decimals, commas, spaces inside the number and exponents like 1e3. Values above 9007199254740991 show "That number is too large to convert precisely."