Computer memory is a row of numbered boxes, each holding one byte, and the number of a box is its address. An address that is n bits wide can name 2 to the power n boxes, so 8 bits name 256, 16 bits name 65,536 and 20 bits name 1,048,576, and each extra bit doubles the count. To find how many address bits a memory needs, find the smallest n for which 2 to the power n is at least the number of boxes.

Part of Data Storage

How a computer gives every byte of memory a unique numbered location, and how the width of the address in bits sets how many locations can be named.

A Memory Is Numbered Boxes, And The Address Is The Number On The Box

Picture a wall of pigeonholes, each with a number painted on it and each holding one thing. To store something you need to know which box. To read it back you give the number again. A memory works the same way. Each box holds a byte (8 bits, 256 possible values, per Capacity Units), and the CPU says which box by putting its number, the address, on a set of wires.

Two things are easily confused. The address is the number of the box. The contents are what is in it. Address 5 might hold the value 200, and the next moment hold 17. The address of a box never changes; what is in it does.

A telephone exchange has the same structure. A subscriber’s number is not the subscriber; it is the name the exchange uses to find the line. With two-digit numbers you can name 10 × 10 = 100 lines, and with three digits 10 × 10 × 10 = 1,000, which is the arithmetic of the step-by-step exchange in Automatic Switching. Memory uses binary digits where the telephone uses decimal ones, but each extra digit multiplies the count in the same way.

Each Address Wire Doubles The Number Of Boxes

A wire carries one bit, 0 or 1. Number Systems explains why two voltage levels make a bit. With n wires there are 2 × 2 × … × 2, n times, combinations, which is 2ⁿ:

Address wires (n)Boxes named (2ⁿ)Highest address (2ⁿ − 1)
121
387
8256255
101,0241,023
124,0964,095
1665,53665,535
201,048,5761,048,575

The numbers start at 0, which is why the highest address is one less than the count. The 8-bit, 16-bit and 20-bit rows match the address bus examples in address buses and decoding, which also lists 24-bit, 32-bit and 64-bit buses.

Worked Example: A Three-Wire Memory

Take 3 address wires. Then 2³ = 8 boxes, addressed 000 to 111 in binary:

  • 000 = 0, 001 = 1, 010 = 2, 011 = 3, 100 = 4, 101 = 5, 110 = 6, 111 = 7
  • To reach box 5, set the wires to 101: 1 × 4 + 0 × 2 + 1 × 1 = 5
  • Add a fourth wire and the count doubles to 2⁴ = 16, addresses 0 to 15; the old eight boxes are the ones with the new wire at 0, and the new eight have it at 1

Worked Example: How Many Wires For 5,000 Bytes?

Find the smallest n with 2ⁿ ≥ 5,000.

  • 2¹² = 4,096, which is less than 5,000: not enough
  • 2¹³ = 8,192, which is at least 5,000: enough

So 13 address wires are needed. 8,192 − 5,000 = 3,192 boxes would be unused. Compare 4,000 bytes: 2¹² = 4,096 ≥ 4,000, so 12 wires suffice.

Worked Example: A 16-Bit Machine

  • Boxes: 2¹⁶ = 65,536, which is 64 KiB with 1 KiB = 1,024 bytes
  • Highest address: 65,535, written in hexadecimal as FFFF, since four hex digits are 4 × 4 = 16 bits (Hex and Octal)
  • Total bits: 65,536 boxes × 8 bits = 524,288 bits
  • Two 32 KiB chips, each with 2¹⁵ = 32,768 boxes: the top address wire (bit 15) selects the chip. Addresses 0 to 32,767 have bit 15 at 0, and address 32,768 (hex 8000) is the first with it at 1

The wires name the boxes; they do not hold the data. Eight separate data wires carry the byte in or out. The address width and the data width are independent.

Why Names Beat Wires

Without addresses, every box would need its own wire from the CPU, and a 64 KiB memory would need 65,536 wires. With addresses it needs 16 plus a decoder. That is the same economy as the telephone exchange replacing 4,950 pairs for 100 telephones with 100 lines (Switching Networks). The decoder looks at the address wires and activates exactly one box, or one chip; how it does this and how a memory map allots address ranges to RAM, ROM and input/output is in address buses and decoding.

What You Need

  • Pencil and paper, and the ability to count in binary (Binary Counting)
  • A target size for the memory, in bytes
  • A power-of-two table from 2⁰ upward, which you will use constantly

Common Mistakes

  • Mixing up address and contents. Address 5 and the value 5 are different things.
  • Forgetting that counting starts at 0. A 256-box memory has addresses 0 to 255, not 1 to 256.
  • Treating bits as boxes. An address names a byte, not a single bit.
  • Rounding the wrong way. If 2ⁿ is below the size, n is too small; round up to the next n.
  • Using decimal prefixes for memory. A kilobyte of memory is normally 1,024 boxes, not 1,000 (Capacity Units).

What’s Next