Sign up ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

How many bits of address is required (for the program counter for example) in a byte-addressed computer with 512 Mbyte RAM?

What does the formula look like?

How is this connected with the fact that 32 bits can address no more than 4 GB RAM?

share|improve this question
Remember that in practice it's less or sometimes more! There may be address bits that are reserved for some other purpose so you have memory range that is never accessible. You can also access more memory than this with an instruction that says "address now refer to that other 512Mb block until we swap back" – Martin Beckett Dec 10 '12 at 16:22
@Caleb - that's why I put it as a comment rather than an answer. And for questions like "why can I only see 2Gb on my 32bit machine on windows but 64Gb on Linux" – Martin Beckett Dec 10 '12 at 18:49
How familiar are you with the idea of "virtual memory"? Some operating systems will take space from a hard drive to make it appear there is more RAM than they may physically be. Just an idea that may be worth noting here. There is also Physical Address Extension,, that may also be worth examining. – JB King Dec 10 '12 at 22:15

3 Answers 3

up vote 10 down vote accepted

You need log2(n) bits to address n bytes. For example, you can store 256 different values in an 8 bit number, so 8 bits can address 256 bytes. 210 = 1024, so you need 10 bits to address every byte in a kilobyte. Likewise, you need 20 bits to address every byte in a megabyte, and 30 bits to address every byte in a gigabyte. 232 = 4294967296, which is the number of bytes in 4 gigabytes, so you need a 32 bit address for 4 GB of memory.

share|improve this answer
OK so for 512 Mbyte RAM the equation is 512*1024²=2^x(?) Thanks a lot for the prompt answer. – Programmer 400 Dec 10 '12 at 16:07
log2(512*1024*1024) = log2(512) + log2(1024) + log2(1024) = 9 + 10 + 10 = 29. – Caleb Dec 10 '12 at 16:09
Logarithm is the inverse of exponentiation. log2(2^X) == X . Hence, log2(512) == log2(2^9) == 9. As an aside, most calculators provide log10, but you can convert log10 to log2 by dividing by log10(2). E.g., Google Calculator: log(512*1024*1024) / log(2) – Brian Dec 10 '12 at 16:18

You need the log (base 2) of the N bytes in order to address N bytes of RAM directly.

4 GB = 2^32 bytes
log_2( 2^m ) = m


log_2( 2^32 ) = 32

So a 32-bit address lets you directly reference 2^32 bytes (4 GB). A 64-bit address lets you directly reference 2^64 bytes (16 exabytes).

share|improve this answer
Nice answer, many thanks. – Programmer 400 Dec 10 '12 at 16:08

Existing answers have explained that the formula for addressing ram is 2^BITS = Addressable ram, but have not explained why.

Consider a system with 2 bits. It can address 4 bytes of ram as follows:

Byte 0: 00
Byte 1: 01
Byte 2: 10
Byte 3: 11

For each additional bit, we can address twice as much memory. E.g., add a 0 bit to each for bytes 0-3, then add a 1 bit for bytes 4-7. We address byte X by using a bit arrangement corresponding to X in binary.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.