# log2() Function & Examples

Use the log2() arithmetic function in Calcul.io. Review its syntax, edit working examples, understand the result, and explore related math functions.

## log2

#### log2(x)

Try it yourself:

```calculio
log2(0.03125)
log2(16)
log2(16) / log2(2)
pow(2, 4)
```

[exp](https://calcul.io/function/exp/index.md)

[log1p](https://calcul.io/function/log1p/index.md)

[log](https://calcul.io/function/log/index.md)

[log10](https://calcul.io/function/log10/index.md)

---

## log2(): Base-2 Logarithm

**log2()** returns the exponent of 2 that produces a positive input. It is useful for binary data sizes, algorithmic complexity, tree depth, and repeated halving.

## Binary interpretation

log2(8) is 3 because 2³ is 8. Real inputs must be positive; zero and negative values have no real logarithm. Reverse a result using [pow()](https://calcul.io/function/pow/index.md), and use [log()](https://calcul.io/function/log/index.md) when a natural-log formula is required.

In data structures, a base-2 logarithm often describes how many balanced decisions are needed to search a range. Use [floor()](https://calcul.io/function/floor/index.md) or [ceil()](https://calcul.io/function/ceil/index.md) only after deciding whether partial levels should count.

[All functions](https://calcul.io/functions/index.md)
