PHP pow() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

In PHP, pow() raises a number to a power. For example, pow(2, 3) means 2 x 2 x 2, which is 8.

It does the same job as the ** operator. The result is an integer when possible, and a float when the exponent is negative, fractional, or the result is too large.

Syntax

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

PHP
$result = pow(2, 3);
CallWhat it does
pow(2, 3)Returns 8.
pow(5, 2)Returns 25, the square of 5.
pow(9, 0.5)Returns 3, which is the square root of 9.

pow($a, $b) is the same as $a ** $b. A negative exponent gives a fraction, and an exponent of 0.5 gives a square root. If the result is bigger than PHP_INT_MAX, PHP returns a float.

Library declarations
PHP
pow(mixed $num, mixed $exponent): int|float|object

Parameters

ParameterDescription
numRequired. The base number.
exponentRequired. The power to raise the base to. It can be negative or a decimal.

Return Value

Return ValueDescription
intThe result when both values are integers and the answer fits in an integer.
floatThe result when the exponent is negative or fractional, or when the answer is too large for an integer.

PHP Examples

Example 1 — Raise Numbers to a Power

Pass the base first and the exponent second.

PHP
<?php
echo pow(2, 3), PHP_EOL;
echo pow(5, 2), PHP_EOL;
echo pow(2, 10), PHP_EOL;

How It Works

  1. pow(2, 3) multiplies 2 by itself three times to get 8.
  2. pow(5, 2) squares 5 to get 25.
  3. pow(2, 10) gives 1024, a common value in computing.
  4. All three results are integers.

Example 2 — Negative, Zero, and Fractional Exponents

Unusual exponents give different kinds of answers.

PHP
<?php
echo pow(2, -1), PHP_EOL;
echo pow(9, 0.5), PHP_EOL;
echo pow(10, 0), PHP_EOL;
echo pow(-8, 1 / 3), PHP_EOL;

How It Works

  1. A negative exponent means one divided by the power, so pow(2, -1) is 0.5.
  2. An exponent of 0.5 is a square root, so pow(9, 0.5) is 3.
  3. Any number to the power 0 is 1.
  4. A negative base with a fractional exponent has no real answer, so PHP returns NAN.

Example 3 — Print a Table of Powers

Use pow() inside a loop to build a small table.

PHP
<?php
for ($i = 0; $i <= 4; $i++) {
    echo "3^", $i, " = ", pow(3, $i), PHP_EOL;
}

How It Works

  1. Start a for loop that counts from 0 to 4.
  2. Each time, pow(3, $i) raises 3 to the current power.
  3. echo joins the text and the result on one line.
  4. The loop prints five lines, each three times bigger than the last.

Frequently Asked Questions

pow() raises a base number to an exponent. For example, pow(2, 3) returns 8.
They give the same result. pow($a, $b) and $a ** $b are interchangeable, and ** is shorter to write.
Use an exponent of 0.5, for example pow(16, 0.5) returns 4. The sqrt() function is clearer for this.
PHP returns a float when the exponent is negative or a decimal, or when the integer result would be too big for PHP_INT_MAX.
NAN appears when the answer is not a real number, such as a negative base with a fractional exponent.

Next: rad2deg()

rad2deg() converts an angle from radians to degrees.

rad2deg() 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