---
title: log2 function
description: Learn the syntax of the log2 function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/log2
---

# `log2` function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime

Returns the logarithm of `expr` with base `2`.

## Syntax

```
log2(expr)
```

## Arguments

* `expr`: An expression that evaluates to a numeric.

## Returns

A `DOUBLE`.

If expr is less than or equal to 0 the result is NULL.

## Examples

```sql
> SELECT log2(2);
 1.0
```

## Related functions

* [`log` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/log.md)
* [`ln` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/ln.md)
* [`log1p` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/log1p.md)
* [`log10` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/log10.md)
* [`pow` function](https://docs.databricks.com/aws/en/sql/language-manual/functions/pow.md)
