Home / Encoding guides / Guide: octal numbers

Octal Numbers Explained

A clear introduction to base 8: how it works, how to convert it, and where it is still used.

What is the octal system?

Octal is a positional number system with a base of 8. It has eight digits, 0 to 7. After 7 comes 10, which means one eight and no ones, so octal 10 equals decimal 8.

Place values

From the right, the places are worth 1, 8, 64, 512 and so on, each eight times the one before. The octal number 345 means 3 x 64 + 4 x 8 + 5 = 229.

Counting in octal

Decimal 8 is 10, 9 is 11, 10 is 12, 15 is 17 and 16 is 20. There is no digit 8 or 9.

Converting

Octal and hexadecimal

Hexadecimal groups binary into fours and octal groups it into threes. Hex became the standard because bytes are 8 bits, which split evenly into two hex digits but not into whole octal digits.

Octal in Unix permissions

A permission digit adds read (4), write (2) and execute (1). So 7 is rwx, 6 is rw-, 5 is r-x, 4 is r--, and 0 is no access. The mode 755 gives the owner everything and everyone else read and execute.

chmod 755 script.sh

Octal in code

Many languages write octal literals with a leading 0, while Python 3 and modern JavaScript use the prefix 0o, as in 0o755. A stray leading zero in older code can change the meaning of a number, so check the rules of your language.

print(oct(493))        # 0o755
print(int("755", 8))   # 493

Try everything at once with the octal converter.

Convert instantly. Switch between octal, decimal, binary and hex, and work out chmod permissions.

Open the octal converter

Frequently asked questions

What is octal in simple terms?

A way of counting in eights, using only the digits 0 to 7.

Why is hex more common than octal?

Hex splits an 8-bit byte into two clean digits, while octal does not divide bytes evenly.

What does chmod 644 mean?

The owner can read and write, and everyone else can only read.