Article — Decimal to Octal Converter
The Decimal to Octal Converter
Octal is the base-8 number system with digits 0–7. The decimal to octal conversion is repeated division by 8, reading remainders bottom-up. 64 decimal becomes 100 octal; 493 decimal becomes 755 octal (the Unix chmod value for rwxr-xr-x). Each octal digit encodes exactly three bits.
Octal survives in modern computing mostly through Unix file permissions and a handful of escape sequences in older programming languages. Hexadecimal long ago took over from octal for byte-level work, but octal still hangs on where the three-bit grouping happens to match real-world structures — and chmod is the canonical case.
What is octal?
Octal is a positional number system with eight digits (0, 1, 2, 3, 4, 5, 6, 7). The right-most column is the 1s column, the next is the 8s column, the next the 64s column, the next the 512s column, and so on — each position is a power of 8.
Octal aligned naturally with the early generations of computers that used 12-, 24-, or 36-bit words, because those word sizes divide cleanly by 3. One octal digit covers three bits, so a 36-bit word is exactly 12 octal digits. Modern byte-oriented machines (8, 16, 32, 64 bits) divide by 4 rather than 3, which is why hex took over.
The PDP-8, one of the most popular minicomputers ever made (over 50,000 sold from 1965 onward), used 12-bit words and was documented entirely in octal. Programmers wrote octal machine code by hand, and the indicator lights on the front panel were arranged in groups of three to match the octal digits.
The decimal to octal algorithm
The standard algorithm is repeated division by 8.
step 1 divide N by 8, keep remainderstep 2 repeat on quotient until 0step 3 read remainders bottom-upstep 4 all remainders are 0–7Worked example with 342 decimal: 342 ÷ 8 = 42 r 6; 42 ÷ 8 = 5 r 2; 5 ÷ 8 = 0 r 5. Reading bottom-up gives 526 octal. Check: 5 × 64 + 2 × 8 + 6 = 320 + 16 + 6 = 342. The same algorithm scales to any non-negative integer.
Octal to decimal (positional sum)
The reverse is a positional sum. From right to left, position values are 1, 8, 64, 512, 4,096, 32,768, 262,144 (the powers of 8). Multiply each digit by its position value and add.
Worked example with 755 octal: 7 × 64 + 5 × 8 + 5 × 1 = 448 + 40 + 5 = 493 decimal. Same with 1234 octal: 1 × 512 + 2 × 64 + 3 × 8 + 4 × 1 = 512 + 128 + 24 + 4 = 668 decimal. The full algorithm is identical to the decimal interpretation everyone learns in school — only the base differs.
Octal in Unix chmod permissions
Unix permissions are the headline use case for octal today. Each file has nine permission bits — read, write, execute for the owner, group, and others. Three bits per group map exactly to one octal digit (0–7). The full set fits in three octal digits.
The digit values translate directly: 7 = rwx (4 + 2 + 1), 6 = rw- (4 + 2), 5 = r-x (4 + 1), 4 = r-- (4), and so on. Memorising those eight combinations covers nearly every chmod you will ever need to read or write.
- 7 = rwx — full access
- 6 = rw- — read and write, no execute
- 5 = r-x — read and execute, no write
- 4 = r-- — read only
- 3 = -wx — write and execute (rare)
- 2 = -w- — write only (rare)
- 1 = --x — execute only (special case)
- 0 = --- — no access
Octal in C, Python, and shell
Programming languages handle octal literals in three styles. Old C and shell use a plain leading zero (0755). Python 3 and modern C/C++ use the 0o prefix (0o755). A few older Pascal-style languages used a trailing letter or another marker. The leading-zero style remains the most common in shell scripts and historic C, but it is the most error-prone — typing 0755 thinking decimal gives you 493.
Octal also shows up in C/Python escape sequences. A backslash followed by one to three octal digits inside a string literal stands for the byte with that value. "\101" is the letter A (octal 101 = decimal 65 = ASCII A). The same idea works in Python 2 and Bash echo. Modern code more often uses \x (hex) or \u (Unicode) for the same purpose.
If you find yourself converting between chmod permissions and bit patterns often, memorise the eight combinations once. After that you read chmod 755 as 111-101-101 by eye, and you can write any permission set without consulting a table.
Octal vs hexadecimal — which to use
For byte-level work, hex wins. A byte (8 bits) is exactly two hex digits (00–FF), but it spans three octal digits (000–377) and wastes a third of the third digit. Modern memory dumps, colour codes, network protocols, and crypto values all use hex for that reason.
Octal wins only when the underlying structure is naturally divisible by 3. Unix permissions are the textbook case. A few legacy file formats and embedded systems also use octal. Outside those niches, hex is the default modern radix.
A short history of octal in computing
Octal dominated computing documentation from the 1950s through the 1970s. The IBM 704 and 709 (36-bit), the CDC 6600 (60-bit), the PDP-7, PDP-8, and PDP-10 series (12-, 18-, and 36-bit) all used octal as the standard radix for memory addresses, machine code listings, and front-panel toggles. Whole generations of programmers learned octal first and decimal second.
The shift to byte-oriented machines began with the IBM System/360 in 1964, which standardised on 8-bit bytes and 32-bit words. Hex maps to bytes; octal does not. By the mid-1970s most new systems documented memory in hex, and octal retreated to the few applications where three-bit grouping still made sense.
Common decimal to octal mistakes
Most octal errors are about prefix handling and digit range.
- leading zero in C — 0755 is octal 493 decimal, not decimal 755
- using digits 8 or 9 — only 0–7 are valid octal digits
- treating chmod as decimal — chmod 755 is octal; chmod 1755 in decimal means something else entirely
- mixing 0o with 0 prefix — Python 3 requires 0o; bare leading zero is a syntax error
- letting any digit exceed 7 — 8 in octal is invalid; the next value after 7 is 10 (octal)
- byte alignment — 1 byte is not 1 octal digit; you need three octal digits (000–377) to span a byte's 0–255 range
Setting chmod 777 grants full read/write/execute access to everyone on the system. It is the simplest way to fix "permission denied" errors and the simplest way to introduce a security hole. Default to 644 for files and 755 for directories and executables. Use 777 only as a deliberate, scoped choice — never as a fix-all.