PHP octdec() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

In PHP, octdec() converts an octal (base 8) number to a decimal (base 10) number.

Octal uses only the digits 0 to 7. You pass the octal number as a string, and PHP gives you the normal decimal number back.

Syntax

Call octdec() with the values you need. Start with this line.

PHP
$decimal = octdec("755");
CallWhat it does
octdec("17")Returns 15.
octdec("777")Returns 511.
octdec("10")Returns 8.

Octal numbers are often seen in Unix file permissions such as 755 or 644. The reverse function is decoct(), which converts decimal to octal.

Library declarations
PHP
octdec(string $octal_string): int|float

Parameters

ParameterDescription
octal_stringRequired. The octal number as a string. Only the digits 0 to 7 are valid.

Return Value

Return ValueDescription
intThe decimal value of the octal string.
floatA float is returned when the result is larger than PHP_INT_MAX.

PHP Examples

Example 1 — Convert Octal to Decimal

Pass an octal string to octdec() and get a decimal number back.

PHP
<?php
echo octdec("17"), PHP_EOL;
echo octdec("777"), PHP_EOL;
echo octdec("10"), PHP_EOL;

How It Works

  1. octdec("17") calculates 1 x 8 + 7, which is 15.
  2. octdec("777") calculates 7 x 64 + 7 x 8 + 7, which is 511.
  3. octdec("10") calculates 1 x 8 + 0, which is 8.
  4. Each result is a normal decimal integer.

Example 2 — Leading Zeros in Permissions

File permissions are often written with a leading zero. octdec() handles them fine.

PHP
<?php
echo octdec("0755"), PHP_EOL;
echo octdec("0644"), PHP_EOL;
echo octdec("0"), PHP_EOL;

How It Works

  1. The leading 0 in "0755" does not change the value.
  2. 0755 in octal is 7 x 64 + 5 x 8 + 5, which is 493.
  3. 0644 in octal is 6 x 64 + 4 x 8 + 4, which is 420.
  4. octdec("0") returns 0.

Example 3 — Round Trip with decoct()

decoct() turns a decimal number into octal, and octdec() turns it back.

PHP
<?php
$mode = decoct(493);

echo "Octal: ", $mode, PHP_EOL;
echo "Decimal: ", octdec($mode), PHP_EOL;

How It Works

  1. decoct(493) converts the decimal number to the octal string "755".
  2. Print the octal value.
  3. octdec($mode) converts the string back to decimal.
  4. The final result is 493, the number we started with.

Frequently Asked Questions

octdec() converts an octal (base 8) string to a decimal (base 10) number.
Use decoct(), for example decoct(8) returns "10". It is the reverse of octdec().
Octal numbers are best handled as strings because they can be long. PHP also accepts an integer, but it converts it to a string first.
Digits 8 and 9, and other characters, are ignored. PHP 7.4 and later also shows a deprecation notice, so clean your input first.
Yes. octdec("755") gives 493. For chmod() you can also write the octal literal directly as 0755 in your code.

Next: pi()

pi() returns an approximate value of the mathematical constant pi (3.14159...).

pi() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful