A computer needs places to keep programs and data. Some memory is very fast and close to the CPU, and some is slower but holds far more. This lesson explains the memory hierarchy and why computers use several kinds of storage.

Primary memory

Primary memory is directly accessible by the CPU.

  • RAM (random access memory): holds the programs and data currently in use. It is fast but volatile: its contents are lost when power is removed.
  • ROM (read-only memory): holds permanent instructions such as the firmware that starts the computer (BIOS/UEFI). It is non-volatile.
  • Cache: a small, very fast memory between the CPU and RAM that stores frequently used data and instructions. It is organised in levels (L1 is smallest and fastest, then L2, L3). A cache hit saves a slower trip to RAM.
  • Registers: the fastest storage of all, inside the CPU itself.

Secondary storage

Secondary storage is non-volatile and used for long-term storage. The CPU cannot run code directly from it; data must be loaded into RAM first.

  • Magnetic (hard disk drive): spinning platters and read/write heads. Cheap per gigabyte and high capacity, but slower and sensitive to shocks.
  • Solid state (SSD, flash, USB drives): no moving parts, so it is faster, quieter and more durable, though usually more expensive per gigabyte.
  • Optical (CD, DVD, Blu-ray): data read with a laser. Cheap and portable, but low capacity and slow, and largely declining.
  • Cloud storage: data held on remote servers and reached over a network. Convenient and scalable, but depends on connectivity and trust in the provider.

The memory hierarchy

Moving down the hierarchy, from registers to cache to RAM to SSD or HDD, capacity increases while speed decreases and cost per byte drops. Computers combine these to get the best compromise: a small amount of expensive fast memory, and a large amount of cheap slow memory.

Example: when you open a game, it is copied from the SSD into RAM. The most-used instructions get pulled into cache, and the CPU holds the values it is working on in registers.

Virtual memory

When RAM is full, the operating system can use part of secondary storage as virtual memory. This lets more programs run than RAM alone would allow, but it is much slower, and heavy use leads to a slowdown known as thrashing.

Check your understanding

Which memory is volatile?

  • ROM
  • RAM
  • SSD
  • Optical disc

Answer: RAM. It loses its contents when power is off.

Why does a computer use cache?

  • To permanently store files
  • To give the CPU quick access to frequently used data
  • To increase screen resolution
  • To connect to the internet

Answer: To give the CPU quick access to frequently used data. It reduces slower RAM accesses.

Which statement about SSDs compared to HDDs is correct?

  • SSDs have moving parts
  • SSDs are generally faster and more durable
  • SSDs are volatile
  • SSDs cannot store programs

Answer: SSDs are generally faster and more durable. They have no moving parts.

What is virtual memory?

  • Memory inside the CPU
  • Secondary storage used as an extension of RAM
  • A type of ROM
  • A graphics card

Answer: Secondary storage used as an extension of RAM. It is slower than real RAM.