edubun
English
1 / 19

6 / 6 · Intro

Memory and storage

With 32-bit addresses a processor can name 4,294,967,296 bytes, exactly 4 GiB. Switch the power off and RAM forgets all of it.

Jump to the 10 practice questions

You will learn

  • Tell memory (RAM) from storage
  • Order the memory layers by speed

Before this: What a CPU does

1Explain

16 GB of memory, 512 GB of storage

"My laptop has 16 GB of memory, so it can hold 16 GB of photos." That sentence mixes up two different parts, and the laptop advert itself shows why. It lists two sizes, for example 16 GB of memory and 512 GB of storage. Memory, or RAM, holds the programs and data the CPU is using right now. Storage, a solid-state drive (SSD) or an older hard disk, keeps your files when the power is off. The photos live on the 512 GB side. The 16 GB is the working space where a photo goes while you are editing it.

2Explain

Why RAM forgets when the power goes

Most RAM stores each bit as a tiny charge that leaks away unless it is refreshed many times a second, so everything in it is lost when the power goes. That is what "volatile" means. Storage keeps data without power. An SSD traps charge in flash memory cells that hold it for years, and a hard disk records bits as magnetised spots on spinning platters. Storage is much bigger and cheaper per byte, but much slower to reach, so programs are copied from storage into RAM before they run.

3Problem

Volatile

What does "volatile" mean for RAM?

Hint

Think of a power cut.

Solution

Answer: It loses its contents when the power is off

RAM charges leak away without power and refreshing.

4Problem

Files with the power off

Which keeps your files when the power is off?

Hint

The one that is not volatile.

Solution

Answer: SSD

Flash cells in an SSD hold their charge without power.

5Explore

How the CPU finds one byte among billions

Memory is a long row of cells, each holding one byte, and each cell has a number called its address, starting from 0. To read or write, the CPU puts an address on a set of wires and gets back the byte stored there. The number of address bits sets how much memory can be reached. Four address bits, as in the toy computer, give 2 to the power 4 = 16 cells. Sixteen bits give 65,536. Thirty-two bits give 4,294,967,296 bytes, which is exactly 4 GiB.

Each extra address bit doubles the number of cells that can be reached.

Address bits
const bits = 4;
console.log(2 ** bits);
Output
16

6Problem

16 address bits

How many memory cells can 16 address bits reach?

cells

Hint

2 to the power 16.

Solution

Answer: 65536 cells

2¹⁶ = 65,536.

7Problem

32 address bits

How many bytes can 32-bit addresses name?

bytes

Hint

2 to the power 32.

Solution

Answer: 4294967296 bytes

In byte-addressed memory, each address pattern names one byte. The 32 address bits give 2³² = 4,294,967,296 patterns, so that many bytes can be addressed.

8Problem

That in GiB

How many GiB is that?

GiB

Hint

One GiB is 2 to the power 30 bytes.

Solution

Answer: 4 GiB

2³² ÷ 2³⁰ = 4.

9Problem

Bits in the toy

The toy computer has 16 cells of 8 bits. How many bits of memory is that in total?

bits

Hint

16 × 8.

Solution

Answer: 128 bits

16 × 8 = 128 bits, or 16 bytes.

10Explore

Number or instruction

A cell has no idea what its bits mean. In the toy computer the 8 bits 00000100 in a data cell are the number 4, but read as an instruction the same bits mean HALT 4. Only the way the CPU reaches a cell decides which, as the next instruction or as data named by an instruction. That follows directly from von Neumann's idea of keeping both in one memory. It is also why a bug that writes to the wrong address can wreck a whole program.

Loading

Drag to turn. Scroll or pinch to zoom.

The 4 × 3 program. Cells 12 to 15 hold data (shown in green): 1, the running result, 4 and the counter 3. Press Run and watch cell 13 grow 4, 8, 12 while cell 15 counts down. The whole run is 24 instructions, 72 phases. Every cell is shown as its 8 bits; only the CPU decides whether they are an instruction or a number.

11Problem

Cell 13 after 4 × 3

After the 4 × 3 program halts, what number is in cell 13?

Hint

4 + 4 + 4.

Solution

Answer: 12

It adds 4 three times: 4, 8, 12.

12Problem

00000100 as an instruction

In the toy, a data cell holds 00000100. Read as an instruction, what would it mean?

Hint

The first four bits, 0000, are the opcode.

Solution

Answer: HALT 4

Opcode 0000 is HALT; the address bits are 0100 = 4.

13Explore

The same bits, read two ways

The first line reads the cell as a number, the second as an instruction of the toy computer.

Cell
const cell = 0b00000100;
const names = ["HALT", "LOAD", "ADD", "SUB", "STORE", "JUMP", "JZ"];
console.log(cell);
console.log(names[cell >> 4] + " " + (cell & 15));
Output
4
HALT 4

14Explain

Each layer down is bigger and slower

Fast memory is expensive, so computers use layers. Closest to the circuits are the registers, a few dozen values the CPU works on directly, like the accumulator in the toy. Next come caches, small blocks of fast memory on the processor chip itself, usually named L1, L2 and L3, which keep copies of recently used parts of RAM. Then RAM, then the SSD or hard disk, and beyond that the network. Each layer down is bigger and slower. A program runs fast when most of what it needs is already in the top layers.

15Problem

Fastest to slowest

Order from fastest to slowest.

  1. Registers
  2. SSD
  3. Cache
  4. RAM
Hint

From inside the CPU outwards.

Solution

Answer:

  1. Registers
  2. Cache
  3. RAM
  4. SSD

Each layer further from the circuits is bigger and slower.

16Problem

Why programs are copied into RAM

Why are programs copied from storage into RAM before they run?

Hint

Compare how fast the CPU reaches each one.

Solution

Answer: RAM is much faster for the CPU to reach

Storage is large and lasting but slow; RAM is the working space.

17Practice

How many address bits?

Finish addressBits(cells): return the smallest number of address bits that can give every cell its own address. 16 cells need 4 bits, 1000 cells need 10.

Expected output
4
10
16
Your code
function addressBits(cells) {
  let bits = 0;
  return bits;
}
console.log(addressBits(16));
console.log(addressBits(1000));
console.log(addressBits(65536));
Hint

Keep adding a bit while 2 ** bits is still smaller than the number of cells.

A solution
function addressBits(cells) {
  let bits = 0;
  while (2 ** bits < cells) bits++;
  return bits;
}
console.log(addressBits(16));
console.log(addressBits(1000));
console.log(addressBits(65536));

18Explain

Common mistakes

  • "More RAM makes the CPU faster."

    RAM size changes neither the clock nor the work done per tick. It decides how much can be kept close at hand. If the programs and data you use already fit, more RAM changes little. If they don't fit, the computer keeps going back to much slower storage, and then more RAM helps.

  • "16 GB of memory means room for 16 GB of files."

    Files are kept in storage, the 512 GB in the advert. RAM is the working space for whatever is open right now, and it empties when the power goes.

  • "If it is on the screen, it is safely inside the computer."

    An open document sits in RAM. Until it is saved to storage, a power cut or a flat battery wipes it, because RAM is volatile.

19

Summary

  • Memory is numbered cells; n address bits reach 2ⁿ cells (32 bits = 4 GiB).
  • The same bits can be an instruction or data; how the CPU reaches them decides.
  • RAM is volatile working memory; SSDs and hard disks keep data without power.
  • Registers, cache, RAM, storage: each layer down is bigger and slower.

Back to the courseHow computers work
Full text · The whole lesson as one text

"My laptop has 16 GB of memory, so it can hold 16 GB of photos." That sentence mixes up two different parts, and the laptop advert itself shows why. It lists two sizes, for example 16 GB of memory and 512 GB of storage. Memory, or RAM, holds the programs and data the CPU is using right now. Storage, a solid-state drive (SSD) or an older hard disk, keeps your files when the power is off. The photos live on the 512 GB side. The 16 GB is the working space where a photo goes while you are editing it.

Why RAM forgets when the power goes

Most RAM stores each bit as a tiny charge that leaks away unless it is refreshed many times a second, so everything in it is lost when the power goes. That is what "volatile" means. Storage keeps data without power. An SSD traps charge in flash memory cells that hold it for years, and a hard disk records bits as magnetised spots on spinning platters. Storage is much bigger and cheaper per byte, but much slower to reach, so programs are copied from storage into RAM before they run. That copying is what is happening while an app says it is loading.

How the CPU finds one byte among billions

Memory is a long row of cells, each holding one byte, and each cell has a number called its address, starting from 0. To read or write, the CPU puts an address on a set of wires and gets back the byte stored there. The number of address bits sets how much memory can be reached. Four address bits, as in the toy computer, give 2 to the power 4 = 16 cells. Sixteen bits give 65,536. Thirty-two bits give 4,294,967,296 bytes, which is exactly 4 GiB. A 32-bit byte address names up to 4 GiB. Some 32-bit systems use extra hardware features to access more physical RAM. Today's 64-bit processors can name far more.

A cell has no idea what its bits mean. In the toy computer the 8 bits 00000100 in a data cell are the number 4, but read as an instruction the same bits mean HALT 4. Only the way the CPU reaches a cell decides which, as the next instruction or as data named by an instruction. That follows directly from von Neumann's idea of keeping both in one memory. It is also why a bug that writes to the wrong address can wreck a whole program.

The 4 × 3 program. Cells 12 to 15 hold data (shown in green): 1, the running result, 4 and the counter 3. Press Run and watch cell 13 grow 4, 8, 12 while cell 15 counts down. The whole run is 24 instructions, 72 phases. Every cell is shown as its 8 bits; only the CPU decides whether they are an instruction or a number.

Each layer down is bigger and slower

Fast memory is expensive, so computers use layers. Closest to the circuits are the registers, a few dozen values the CPU works on directly, like the accumulator in the toy. Next come caches, small blocks of fast memory on the processor chip itself, usually named L1, L2 and L3, which keep copies of recently used parts of RAM. Then RAM, then the SSD or hard disk, and beyond that the network. Each layer down is bigger and slower. A program runs fast when most of what it needs is already in the top layers. That is why reading data in order is usually quicker than jumping around.

Common mistakes
  • "More RAM makes the CPU faster." RAM size changes neither the clock nor the work done per tick. It decides how much can be kept close at hand. If the programs and data you use already fit, more RAM changes little. If they don't fit, the computer keeps going back to much slower storage, and then more RAM helps.
  • "16 GB of memory means room for 16 GB of files." Files are kept in storage, the 512 GB in the advert. RAM is the working space for whatever is open right now, and it empties when the power goes.
  • "If it is on the screen, it is safely inside the computer." An open document sits in RAM. Until it is saved to storage, a power cut or a flat battery wipes it, because RAM is volatile.
Teacher's noteStart from a real advert or a phone's settings screen and ask which number is "memory" and which is "storage". Most learners have seen both numbers and assumed they meant the same thing. A desk and a bookshelf work as a picture: the desk is small but within reach, the shelf is big but you have to walk to it. The sticking point is telling an address from the content stored there. Run the 4 × 3 program and point at cell 13. The address stays 13 the whole time, while the content goes 0, 4, 8, 12.
Key points
  • Memory is numbered cells; n address bits reach 2ⁿ cells (32 bits = 4 GiB).
  • The same bits can be an instruction or data; how the CPU reaches them decides.
  • RAM is volatile working memory; SSDs and hard disks keep data without power.
  • Registers, cache, RAM, storage: each layer down is bigger and slower.

Practice questions from Memory and storage on edubun

Embed this quiz

Free to embed. Please keep the credit line.

Sources for this course (10)
  • (checked 2026-10-17)
  • Standards: NIST, "Prefixes for binary multiples" (physics.nist.gov/cuu/Units/binary.html: IEC approved kibi, mebi, gibi in December 1998; 1 B = 8 bit; 1 MiB = 1 048 576 B; 1 MB = 1 000 000 B; 1 GiB = 1 073 741 824 B; historical note: memory makers usually mean 2²⁰ bytes by megabyte, storage makers 1 000 000, and the "1.44 MB" diskette uses a megabyte of 1 024 000 bytes)
  • IETF RFC 20 "ASCII format for Network Interchange" (1969, 7-bit codes, A = 65, a = 97, 0 = 48)
  • IETF RFC 3629 "UTF-8, a transformation format of ISO 10646" (2003: 1 to 4 octets per character, ASCII unchanged, code points up to U+10FFFF, U+0800 to U+FFFF take three octets, "the first octet of a multi-octet sequence indicates the number of octets", example U+D55C U+AD6D U+C5B4 = ED 95 9C EA B5 AD EC 96 B4)
  • Official documentation: MDN Web Docs, "<color>" (hexadecimal colour notation #RRGGBB)
  • Intel, "Intel Chips" timeline poster (2012: Intel 4004 of 1971 with 2,300 transistors; 2nd generation Core 2010 with 1.16 billion)
  • Teaching model: the toy computer in the network-lab scene (16 cells of 8 bits, 4-bit opcode and 4-bit address) is made for this course, not a real chip. History blocks only (the logic-gates story and the von Neumann paragraph of the-cpu): George Boole, An Investigation of the Laws of Thought (1854, Project Gutenberg 15114)
  • Claude E. Shannon, "A Symbolic Analysis of Relay and Switching Circuits", Transactions of the AIEE vol. 57 (1938)
  • abstract of his MIT master's thesis. Computer History Museum, The Silicon Engine, "1947: Invention of the Point-Contact Transistor" (Bardeen and Brattain, December 1947, germanium)
  • John von Neumann, "First Draft of a Report on the EDVAC" (30 June 1945, Moore School, reprinted in IEEE Annals of the History of Computing 15:4, 1993).

Checked: 2026-10-17