Logarithms are easier to calculate if you can write your input as a power of the base. In this case, .

In general, . So writing the input as a power of your base gives you the easiest way to evaluate a logarithm. If the input and base aren't related by a nice power relationship, you may have to relate them to known values or use a calculator.

Answer from walkar on Stack Exchange
🌐
Quora
quora.com › How-do-you-solve-log-base-2-without-a-calculator
How to solve log base 2 without a calculator - Quora
But the more precise you want to be, the harder it becomes to compute by head ! PS : all the rules you must use to get this method is that : Log2 is a growing function, so if a < x < b, log(a) < log(x) < log(b) (for all bases bigger than 1, ...
Discussions

.net - How can I compute a base 2 logarithm without using the built-in math functions in C#? - Stack Overflow
How can I compute a base 2 logarithm without using the built-in math functions in C#? I use Math.Log and BigInteger.Log repeatedly in an application millions of times and it becomes painfully slow... More on stackoverflow.com
🌐 stackoverflow.com
How do computers computer log base 2 computations?
floating point in its native representation is already in the form of m*2e where 1<=m<2 (most of the time), so a log2 immediately extracts e using only bit manipulations, and then computes log2(m). by now we're working with range [1,2), which gives a good convergence rate if you compute ln(m) via ln(1+x) series expansion (some details omitted, we're not really working in range [1,2), but it's fixable). and finally we multiply it by log2(e) which is stored as a constant to get log2(m) More on reddit.com
🌐 r/computerscience
8
2
January 27, 2023
log base 2 of 3 without calculator (Check)
Your solutions are not wrong. The problem occurs when you can't approximate the roots or get an irrational root you're unfamiliar with, say 73/5 and have to compare it to another difficult root, say 717/29 73/5 = 3.21 (approximately) 717/29 = 3.19 (approximately) Your method is a bit more brute force which for small numbers like this works but will necessitate a calculator earlier than the one shown in the video which was more elegant and doesn't necessitate a calculator. More on reddit.com
🌐 r/learnmath
2
4
March 24, 2020
How are logarithms calculated without calculators?
Before calculators existed, people used tables of logarithms , which had the logarithms pre-computed for a lot of numbers between 1 and 10 (to a given precision). This was enough to calculate the (decimal) logarithm for any (positive) number, for example: log_10(123) = 2 + log_10(1.23) However, somebody still had to create such tables, but there are algorithms for that, for example, the Taylor series . More on reddit.com
🌐 r/askmath
12
18
February 15, 2024
🌐
Quora
quora.com › How-do-you-figure-out-the-log-of-base-2-without-a-calculator
How to figure out the log of base 2 without a calculator - Quora
Answer (1 of 4): You can get the integer part by counting how many times you can divide X by 2 before 1 or a slightly shorter number. Let’s say you want log2(15) 15/2 = 7.5 7.5/2 = 3.75 3.75/2 = 1.875 1.875/2 = 0.9375 You could only divide ...
🌐
YouTube
youtube.com › watch
Evaluate a Logarithm Without a Calculator with Base 2 - YouTube
👉 Learn how to evaluate basic logarithms. Recall that the logarithm of a number says a to the base of another number say b is a number say n which when rais...
Published   December 18, 2013
🌐
Medium
cevic.medium.com › how-to-calculate-base-2-logarithm-without-a-calculator-9fd4b90dfc19
How To Calculate Base-2 Logarithm Without A Calculator | by Cevic | Medium
January 24, 2021 - That means the logarithm of a given number x is the exponent to which another fixed number, the base b, must be raised, to produce that number x. To put it simply, when I write log2 512, where 2 is the base, what I mean is: “if 2 to the x equals 512, how much is x?” In this case, the answer is 9....
🌐
Homework.Study.com
homework.study.com › explanation › how-do-you-calculate-log-base-2-on-a-calculator.html
How do you calculate log base 2 on a calculator? | Homework.Study.com
Use the change-of-base formula to approximate log _7 21. Use the calculator to find the value of log( 2 5) and log(2) + log(5). Round the answer to three decimal places. Find the exact value of the logarithm without using a calculator.
Find elsewhere
🌐
Physics Forums
physicsforums.com › homework help › calculus and beyond homework help
How do I do log to the base 2? • Physics Forums
July 21, 2010 - Participants discuss the use of the change of base formula, specifically log(x)/log(2), and question the efficiency of this method for complex equations. Some suggest simplifying expressions on paper before using a calculator.
🌐
Reddit
reddit.com › r/computerscience › how do computers computer log base 2 computations?
r/computerscience on Reddit: How do computers computer log base 2 computations?
January 27, 2023 -

In math, using the natural log makes problems just work (this isn't a math post, so I'm not going to elaborate). I want to use log properties to try to improve some math operations in a program I've written and optimize my code a little bit. I'm inevitably going to have to do log base 2 of a float, and I was wondering how a computer would implement a log base 2 function. Additionally, how does log base 2 operation performance compare to division or square roots, and finally, are there any approximations I should know about for log base 2 as there is for the sine function (at certain x values)?

🌐
Reddit
reddit.com › r/learnmath › log base 2 of 3 without calculator (check)
r/learnmath on Reddit: log base 2 of 3 without calculator (Check)
March 24, 2020 -

I got this question from this video and there were 4 options:

https://www.youtube.com/watch?v=X6C5hGpWW5A

can anyone tell me if my method was accurate, (the guy in the video used a more simpler method but here's mine):

we know 2>x>1 (2^2 = 4 >3 > 2^1 =2) then I took three values as x from the question:

(i) 2^ 3/2 = 2 *sq rt (2)

(ii) 2 ^ 4/3 = 2* cub rt (2)

(iii) 2 ^ 5/3 = 2* cub rt (4)

As (ii) n (iii) are the closest values to 3, log base 2 of 3 must lie between 1 1/2 and 1 2/3. How accurate do you think this method would be? I will really really enjoy some feedback it has really been bugging me.

🌐
Reddit
reddit.com › r/askmath › how are logarithms calculated without calculators?
r/askmath on Reddit: How are logarithms calculated without calculators?
February 15, 2024 -

I don't mean the basic/easy ones like log100 base 10, log 4 base 2 etc., rather log(0.073) base 10? For pH-calculations for example. People must have had a way of solving it to know acidities before calculators were invented. I tried googling it, all I got was some 9th grade stuff on what a logarithm is

🌐
VEDANTU
vedantu.com › maths › log base 2: meaning, formula, table & examples
Log Base 2 – Definition, Formula, Calculator & Table
April 21, 2020 - Calculating log₂(x) involves ... to convert to a more readily available base (like base 10 or natural logarithm): log₂(x) = ln(x) / ln(2) or log₂(x) = log₁₀(x) / log₁₀(2)....
🌐
Cuemath
cuemath.com › algebra › log-base-2
Log Base 2 - Formula, Solution, Examples
Log base 2 is useful to write the exponential form with a base of 2 into logarithmic form. The number 20 = 1, 21 = 2, 22 = 4, 23 = 8, 24 = 16, but if we have 2x = 25 and we need to find the value of x, then we can first write it as log base 2 or \(log_225 = x\), and find the value of x.
🌐
Homework.Study.com
homework.study.com › explanation › how-do-you-calculate-log-base-2-manually.html
How do you calculate log base 2 manually? | Homework.Study.com
Use a change-of-base formula to evaluate the logarithm. log _4(19) ... Solve for x without using calculator. a) 3x log 45 = 0.4, b) -1 = log 5^{2x} .
Top answer
1 of 2
3

I have tried to run most of the methods from different answers from 1 and 2 where I found that power_of_2 and easy show a good performance.

import math
import timeit

def myLog(x, b):
    if x < b:
        return 0
    return 1 + float(myLog(x / b, b))


def easy(x):
    return x.bit_length() - 1


def brute(x):
    # determine max p such that 2^p <= x
    p = 0
    while 2 ** p <= x:
        p += 1
    return p - 1


def log2_approx(val):
    from math import floor
    val = floor(val)
    approx = 0
    while val != 0:
        val &= ~ (1 << approx)
        approx += 1
    return approx


def log2(n):
    i = 0
    while n > 1:
        n >>= 1
        i += 1
    return i


def power_of_2(n):
    return (n & (n - 1) == 0) and n != 0

def log2_fast(n):
    return  math.frexp(33554436)[1] - 1
import time
from functools import partial
 
import time

start_time = time.time()
math.log2(33554432)
print("math.log2 is %s microseconds ---" % ((time.time() - start_time) * 1000000))
start_time = time.time()
myLog(33554432.0, 2.0)
print(" myLog is %s microseconds ---" % ((time.time() - start_time) * 1000000))

start_time = time.time()
brute(33554432)
print(" brute is --- %s microseconds ---" % ((time.time() - start_time) * 1000000))
start_time = time.time()

log2_approx(33554432) - 1
print("log2_approx is --- %s microseconds ---" % ((time.time() - start_time) * 1000000))
start_time = time.time()
log2_fast = math.frexp(33554436)[1] - 1
print(" log2_fast is --- %s microseconds ---" % ((time.time() - start_time) * 1000000))

start_time = time.time()
log2(33554432)
print("log2 is --- %s microseconds ---" % ((time.time() - start_time) * 1000000))

start_time = time.time()
power_of_2(33554432)
print("power_of_2 is --- %s microseconds ---" % ((time.time() - start_time) * 1000000))
start_time = time.time()
easy(33554432)
print("easy is --- %s microseconds ---" % ((time.time() - start_time) * 1000000))

Running time

 math.log2 is 3.0994415283203125 microseconds ---
 myLog is 5.4836273193359375 microseconds ---
 brute is --- 6.4373016357421875 microseconds ---
 log2_approx is --- 6.4373016357421875 microseconds ---
 log2_fast is --- 1.6689300537109375 microseconds ---
 log2 is --- 2.1457672119140625 microseconds ---
 power_of_2 is --- 0.7152557373046875 microseconds ---
 easy is --- 0.476837158203125 microseconds ---

Using timeit shows delay

test_items=33554432
base=2
times = timeit.Timer(partial(math.log2, test_items))
print("math.log2 is %s microseconds ---", (times.timeit(1000000)))
times = timeit.Timer(partial(myLog, test_items,base))
print("myLog is %s microseconds ---", (times.timeit(1000000)))
times = timeit.Timer(partial(easy, test_items))
print("easy is %s microseconds ---", (times.timeit(1000000)))
times = timeit.Timer(partial(brute, test_items))
print("brute is %s microseconds ---", (times.timeit(1000000)))
times = timeit.Timer(partial(log2_approx, test_items))
print("log2_approx is %s microseconds ---", (times.timeit(1000000)))
times = timeit.Timer(partial(log2, test_items))
print("log2 is %s microseconds ---", (times.timeit(1000000)))
times = timeit.Timer(partial(power_of_2, test_items))
print("power_of_2 is %s microseconds ---", (times.timeit(1000000)))
times = timeit.Timer(partial(log2_fast, test_items))
print("log2_fast is %s microseconds ---", (times.timeit(1000000)))

Running time

math.log2 is %s microseconds --- 0.05126429593656212
myLog is %s microseconds --- 4.137887543998659
easy is %s microseconds --- 0.10356121498625726
brute is %s microseconds --- 5.254867412033491
log2_approx is %s microseconds --- 3.81522585300263
log2 is %s microseconds --- 1.7966924259671941
power_of_2 is %s microseconds --- 0.1572157460032031
log2_fast is %s microseconds --- 0.21886748599354178
2 of 2
2

If your code needs to call this function repeatedly, and the inputs are guaranteed to be even integer powers of two (unlike your example!) I imagine it's going to be hard to beat a hard-coded dictionary lookup.

def precalculate_pow2(ceiling):
    i = 1
    result = dict()
    for n in range(ceiling):
        result[i] = n
        i <<= 1
    return result

powersof2 = precalculate_pow2(500) # or whatever your upper limit is

def log2(n):
    return powersof2[n]

Obviously, the loop to calculate the values is no more efficient than your current code, but memoizing it allows you to amortize that cost over all the calls to the log2 function.

As a variation, you could start with the dictionary containing only one value, and only populate the missing parts on subsequent calls, using a recursive function.

powersof2 = {1: 0}

def log2(n):
    if n not in powersof2:
        powersof2[n] = 1 + log2(n >> 1)
    return powersof2[n]

This has the obvious drawback that it will go into an endless loop if you call it with a negative value (though Python will then throw a traceback once you exhaust the maximum recursion limit).

🌐
Omni Calculator
omnicalculator.com › math › log-2
Log Base 2 Calculator
December 17, 2025 - We denote them ln(x) and log(x) (the second one simply without the small 10), and their bases are, respectively, the Euler number e and (surprise, surprise!) the number 10. While the latter is obvious, the former may pose some problems – if you're not sure what the number e is, check out our e calculator. The logarithm function is defined only for positive numbers. In other words, whenever we write logₐ(b), we require b to ...
🌐
Wikipedia
en.wikipedia.org › wiki › Logarithm
Logarithm - Wikipedia
5 days ago - The constants π and ln(2) can be calculated with quickly converging series. While at Los Alamos National Laboratory working on the Manhattan Project, Richard Feynman developed a bit-processing algorithm to compute the logarithm that is similar to long division and was later used in the Connection Machine.
🌐
Wikipedia
en.wikipedia.org › wiki › Binary_logarithm
Binary logarithm - Wikipedia
February 15, 2026 - An easy way to calculate log2 n on calculators that do not have a log2 function is to use the natural logarithm (ln) or the common logarithm (log or log10) functions, which are found on most scientific calculators.
🌐
VEDANTU
vedantu.com › maths › value of log 2 in maths: exact values, formulas & uses
Value of Log 2: Exact Logarithm Values, Tables & Shortcuts
Mastering this helps with fast calculations in exponentials, scientific data, and other log-based maths concepts. A quick way to remember the value of log 2 is to think “log 2 is almost 0.3.” During exams, students often recall that 210 = 1024 ≈ 103, backing up that 10 × log 2 ≈ 3 ⇒ log 2 ≈ 0.3.