Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
I'd say it depends whether you're addressing the memory directly or indirectly. – Machado Feb 5 at 19:50
Why did you put a bounty on an answered question from 3 years ago? With an accepted answer!? – Tersosauros Feb 6 at 5:24
up vote 13 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

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

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

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

There is no answer.

For modern systems software uses virtual memory, and virtual memory has nothing to do with physical memory. For example, you might have 512 MiB of RAM, 1.5 GiB of swap space, and 2 GiB of memory mapped files.

For most systems that have about 512 MiB of RAM; you'd typically want/expect 32-bit addresses and 32-bit instruction pointer (and have 4 GiB of virtual address space per process, including space reserved by kernel).

Note that "amount of RAM" also has nothing to do with actual physical address size or minimum physical address size. A computer with 512 MiB of RAM, 4 MiB of ROM, and 512 MiB of memory mapped devices (video cards, etc) may need a minimum of 2 GiB of physical address space (and may actually have 4 GiB of physical address space).

share|improve this answer
Also worth considering segmented architectures, which need many more bits per byte of actually usable memory due to the need for a segment selector as part of the address. – Jules Feb 5 at 21:07

It depends not on the amount of RAM, but on the address space. A 64 bit processor with 512 MB RAM and virtual memory supported by a 5 TB hard drive needs at least 43 bits for addresses. Now if you support sparse allocations then you need more.

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.