Log Base 2 Calculator
log2(1,024) is 10, because 2 to the 10th power lands on 1,024 exactly. Any other number goes through change of base: divide ln(x) by 0.693147. For example, log2(100) = 4.6052 ÷ 0.6931, which works out to 6.6439, and 100 values need 7 bits.
| log2(x) | |
| Change of base work (ln(x) ÷ ln(2)) | |
| Check: 2 raised to the result | |
| Nearest power of 2 below | |
| Nearest power of 2 above | |
| Bits needed to tell apart that many values | |
log2(x) = ln(x) ÷ 0.693147, the change of base rule. The calculation runs entirely in your browser, and nothing you type is uploaded or stored.
Enter a number and get log2 of it, plus the change of base work, the bit count it implies and the two powers of 2 that sit around it.
Key takeaways
- log2(x) counts doublings from 1 up to x, and log2(1,024) = 10
- Change of base does the job: log2(x) = ln(x) ÷ 0.693147
- Values need log2(n) bits rounded up: 1,000 values need 10 bits
- 16-bit audio holds 65,536 levels and spans about 96.3 dB
- Binary search over 1,000,000 items stops within 20 steps, since 2^20 = 1,048,576
On this page
What log base 2 asks
A base 2 logarithm asks one question: 2 raised to what power gives this number? Written as log2(x), the answer is the exponent y in the equation 2 to the y = x. Because 2 × 2 × 2 = 8, log2(8) = 3. Because 2 to the 10th power is 1,024, log2(1,024) = 10. And because 0.5 is 2 to the minus 1, log2(0.5) = −1.
Every step of base 2 doubles, so the log2 of a number is its distance from 1 counted in doublings. That is why log2 keeps turning up wherever doubling or halving stacks up: memory sizes, binary search, audio bit depth and the information content of a message all count doublings.
Enter any positive number above and the calculator returns the log2 value, the change of base work behind it, a check that raises 2 back to the answer, the two powers of 2 that bracket your input, and the bit count a set of that size needs.
The powers of 2 worth knowing cold
Base 2 logs are easy to sanity check because the powers of 2 are short, whole numbers:
| Exponent n | 2 to the n | Exponent n | 2 to the n |
|---|---|---|---|
| 1 | 2 | 8 | 256 |
| 2 | 4 | 10 | 1,024 |
| 3 | 8 | 12 | 4,096 |
| 4 | 16 | 16 | 65,536 |
| 5 | 32 | 20 | 1,048,576 |
| 6 | 64 | 30 | 1,073,741,824 |
| 7 | 128 | 32 | 4,294,967,296 |
Three rows carry most of the daily weight. 2 to the 8th is 256, the number of values in one byte. 2 to the 10th is 1,024, the gap between 1,000 and a kilobyte as computers count it. 2 to the 16th is 65,536, the level count of 16-bit audio. If your number falls between two rows, its log2 falls between the two exponents: 500 sits between 256 and 1,024, so log2(500) must sit between 8 and 10, and it comes out at 8.9658.
The change of base formula does all the work
Most calculators have no log2 button, and none is needed. The change of base rule turns any logarithm into a division of two logs you can compute: log2(x) = ln(x) ÷ ln(2). The constant ln(2) is 0.693147, so every base 2 log is a natural log divided by the same small number. The NIST Digital Library of Mathematical Functions lists the logarithm definitions behind this, and the rule works in any base: log2(x) = log10(x) ÷ 0.30103 too.
Two shortcuts are worth memorizing. Dividing by ln(2) equals multiplying by 1.4427, so log2(x) = 1.4427 × ln(x). And multiplying a base 10 log by 3.3219 gives the same result, because 1 ÷ 0.30103 = 3.3219.
Worked example, every step shown. Take 100: ln(100) = 4.60517 and ln(2) = 0.69315, so log2(100) = 4.60517 ÷ 0.69315 = 6.6439. The sanity check is free: 2 to the 6th is 64 and 2 to the 7th is 128, and 100 sits between them, so the answer has to land between 6 and 7.
The same steps handle numbers below 1. Take 0.25: ln(0.25) = −1.38629, and −1.38629 ÷ 0.69315 = −2, so log2(0.25) = −2. Logs of numbers below 1 are negative, and that is normal. The MIT OpenCourseWare calculus course covers the natural logarithm in the same terms if you want the full derivation.
From log2 to bit counts
The number of bits needed to tell apart n different values is log2(n) rounded up to the next whole number, because bits come in whole units:
| Values to tell apart | log2 of that | Bits needed |
|---|---|---|
| 8 | 3.0000 | 3 |
| 9 | 3.1699 | 4 |
| 100 | 6.6439 | 7 |
| 256 | 8.0000 | 8 |
| 1,000 | 9.9658 | 10 |
| 65,536 | 16.0000 | 16 |
| 1,000,000 | 19.9316 | 20 |
The gaps are where the insight sits. Going from 8 values to 9 costs a whole extra bit, so 4 bits handle 9 values with room left over for 16. The table also reads backward as a count of combinations: 10 bits distinguish 1,024 values, 20 bits distinguish about a million, and 32 bits distinguish 4,294,967,296, which is why a 32-bit address space tops out at about 4.29 billion locations.
Bits, bytes and why 1,024 keeps appearing
Eight bits make one byte, and log2 explains the 256 that shows up in color palettes and character sets: 2 to the 8th is 256, so one byte holds 256 values. Two bytes hold 2 to the 16th, or 65,536 values, which is the range of a single 16-bit audio sample.
The 1,024 habit comes from the same place. Memory was engineered in powers of 2, so a kilobyte of memory meant 1,024 bytes and a megabyte meant 1,048,576. Drive makers later moved to plain thousands, which is why a drive sold as 1,000,000,000,000 bytes shows as about 931 gibibytes in an operating system that divides by 1,073,741,824, the value of 2 to the 30th. Each of those constants is a power of 2, and its exponent is a base 2 log.
For scale at the top end, 2 to the 32nd is 4,294,967,296 and 2 to the 64th is about 1.8 × 10 to the 19th. The exponents 32 and 64 are the base 2 logs of those counts, which is the sense in which a 64-bit chip works with vastly bigger addresses.
Entropy: counting information in bits
Information theory measures surprise in bits, and the formula is built from log2. For outcomes with probabilities p, the entropy is the negative sum of p × log2(p) across the outcomes. A fair coin has two outcomes at 0.5 each, and 0.5 × log2(0.5) = 0.5 × −1 = −0.5, so the two sides sum to 1 bit. One fair coin flip carries exactly 1 bit of information.
Real sources are rarely fair. For a 90/10 event, the entropy works out to −(0.9 × log2(0.9) + 0.1 × log2(0.1)) = −(0.9 × −0.1520 + 0.1 × −3.3219) = 0.469 bits. The rare outcome is a big surprise, but it is rare, so the average message carries less than half a bit. A fair six sided die lands at log2(6) = 2.585 bits per roll, and 8 equally likely outcomes carry 3 bits, since 2 to the 3rd is 8.
The same counting shows up in data compression. A Huffman code hands the most likely outcome the shortest label, and the average length of those labels, measured in bits per symbol, sits close to the entropy of the source. A source that offers 8 equally likely outcomes needs 3 bits per symbol no matter how clever the code is, because log2(8) = 3 is the floor the source itself sets. Compression only has room to work inside that floor, which is why a skewed source with entropy 0.469 bits per symbol can shrink much further than a flat one.
Audio dynamic range, one bit at a time
Each bit of audio depth adds about 6.02 dB of dynamic range, and that constant is a base 2 log wearing a unit: 20 × log10(2) = 20 × 0.30103 = 6.0206 dB. Multiply by the bit depth to get the span between the quietest and loudest level a format can carry:
| Bit depth | Levels per sample | Dynamic range |
|---|---|---|
| 8-bit | 256 | 48.2 dB |
| 16-bit | 65,536 | 96.3 dB |
| 24-bit | 16,777,216 | 144.5 dB |
This is why CD audio, at 16 bits, spans about 96 dB, enough to run from a quiet room to a loud concert hall, while 24-bit studio files push to about 144.5 dB and leave headroom for mixing. The level counts are powers of 2, so the whole subject is log2 territory: one more bit of depth doubles the levels and buys the same 6.02 dB every time.
Algorithm steps, Excel and Python
Binary search halves the search space at every step, so its step count is a base 2 log. Searching a sorted list of 1,000,000 names takes at most 20 comparisons, because 2 to the 20th is 1,048,576, just enough to cover the list. The pattern scales smoothly:
| Items to search | Steps needed | Covering power of 2 |
|---|---|---|
| 100 | 7 | 128 |
| 1,000 | 10 | 1,024 |
| 1,000,000 | 20 | 1,048,576 |
| 1,000,000,000 | 30 | 1,073,741,824 |
A billion items in 30 steps is the punchline of O(log n): multiplying the workload by a thousand adds only 10 steps, because a thousand is 2 to the 10th.
To compute log2 outside this page: in Excel or Google Sheets, write =LOG(x, 2), or divide two logs as =LN(x)/LN(2). The formula =LOG(100, 2) returns 6.6439. In Python, math.log2(100) returns 6.643856189774725, and numpy.log2 does the same across whole arrays. On a plain calculator with an ln key, take the natural log of the number and divide by 0.693147.
Frequently asked questions
What is log2 of 100?
6.6439. Change of base gives it in two lines: ln(100) = 4.60517 and ln(2) = 0.69315, and 4.60517 ÷ 0.69315 = 6.6439. The check is that 2 to the 6th is 64 and 2 to the 7th is 128, which bracket 100.
How many bits do I need for 1,000 different values?
10. The exact figure is log2(1,000) = 9.9658, and bits come in whole units, so you round up to 10. That covers up to 1,024 values, since 2 to the 10th is 1,024.
What is log2 of 1,048,576?
Exactly 20, because 2 to the 20th is 1,048,576. That number is a megabyte in the older memory sense, and it is the reason a binary search over a million items stops within 20 steps.
Can log2 be zero or negative?
log2(1) = 0, since 2 to the power 0 is 1. Numbers below 1 give negative logs: log2(0.5) = −1 and log2(0.25) = −2. Zero and negative inputs have no base 2 log at all.
How do I calculate log2 in Excel?
Use =LOG(x, 2), or divide two logs as =LN(x)/LN(2). For example, =LOG(100, 2) returns 6.6439. Google Sheets works the same way.
How do I write log2 in Python?
math.log2(x) from the math module. math.log2(100) returns 6.643856189774725. numpy.log2 handles whole arrays at once, which is handy for large datasets.
Why do I keep seeing 1,024 instead of 1,000?
Because 2 to the 10th is 1,024. Memory was built in powers of 2, so a kilobyte of memory meant 1,024 bytes and a megabyte meant 1,048,576.
What does 6.02 dB per bit mean?
Each added bit of audio depth doubles the level count, and 20 × log10(2) = 6.0206 dB. Sixteen bits give 16 × 6.0206, about 96.3 dB of dynamic range.
Is log2 the same as ln?
No. ln uses the base 2.71828 and log2 uses 2. They differ by a fixed factor: ln(x) = 0.6931 × log2(x), and log2(x) = 1.4427 × ln(x). For 100, ln(100) = 4.6052 while log2(100) = 6.6439.
How many values does one byte hold?
256, since one byte is 8 bits and 2 to the 8th is 256. Two bytes hold 65,536 values, which is the range of one 16-bit audio sample.
What does O(log n) mean in practice?
An algorithm that halves the problem at every step. A binary search needs about log2(n) comparisons: 7 steps for 100 items, 10 for 1,000 and 20 for 1,000,000.
What is the entropy of a fair coin flip?
Exactly 1 bit, since both outcomes have probability 0.5 and each side contributes 0.5 × log2(0.5) = −0.5. A fair die rolls in at log2(6) = 2.585 bits.
How do I sanity check a log2 result?
Bracket it with powers of 2. For 500: 2 to the 8th is 256 and 2 to the 10th is 1,024, so the answer belongs between 8 and 10, and log2(500) = 8.9658 confirms it.
Spotted a wrong number or a broken result?
More Math tools
Fee schedules, rates and rules change without notice. Always confirm important figures with the official source before you rely on them.