Note that log2(x) is defined for any x greater than zero. If you have a calculator than computes the natural logarithm (often denoted ln), then you can calculate log2(x) = ln(x)/ln(2). The same thing works with log base 10, i.e. log2(x) = log10(x)/log10(2).

But what does it mean?log2(x) means the power you have to raise 2 in order to get x. For example, 22 = 4, so log2(4) is 2. Similarly, 23 = 8, so log2(8) = 3. It turns out that 21.58496 is very nearly 3, so log2(3) is roughly 1.58496.

Some cases deserve special mention. log2(2) = 1 because 21 is 2. log2(1) = 0 because by mathematical convention 20 = 1 (this holds not just for 2, but for any base). Finally, note that log2(0) is undefined, although some software will return -Infinity (which is the limit of log2(x) as x approaches zero).

What is it used for?

The logarithm is useful for a variety of purposes. One of the more common is when describing exponential growth or decay. For example, the time for a radioactive substance to decay to half its mass is called the half life. Similarly we can describe accelerating growth in terms of the doubling time. I previously applied this to the number of blogs tracked by Technorati.

In computing, log2 is often used. One reason is that the number of bits needed to represent an integer n is given by rounding down log2(n) and then adding 1. For example log2(100) is about 6.643856. Rounding this down and then adding 1, we see that we need 7 bits to represent 100. Similarly, in order to have 100 leaves, a binary tree needs log2(100) levels. In the game where you have to guess a number between 1 and 100 based on whether it's higher or lower than your current guess, the average number of guesses required is log2(100) if you use a halving strategy to bracket the answer.

Two much of nothing

Although I can't provide additional help to people with logarrhythmias, I hope this note is of some assistance.

104 Comments:

Another good use of log 2 is related to those "intelligent design" advocates who like to prattle about "complex specified information" and "information theory". When an IDiot is in full spate about how information theory disproves evolution and provides evidence for an intelligent designer, sweetly ask him (it's usually a him), "So what's log 2 all about in that context?"

Then continue to smile during the subsequent arm-waving and ducking and weaving. I hypothesize that 19 times out of 20, the IDiot will be at a loss. (Now for some field work!)

Hi Nick,I'm still kind of confused. I am a biochemist who is useless at maths. I just got affymatrix data back 'normalized for gene expression log2'. Can I directly compare 2 different genes? For example If I have gene 1 log2 1.2 and gene 2 log2 2.4 does that mean gene 2 is expressed twice as much as gene 1?Kind regards,Pat (Ireland)

Hi Nick, I came across your website while trying to understand the change-of-base-theorem to find the logarithm, but now I'm completely lost trying to solve for the exponential equation below:5^x+2 = 3^2x-2

How do you enter this in to a calculator? e.g. how would I know what power to raise the 4 to in the equation: (log 8) to the base 4. Is there an easy way to put it in to the calculator so it will tell me what power I should raise it to? Help would be much appreciated, Thanks in advance

If you would like to calculate log base 4 of 8, you would first calculate log10 of 8 (which is approximately 0.90309) and then divide that by log10 of 4 (which is approximately 0.60206), which gives 1.5. So 4 raised to the power of 1.5 is 8.

Thanks for the wonderfull explanation on the log2(x) issue. I was also looking for it because of microarray data, just like someone else in this thread. You were right with your answer to him: the value represents how much gene expression in one group differs from gene expression in another group. However, once you have calculated these Logs's, they are only usefull to easily see what genes have the biggest differences between groups: being either the biggest negative number (highest expression in group 1) or the biggest positive number (being highest in group 2). The values cannot be compared with eachother as you suggested in your reply.

I have a question for myself as well: in your explantion you used the ln, but when someone asked how to put it in Excell you simply took the 10log(x)/10log(2) in stead of ln(x)/ln(2). In understand it is the same, but why then use the ln in your explantion? Are there circumstances in which it matters which one you use?

Thanks, Anonymous. The only difference between the log and ln functions is a multiplicative constant, so when you take a ratio (log/log or ln/ln) it makes no difference.

To complicate matters, not everyone uses the same notation: depending on the application, log can mean log base 10, or ln, or log base 2. In most programming languages the log function computes ln, and there is often a log10 function to compute log base 10. But in Excel, the log function computes log base 10, and the ln function computes the natural logarithm.

Log2 is commonly used in microarray data, and many other types of biological or biochemical data in which values can increase or decrease from a baseline. The reason log2 is useful in these cases is because a 2-fold increase in gene expression (using microarray as example) would take a value from baseline of say 100% (normalized baseline) to 200%. The same magnitude decrease (2-fold) drops the value from 100% to 50%. When plotted as bar graph, it appears that the increase is greater than the decrease, but they are in fact the same magnitude. The effects get even more visually challenging when larger fold differences are plotted, say 10 or 100 fold. When converted to log2 scale, the increases and decreases of the same magnitude show the same size differences in the bar chart - a visually more pleasing and "accurate" presentation. Log2 is therefore is one way to "stop lying with statistics."

Thanks for all the information about Log2. Currently I am using Log2 in excel but I just noticed that some values are slightly different to those obtained using your calculator instead.e.g. Log(0.88,2)= -0.1776 (in excel) and using your calculator is: -0.1844

I never learn abou a log and i am also very bed in maths and its formula, even log.So anyone tell me that how to calculate the log base 2 easily or calculate without the calculator.....Please help me friendsssssss

Dear Nick,Thanks for your great explanation and graph!Still useful in 2017! :-) Got here searching for answers to Bio-O notation and whether Big-O O(n*logn) stood for base 10 or base e. Turns out it's related to the number of child nodes in a tree. I think I used 2 nodes, so it's base 2 instead. Thanks for your really clear explanation!