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 to decimal: multiply each digit by its power of 8 and add. See the octal to decimal converter.
- Decimal to octal: divide by 8 repeatedly and read the remainders upward. See the decimal to octal converter.
- Octal and binary: swap each digit for three bits. See the octal to binary converter.
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.shOctal 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)) # 493Try everything at once with the octal converter.
Convert instantly. Switch between octal, decimal, binary and hex, and work out chmod permissions.