/7 min read

What is Octal? The Base-8 Number System Explained

Octal is one of the most practical number systems in computing. It powers Unix file permissions, appears in programming language literals, and gives humans a compact way to read groups of binary bits.

What is Octal?

Octal, also called base-8, is a positional number system that uses exactly eight digits: 0 through 7. It works like decimal, but each place is based on powers of 8 instead of powers of 10.

In computing, octal values are often written with a 0o prefix so they are not confused with decimal numbers. For example, 0o17 in octal equals 15 in decimal.

Octal is useful because each octal digit maps to exactly 3 binary bits. That clean relationship made octal popular in early computing and keeps it important today in Unix file permissions.

How Octal Works

Like any positional number system, each digit gets its value from its position. In octal, the positions are powers of 8:

PositionPower of 8Decimal Value
Position 0, rightmost8^01
Position 18^18
Position 28^264
Position 38^3512
Position 48^44096

So the octal number 375 means:

  3 x 8^2 = 3 x 64 = 192
+ 7 x 8^1 = 7 x 8  =  56
+ 5 x 8^0 = 5 x 1  =   5
                     -----
                       253  (decimal)

The Octal-Binary Connection

The reason octal is so convenient in computing is simple: 8 = 2^3. One octal digit represents one group of three binary bits:

OctalBinaryDecimal
00000
10011
20102
30113
41004
51015
61106
71117

That means you can convert between octal and binary digit by digit. No long arithmetic is required:

Octal:   7   5   3
Binary: 111 101 011

So octal 753 = binary 111101011

And going back:
Binary: 1 010 110 100
Octal:  1   2   6   4

So binary 1010110100 = octal 1264

Converting Between Octal, Decimal, and Binary

Octal to Decimal

Multiply each digit by its power of 8, then add the results.

Octal 755:
  7 x 8^2 = 7 x 64 = 448
  5 x 8^1 = 5 x 8  =  40
  5 x 8^0 = 5 x 1  =   5
                    -----
                      493  (decimal)

Decimal to Octal

Divide by 8 repeatedly and collect the remainders. Read the remainders from bottom to top.

Convert 493 to octal:
  493 / 8 = 61 remainder 5
   61 / 8 =  7 remainder 5
    7 / 8 =  0 remainder 7

Read the remainders upward: 755
493 decimal = 755 octal

Octal and Binary

Replace each octal digit with its 3-bit binary group, or group binary digits into sets of 3 from the right.

Octal to Binary:
  0o755 -> 7=111  5=101  5=101 -> 111 101 101

Binary to Octal:
  110100011 -> group by 3 from right: 110 100 011
                                       6   4   3 -> 0o643

Octal in Unix File Permissions

Unix and Linux file permissions are where octal really shines. Permissions are stored as three groups of three bits: one group for the owner, one for the group, and one for everyone else.

PermissionSymbolBinary BitOctal Value
Readr1004
Writew0102
Executex0011

Because each permission group is exactly 3 bits, one octal digit represents one full permission group. The classic chmod 755 breaks down like this:

chmod 755 file.sh

  7 = 4+2+1 = rwx  -> Owner:  read + write + execute
  5 = 4+0+1 = r-x  -> Group:  read + execute
  5 = 4+0+1 = r-x  -> Others: read + execute

Binary: 111 101 101
Symbol: rwx r-x r-x

Common permission patterns you will see often:

OctalSymbolicTypical Use
755rwxr-xr-xExecutables, scripts, directories
644rw-r--r--Regular files and config files
600rw-------Private files such as SSH keys
777rwxrwxrwxFull access for everyone, usually avoid in production
400r--------Read-only for owner, deployed secrets

Octal in Programming Languages

Many programming languages support octal literals, but the syntax differs:

JavaScript

// Modern octal (ES6+) - recommended
const permissions = 0o755;   // 493 in decimal
const mask = 0o022;          // 18 in decimal

// Parse octal string to number
parseInt("755", 8);          // 493

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

// Legacy leading-zero octal is confusing
// const old = 0755;  // Avoid this pattern

Python

# Octal literal
permissions = 0o755       # 493 in decimal

# Convert decimal to octal string
oct(493)                  # '0o755'

# Parse octal string to int
int("755", 8)             # 493

# Set file permissions
import os
os.chmod("script.sh", 0o755)

C / C++

// Octal literals use a leading 0
int perms = 0755;    // 493 in decimal
int mask  = 022;     // 18 in decimal

// Print in octal
printf("%o\n", 493);  // Prints: 755

// Common bug:
int x = 010;  // This is 8, not 10

The classic octal trap in C/C++

In C and C++, a number starting with 0 is interpreted as octal. That means 010 equals 8, not 10. This can surprise beginners and cause bugs when numbers are padded with leading zeroes.

A Brief History of Octal

Octal has a longer history than many developers expect:

  • Before computers - some cultures used base-8 counting systems, including counting spaces between fingers instead of the fingers themselves.
  • 1950s and 1960s - early machines with word sizes such as 12, 18, 24, and 36 bits made octal a natural fit because those sizes divide cleanly into 3-bit groups.
  • Unix era - Unix used a 9-bit permission model, three permission bits for each of owner, group, and others. Three octal digits represented that model perfectly.
  • Modern computing - hexadecimal became more common as 8-bit bytes dominated, but octal stayed alive anywhere 3-bit groups are natural.

Octal vs Hexadecimal

Octal and hexadecimal are both compact ways to write binary, but they group bits differently:

FeatureOctal (Base-8)Hexadecimal (Base-16)
Digits used0-70-9 and A-F
Bits per digit34
Best forPermissions and 3-bit groupsBytes, colors, memory addresses
1 byte, 8 bits3 digits with padding or overflow2 digits, perfect fit
Modern usageUnix permissions and legacy codeDominant in most low-level contexts

Hexadecimal won for general low-level computing because a byte is 8 bits and fits exactly into two hex digits. But for 3-bit groupings, especially Unix permissions, octal remains the natural and readable choice.

Convert Octal Numbers Instantly

Use our free Octal Converter tool to convert between octal, decimal, binary, and hexadecimal right in your browser.

Try Octal Converter

References

  1. Ritchie, D.M. & Thompson, K. (1974). The UNIX Time-Sharing System. Communications of the ACM, 17(7). https://dsf.berkeley.edu/cs262/unix.pdf
  2. IEEE & The Open Group. chmod - change the file modes. POSIX.1-2017. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/chmod.html
  3. Mozilla Developer Network. parseInt() - JavaScript. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/parseInt
  4. Python Software Foundation. Built-in Functions: oct(). https://docs.python.org/3/library/functions.html#oct
  5. Knuth, D.E. (1997). The Art of Computer Programming, Volume 2: Seminumerical Algorithms. Addison-Wesley Professional.
USTHJP