Learn how to use the log2 function in Notion formulas.

The log2() function returns the base-2 logarithm of a number.


Code language: JavaScript (javascript)

For reference, here are the named components of a logarithm:

\(\log_{base} argument = exponent\)

A logarithm is the exponent of the base that returns the argument.

log2(64) /* Output: 6 */

2.log2() /* Output: 1 */
Code language: JavaScript (javascript)

Want to learn more about logarithms? Check out this resource:

Using Logarithms in the Real World – BetterExplained

Notion only provides log2(), log10, and ln because those are by far the most commonly-used log bases.

However, if you need to compute a log with a different base, you can use the change of base formula:

\(\log_x y= (\frac{\ln y}{\ln x})\)

So, for example:

\(\log_3 81 = (\frac{\ln 81}{\ln 3})\)

Here’s a Notion formula to compute this:

ln(81) / ln(3) /* Output: 4 */
Code language: JavaScript (javascript)

\(log_{2}\) can be used to perform an interesting mathematical trick – finding the length (i.e. number of digits) in any number when represented in binary. It is done by taking the floor value of a number’s \(log_{2}\)​, then adding one:

\(\lfloor log_{2}n \rfloor + 1\)

The example database below shows this trick in action. Unfortunately, actual binary representation of a base-10 number in Notion is not possible (or at least has not been solved by the Notion community), but you can check the result using this converter.

Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.
A new tool that blends your everyday work apps into one. It’s the all-in-one workspace for you and your team
	+ 1
Code language: JavaScript (javascript)

If you’re curious about the math behind why this trick works, check out this thread:

logarithms – Prove that the binary representation of a number n will use floor(lg(n)) + 1 bits. – Mathematics Stack Exchange

The formula itself is quite simple:

  1. We pass prop("Num") to the log10() function.
  2. This value is then run through the floor function in order to round it to its nearest integer of lower or equal value.
  3. Finally, we add 1.

Other formula components used in this example:

floor – Thomas Frank
add – Thomas Frank
About the Author

My name is Thomas Frank, and I'm a Notion-certified writer, YouTuber, and template creator. I've been using Notion since 2018 to organize my personal life and to run my business and YouTube channel. In addition to this formula reference, I've created a free Notion course for beginners and several productivity-focused Notion templates. If you'd like to connect, follow me on Twitter.

🤔 Have an UB Question?

Fill out the form below and I’ll answer as soon as I can! ~Thomas

🤔 Have a Question?

Fill out the form below and I’ll answer as soon as I can! ~Thomas