Skip to content
Tutorials Center
My learning

Topics

Lesson 38 of 67 ยท Memory Hierarchy

RAM, ROM, SRAM, DRAM and Flash

Learn how SRAM, DRAM, ROM and flash store bits, why DRAM needs refresh, how SSDs differ from hard disks, with worked capacity and bandwidth calculations.

"Memory" is not one thing. The registers in a CPU, the cache, the RAM sticks in your laptop, the firmware chip that starts the machine and the SSD that holds your files each use a different physical technology, chosen for a different mix of speed, density, cost and permanence. Understanding how each one stores a bit tells you why the memory hierarchy looks the way it does.

This lesson covers the main families: SRAM, DRAM, ROM and its descendants, and flash. You will also compare SSDs and hard disks and work through the arithmetic that appears in exams and in real capacity planning. The calculations are runnable, but the hardware itself is shown in diagrams and tables.

A map of memory types

flowchart TD
  M["Semiconductor memory"] --> V["Volatile<br/>(loses data without power)"]
  M --> N["Non-volatile<br/>(keeps data)"]
  V --> SR["SRAM<br/>caches, registers"]
  V --> DR["DRAM<br/>main memory"]
  N --> ROM["ROM, PROM, EPROM"]
  N --> EE["EEPROM"]
  N --> FL["Flash: NOR and NAND"]

Volatile memories are fast working storage; non-volatile ones keep data when the power is off.

The word RAM (random access memory) means any location can be read in about the same time, regardless of address. In everyday talk "RAM" means DRAM, the main memory. ROM (read-only memory) originally meant memory written once at the factory; today it covers many chips that are read often and written rarely.

SRAM: fast, big cells

A static RAM cell stores a bit in a loop of transistors, two inverters that feed each other and hold either 0 or 1 as long as power is on. The standard cell uses six transistors (6T): four for the cross-coupled inverters and two access transistors that connect the cell to the bit lines.

  • Fast: reading just senses the stable value; there is no charge to restore. Access times under a nanosecond are possible.
  • No refresh: the value is held actively by the circuit.
  • Large and expensive: six transistors per bit take a lot of silicon, so on-chip SRAM holds megabytes, not gigabytes.
  • Uses: CPU registers, L1 to L3 caches, small buffers inside network and storage chips.

DRAM: dense, leaky cells

A dynamic RAM cell uses one transistor and one tiny capacitor (1T1C). The bit is the presence or absence of charge on the capacitor. That is far smaller than six transistors, so DRAM stores much more per chip and costs much less per byte. The price is three complications.

  1. Leakage and refresh: the capacitor leaks, and after a few tens of milliseconds the charge is unreliable. The memory controller must refresh every row regularly (the standard window is 64 ms), by reading it and writing it back.
  2. Destructive reads: sensing the charge drains the capacitor, so each read must be followed by a restore.
  3. Slower, structured access: cells sit in a grid of rows and columns. To read a word, the chip first activates a row, copying the whole row into a row buffer, then selects a column from that buffer, and finally precharges before another row can be opened.
flowchart LR
  A["Activate row<br/>(open a row into the row buffer)"] --> C["Read or write column<br/>(fast if row already open)"]
  C --> C2["More columns<br/>of the same row"]
  C2 --> P["Precharge<br/>(close the row)"]

A row hit is cheap; switching to a different row costs precharge plus activate.

This structure explains why reading consecutive addresses is much faster than jumping around: consecutive bytes usually live in the same open row. It is spatial locality again, this time inside the chip. Modern DRAM (DDR4, DDR5) also transfers data on both edges of the clock and splits storage into banks and bank groups, so several rows can be worked on in parallel.

Capacity, refresh and bandwidth by calculation

The following program answers three typical questions: how many bytes a chip holds given its address and data lines, how much time refresh consumes, and what the peak bandwidth of a memory channel is.

Python Capacity, refresh overhead and bandwidth

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Some points from the output:

  • A chip with 26 address lines and 8 data bits holds 2^26 bytes, which is 64 MiB. Each extra address line doubles the capacity; each extra data line multiplies the bits per word.
  • With the typical numbers used here, refresh occupies about 4.5% of the time. Larger chips need longer refresh commands, so the overhead grows with density, and it is one reason controllers schedule refreshes cleverly.
  • Peak bandwidth is the transfer rate times the bus width. DDR4-3200 means 3,200 million transfers per second; a 64-bit (8-byte) channel therefore moves 25.6 GB/s at best. The number in the product name is the transfer rate, not the clock: the real clock is half of it, because data moves on both clock edges. Two channels double the peak. Real programs see less, because of row switches, refresh and access patterns.

Note that bandwidth (bytes per second) and latency (time for the first byte) are different things. DRAM latency has hardly improved in twenty years, about 60 to 90 ns for a random access, while bandwidth has multiplied. Caches and prefetching exist to hide that gap.

The DRAM family: from asynchronous to DDR5

The 1T1C cell has hardly changed, but the interface around it has been redesigned many times. Each step mainly raised bandwidth, because the cell array itself stays slow.

  • Asynchronous DRAM (ADRAM, FPM and EDO): the chip has no clock. The controller drives the row address strobe (RAS) and column address strobe (CAS) lines, and the data appears after a fixed delay. Fast page mode and EDO let several columns of an open row be read without repeating the row address. Timing is set by the signals, not by a clock edge.
  • Synchronous DRAM (SDRAM): a clock coordinates the controller and the chip. Commands are latched on clock edges, the chip has several internal banks that work in overlapped fashion, and it supports burst transfers of consecutive words. Plain SDRAM is also called single data rate (SDR) because it moves one word per clock.
  • Double data rate (DDR) SDRAM: transfers data on both the rising and the falling clock edge, so the transfer rate is twice the clock. Each generation (DDR, DDR2, DDR3, DDR4, DDR5) raises the clock, lowers the voltage, prefetches more bits per access from the array and adds banks. DDR5 also splits each module into two independent 32-bit sub-channels.
  • Rambus DRAM (RDRAM): a narrow 16-bit channel driven at a very high clock, with a packet-based protocol. It was faster per pin than SDRAM around 2000, but it was expensive, hot and licensed, so DDR won.
  • Cache DRAM (CDRAM): a DRAM die with a small SRAM cache on the same chip. Repeated accesses to recently used rows are answered from the on-chip cache, which hides the row-activation delay.
  • Graphics and mobile variants: GDDR and HBM favor bandwidth for GPUs, LPDDR favors low power for phones and laptops.
Python Peak bandwidth across DRAM generations

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The table shows the trend: from SDR to DDR5 the peak rate of one 64-bit channel grows about fifty times, mostly through faster clocks and the double-edge trick. RDRAM's narrow channel kept its peak low even at a high clock, which is part of why it lost the market. The product name (DDR4-3200) quotes the transfer rate, while the clock is half of that.

ROM and its descendants

A mask ROM has its contents burned in during manufacturing, by the presence or absence of a transistor at each cell. It is cheap in volume and cannot be changed. The family evolved toward changeability:

Type How it is written How it is erased
Mask ROM at the factory never
PROM once, by the user (fuses) never
EPROM electrically, with a programmer by ultraviolet light, whole chip
EEPROM electrically, in-circuit electrically, byte by byte
Flash electrically, in pages electrically, in large blocks

The trade-offs are simple. ROM is non-volatile, cheap in bulk and safe from accidental changes, which suits fixed code. But mask ROM cannot be fixed after a manufacturing run, a programmable part is slower and costlier to modify, and even EEPROM and flash wear out after many erase cycles. Programmable logic devices (PLDs) are sometimes used as ROM-like look-up tables for the same reason: the contents are fixed at programming time.

Firmware such as a BIOS or UEFI image, the boot code in a microcontroller and the microcode of a CPU live in this kind of memory, because it must be there the instant power arrives.

Flash memory

Flash stores a bit as charge trapped on an electrically isolated floating gate (or a charge-trap layer) in a transistor. The trapped charge shifts the voltage at which the transistor turns on, and the chip senses that shift. The charge stays for years without power.

There are two main layouts:

  • NOR flash: cells are wired in parallel, giving fast random reads and byte-level addressing. Used for firmware that executes directly from the chip. Lower density, higher cost per bit.
  • NAND flash: cells are wired in series strings, giving high density and low cost. Reads and writes happen in pages (typically 4 to 16 KB), and erases in blocks of hundreds of pages. Used in SSDs, phones and memory cards.

Flash has a rule that shapes all SSD design: a page can only be written when it is empty, and only a whole block can be erased. To update data, the drive writes the new version to a fresh page and marks the old one stale. Later a garbage collector moves live pages out of a mostly stale block and erases it. Two consequences follow:

  • Wear: each erase damages the cell oxide slightly, so every block survives only a limited number of program/erase cycles (from a few hundred for dense QLC to tens of thousands for SLC). A wear-levelling algorithm spreads writes evenly.
  • Write amplification: internal copying means the drive writes more to the flash than the host asked for. Manufacturers publish an endurance rating in TBW (terabytes written).

SSD versus hard disk

A hard disk drive (HDD) is mechanical: spinning platters, a moving arm, and the delays you will study in Disks, SSDs and RAID. An SSD has no moving parts. The two differ most in random access.

Python SSD and HDD timing and endurance

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

For one large sequential read the SATA SSD is only 3 to 4 times faster than the disk, and an NVMe drive over 20 times. For 10,000 random 4 KB reads the gap explodes: about 122 seconds on the disk, because every access needs a seek and a half-rotation (about 12 ms, or 82 operations per second), against about 1 second on either SSD. That is why replacing an HDD with an SSD makes an old machine feel new: operating systems and databases are mostly random access.

HDDs still win on cost per terabyte, which is why they hold archives, backups and cloud object storage. The last line shows the endurance calculation: a drive rated for 300 TB written survives about 16 years of 50 GB per day, so for ordinary use wear is rarely the limit.

Comparison at a glance

SRAM DRAM NAND flash HDD
Storage element 6 transistors 1 transistor + capacitor floating-gate transistor magnetic domain
Volatile yes yes no no
Typical latency about 1 ns 60-90 ns tens of microseconds milliseconds
Cost per GB highest medium low lowest
Refresh needed no yes no no
Typical role cache main memory SSD, phone storage bulk storage

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Why does DRAM need refresh but SRAM does not?

    A DRAM capacitor loses charge within milliseconds and must be rewritten. An SRAM cell actively holds its value while powered.
  2. 2. A memory chip has 24 address lines and 16 data lines. How many bytes can it store?

    2^24 words x 16 bits = 2^24 x 2 bytes = 32 MiB.
  3. 3. What is the peak bandwidth of one 64-bit channel of DDR4-3200?

    3,200 million transfers per second x 8 bytes per transfer = 25.6 GB/s.
  4. 4. Why can a NAND flash drive not simply overwrite a page in place?

    Writing can only turn an empty cell into a programmed one. Clearing needs a block erase, so drives write new data elsewhere and garbage-collect old blocks later.
  5. 5. Which workload shows the biggest advantage of an SSD over an HDD?

    An HDD pays a seek and rotation delay (about 12 ms) per random access, an SSD pays tens of microseconds, a difference of two orders of magnitude.

Summary

  • SRAM (6 transistors per bit) is fast and needs no refresh but is large and costly, so it makes registers and caches.
  • DRAM (one transistor and a capacitor) is dense and cheap but leaks, needs periodic refresh and has row/column structure that rewards sequential access.
  • ROM, PROM, EPROM, EEPROM and flash form a family of non-volatile memories with increasing ease of rewriting.
  • NAND flash writes in pages and erases in blocks, so SSDs use garbage collection, wear levelling and have an endurance rating.
  • Capacity is 2^address lines x data width; peak bandwidth is transfers per second x bytes per transfer x channels.
  • SSDs beat HDDs most on random access; HDDs keep an edge in cost per terabyte.

Next, see how the fast SRAM layer is organised in Cache Memory Basics.