X Xerobit

Octal Converter — Convert Between Octal, Decimal, Binary, and Hex

Octal is base-8, using digits 0–7. It's used in Unix file permissions and legacy systems. Here's how octal conversion works, the relationship to binary, and common octal values.

Mian Ali Khalid · · 5 min read
Use the tool
Number Base Converter
Convert between binary, octal, decimal, hexadecimal, and text (UTF-8). Handles arbitrary lengths. Per-byte and per-character views.
Open Number Base Converter →

Octal is the base-8 number system, using digits 0–7. Each octal digit represents exactly 3 binary bits, making it a compact way to express binary values that was popular before hexadecimal became dominant. Today, octal is mainly encountered in Unix file permissions and occasionally in legacy code.

Use the Number Base Converter to convert between octal, decimal, binary, and hexadecimal.

How octal works

Octal uses powers of 8, just as decimal uses powers of 10 and binary uses powers of 2:

Position: 3    2    1    0
Power:    8³   8²   8¹   8⁰
Value:    512  64   8    1

Octal 745:

7 × 64 = 448
4 × 8  =  32
5 × 1  =   5
Total  = 485 (decimal)

Octal digits: 0, 1, 2, 3, 4, 5, 6, 7. The digits 8 and 9 don’t exist in octal.

Octal to decimal conversion

Multiply each digit by its positional value:

Octal 357:
3 × 8² = 3 × 64 = 192
5 × 8¹ = 5 × 8  =  40
7 × 8⁰ = 7 × 1  =   7
Total = 239 (decimal)

Quick mental math: each octal digit position is 1, 8, 64, 512, 4096…

Decimal to octal conversion

Divide by 8 repeatedly, collect remainders from bottom to top:

Convert 239 to octal:

239 ÷ 8 = 29 remainder 7
 29 ÷ 8 =  3 remainder 5
  3 ÷ 8 =  0 remainder 3

Read remainders bottom-to-top: 357

239 decimal = 357 octal

The binary-octal shortcut

Every 3 binary digits equal 1 octal digit (since 2³ = 8). This makes octal conversion from binary trivial:

Binary: 110 111 101
        ↓   ↓   ↓
Octal:   6   7   5  →  675

Binary: 001 010 011
Octal:   1   2   3  →  123
Octal digit | Binary
    0       | 000
    1       | 001
    2       | 010
    3       | 011
    4       | 100
    5       | 101
    6       | 110
    7       | 111

Octal in Unix file permissions

The most common use of octal in modern computing is Unix file permissions. Each permission group (owner, group, others) is 3 bits: read (4), write (2), execute (1).

Permission: rwxrwxrwx
Binary:     111 111 111
Octal:       7   7   7  = 777 (full permissions for all)

Permission: rwxr-xr-x
Binary:     111 101 101
Octal:       7   5   5  = 755 (owner full, group/others read+execute)

Permission: rw-r--r--
Binary:     110 100 100
Octal:       6   4   4  = 644 (owner read+write, others read only)

Permission: rw-------
Binary:     110 000 000
Octal:       6   0   0  = 600 (owner read+write, no access for others)

Common permission combinations:

  • 777 — full access for everyone (avoid for security)
  • 755 — executable: owner can modify, others can read and run
  • 644 — files: owner can modify, others can read
  • 700 — private directory: only owner can access
  • 600 — private file: only owner can read/write
  • 666 — world-writable: dangerous, avoid
  • 400 — read-only (even for owner, no write)
# Set file permissions using octal:
chmod 755 script.sh
chmod 644 config.json
chmod 600 ~/.ssh/id_rsa  # SSH private key must be 600

Octal in programming languages

Octal literals in code use a leading 0 (old C style) or 0o prefix (modern):

// JavaScript:
const octal = 0o755;  // Modern syntax (ES6+)
console.log(octal);   // 493 (decimal)

// Old syntax (deprecated, avoid):
// const old = 0755;  // 493 — confusing, looks like decimal

// Convert decimal to octal string:
console.log((493).toString(8));  // "755"

// Parse octal string to decimal:
console.log(parseInt('755', 8));  // 493
# Python:
octal = 0o755
print(octal)       # 493

# Convert to octal string:
print(oct(493))    # '0o755'
print(oct(493)[2:]) # '755'  (strip '0o' prefix)

# Parse octal string:
print(int('755', 8))  # 493
// C:
int perms = 0755;  // Octal literal — leading zero!
chmod("file.txt", 0755);  // POSIX chmod uses octal

The leading-zero bug: In C and older JavaScript, a number starting with 0 is octal. 010 is 8, not 10. This trips up developers who pad numbers: 08 is a syntax error in old JavaScript (8 is not a valid octal digit).

Octal in other contexts

Escape sequences: Some languages use octal in string escape sequences:

print('\101')  # Python: octal escape → 'A' (ASCII 65)

IP address classes (historical): Old-style UNIX commands displayed IP addresses in octal. This is obsolete but you may encounter it in very old documentation.

C standard library: open(), mkdir(), and chmod() take permission modes as octal constants.

Octal vs hexadecimal

Both octal and hexadecimal are used to make binary more readable. Hexadecimal is now dominant because:

  • 1 hex digit = 4 bits (one nibble)
  • 2 hex digits = 8 bits (one byte)
  • This aligns naturally with byte boundaries
  • Modern CPUs work in 8/16/32/64-bit chunks, which divide cleanly into hex

Octal aligns with 6-bit and 12-bit values (e.g., 12-bit permissions = 4 octal digits) — useful for the 9-bit file permissions, less useful for modern architecture.


Related posts

Related tool

Number Base Converter

Convert between binary, octal, decimal, hexadecimal, and text (UTF-8). Handles arbitrary lengths. Per-byte and per-character views.

Written by Mian Ali Khalid. Part of the Encoding & Crypto pillar.