Unplug a laptop in the middle of writing an essay and the unsaved part is gone, but the files you saved last week are still there when it switches on again. Both RAM and the SSD hold 0s and 1s, so why does one forget and the other remember? The answer is in how RAM, hard disks and SSDs store data physically: RAM keeps each bit as a tiny electric charge that drains away, a hard disk as a pattern of magnetism, and an SSD as electrons trapped behind a wall of insulation.
This lesson goes inside each one: the transistor-and-capacitor cell of RAM and why it needs refreshing, the spinning magnetic platters of a hard disk, and the flash memory cells of an SSD, including why they wear out. Knowing this explains the speed table in CPU, GPU, RAM and storage, and why some data is lost in a power cut and some isn't.
What you need first: transistors: how a computer understands binary and from logic gates to a CPU.
Key terms
- Volatile memory: loses its data when the power goes off. RAM is volatile.
- Non-volatile storage: keeps its data without power. Hard disks, SSDs and pen drives are non-volatile.
- Capacitor: a tiny component that stores electric charge, like a very small, very leaky battery.
- SRAM (static RAM): memory that stores each bit in a loop of transistors (a flip-flop). Fast and used for CPU caches.
- DRAM (dynamic RAM): memory that stores each bit as charge on a capacitor. Cheaper and denser; used for main RAM.
- Refresh: reading and rewriting DRAM cells regularly, before their charge leaks away.
- Flash memory: non-volatile memory that traps electrons in a cell. Used in SSDs, phones and pen drives.
- Magnetic domain: a tiny region of a hard disk's surface magnetised in one direction, storing one bit.
RAM: bits as electricity
SRAM: a loop that holds a bit
The CPU's registers and caches use SRAM. Each bit is a small latch, usually 6 transistors wired as two NOT gates in a loop, the same feedback idea as the SR latch in from logic gates to a CPU. As long as power flows, the loop keeps holding its value, with no refreshing needed.
SRAM is very fast, but 6 transistors per bit take a lot of space, so it's used only where speed matters most: a CPU has a few megabytes of SRAM cache, not gigabytes.
DRAM: a bucket of charge
Your laptop's 8 or 16 GB of main RAM is DRAM. Each bit is just one transistor and one capacitor:
- Capacitor charged = 1.
- Capacitor empty = 0.
- The transistor is a gate that connects the capacitor to a wire when that row of memory is selected, so the charge can be read or changed.
row select (word line)
|
data ──[transistor]──[capacitor]── ground
(bit line) charged = 1
empty = 0
With only two parts per bit, DRAM packs billions of bits onto a chip cheaply. The catch: the capacitor is so tiny that its charge leaks away within milliseconds, like a bucket with a small hole. So the memory controller refreshes every row on a fixed schedule: it reads each cell and writes the value back at full strength. Standard DDR memory refreshes every row within 64 milliseconds, thousands of times a minute, all the time the computer is on.
Reading a DRAM cell also drains it, so every read is followed by a write-back. That's part of why DRAM is slower than SRAM.
Why RAM forgets in a power cut
Both kinds need power to keep working. SRAM's loop stops the moment power goes; DRAM can't be refreshed, so its capacitors drain empty within a fraction of a second. Every bit becomes meaningless, which is why anything not saved to storage is lost.
| SRAM | DRAM | |
|---|---|---|
| One bit uses | 6 transistors | 1 transistor + 1 capacitor |
| Speed | Fastest | Fast, but slower than SRAM |
| Needs refresh? | No | Yes, every row within about 64 ms |
| Cost per bit | High | Low |
| Used for | CPU registers and caches | Main memory (the "8 GB RAM" in adverts) |
| Without power | Lost | Lost |
Hard disks: bits as magnetism
A hard disk drive (HDD) stores bits magnetically, the same idea as a fridge magnet that keeps its magnetism for years without any power.
Inside a sealed HDD:
- Platters: rigid discs coated with a thin magnetic layer, spinning at 5,400 or 7,200 revolutions per minute in most laptops and desktops.
- Tracks and sectors: each platter surface is divided into circular tracks, and each track into sectors, traditionally 512 bytes and now usually 4,096 bytes each.
- Read/write head: on the end of a moving arm, floating a few nanometres above the spinning surface on a cushion of air.
To write, the head creates a small magnetic field that points each tiny region (magnetic domain) of the surface one way or the other. To read, the head senses the direction as each region passes under it. In practice, bits are stored as changes in direction between regions, which is easier to read reliably.
Why a hard disk remembers without power
Once a region is magnetised, nothing needs to hold it there. Magnetism in these materials stays put for years. Power is needed only to spin the platters and move the head, not to keep the data.
Why hard disks are slow
To read a sector, the arm must move to the right track (the seek), then wait for the sector to spin round under the head (rotational delay). At 7,200 RPM, one revolution takes:
rpm = 7200
ms_per_revolution = 60_000 / rpm
print(round(ms_per_revolution, 2), "ms per revolution")
print(round(ms_per_revolution / 2, 2), "ms average wait for the right sector")
8.33 ms per revolution
4.17 ms average wait for the right sector
Add a few milliseconds of seek time, and each random read takes around 10 ms. In that time, a 3 GHz CPU completes 30 million clock ticks. That's why moving from an HDD to an SSD makes a computer feel so much faster, and why HDDs are fragile: a knock while the head is floating nanometres above the platter can scratch it.
SSDs: bits as trapped electrons
An SSD has no moving parts. It stores data in NAND flash memory: billions of cells, each a special transistor with an extra, insulated layer between its gate and its channel.
That extra layer is the trick. It's called a floating gate in older designs, or a charge trap in most modern ones. It's surrounded by insulating material, so electrons placed there have nowhere to go:
- To write (program) a cell, a relatively high voltage pushes electrons through the thin insulator into the trap, where they stay.
- To read a cell, the controller applies a voltage to the gate and checks whether current flows. Trapped electrons make the transistor harder to switch on (they raise its threshold voltage), so the controller can tell how much charge is in the trap.
- To erase, a voltage in the opposite direction pulls the electrons back out.
control gate
─────────────
insulator
─────────────
charge trap <- electrons stored here: the data
─────────────
thin insulator
─────────────
channel between source and drain
Why an SSD remembers without power
The electrons are surrounded by insulator, so there's no path for them to leave. They stay for years with no power at all. That's what makes flash non-volatile, and why a pen drive keeps your files in a drawer.
It isn't for ever, though. Over a long time (years), a few electrons slowly leak, especially in worn cells and warm conditions. An SSD left unpowered for a very long time can start to lose data, which is why SSDs aren't ideal for long-term archives.
More than one bit per cell
Instead of just "charged" or "empty", modern cells store several charge levels, so one cell holds several bits:
| Type | Bits per cell | Charge levels to tell apart | Trade-off |
|---|---|---|---|
| SLC (single-level cell) | 1 | 2 | Fastest, longest life, most expensive |
| MLC (multi-level cell) | 2 | 4 | |
| TLC (triple-level cell) | 3 | 8 | Most common in laptops today |
| QLC (quad-level cell) | 4 | 16 | Cheapest per GB, slower writes, shorter life |
The number of levels is 2 to the power of the bits per cell:
for name, bits in [("SLC", 1), ("MLC", 2), ("TLC", 3), ("QLC", 4)]:
print(f"{name}: {bits} bit(s) per cell needs {2 ** bits} charge levels")
SLC: 1 bit(s) per cell needs 2 charge levels
MLC: 2 bit(s) per cell needs 4 charge levels
TLC: 3 bit(s) per cell needs 8 charge levels
QLC: 4 bit(s) per cell needs 16 charge levels
More levels squeezed into the same voltage range means smaller gaps between them, so reading is harder and more error-prone. SSDs use strong error-correcting codes to fix the mistakes. (It's the same reason computers use binary in the first place, from the transistors lesson.)
Pages, blocks and wear
Flash has two rules that shape how SSDs work:
- Write in pages, erase in blocks. Data is written in pages (a few kilobytes), but a page can't be overwritten directly; it must first be erased, and erasing only works on a whole block of hundreds of pages.
- Cells wear out. Each erase pushes electrons through the insulator, which slowly damages it. A TLC cell lasts roughly a few thousand program/erase cycles.
The SSD's controller (a small processor running firmware) hides all this. It writes new data to fresh pages instead of overwriting, keeps a map of where each piece of your data really is, cleans up old blocks in the background (garbage collection), and spreads writes evenly across all cells (wear levelling) so no area wears out early. The operating system's TRIM command tells the SSD which pages hold deleted files, so it can clean them up in advance.
SSD makers rate drives in TBW (terabytes written). A 500 GB SSD rated at 300 TBW could take 300 TB of writes:
tbw = 300 # terabytes written, from the drive's specifications
gb_written_per_day = 30 # a busy developer's day
years = tbw * 1000 / gb_written_per_day / 365
print(round(years, 1), "years")
27.4 years
For normal use, an SSD's lifespan isn't something to worry about.
All three compared
| DRAM (RAM) | HDD | SSD (NAND flash) | |
|---|---|---|---|
| A bit is | Charge on a capacitor | Direction of magnetism | Electrons trapped in an insulated cell |
| Keeps data without power? | No | Yes | Yes |
| Moving parts | None | Spinning platters, moving arm | None |
| Random read time (rough) | About 100 nanoseconds | About 10 milliseconds | About 0.1 milliseconds |
| Wears out from writing? | No | Mechanical wear | Yes, slowly; managed by the controller |
| Cost per GB | Highest | Lowest | In between |
So the computer keeps everything permanently on the SSD or HDD, and copies what it's working on into RAM, which is far faster but forgets. "Saving" means copying from RAM back to storage.
Practice
- Why must DRAM be refreshed, but SRAM needn't be?
Show the answer
DRAM stores each bit as charge on a tiny capacitor, which leaks away in milliseconds, so it must be read and rewritten regularly. SRAM stores each bit in a loop of transistors that holds its state as long as there's power.
- Explain, in terms of how the bits are stored, why your saved files survive a power cut but unsaved work doesn't.
Show the answer
Unsaved work is only in RAM, as charges on capacitors that need power and refreshing; without power they drain within a fraction of a second. Saved files are on an SSD (electrons trapped behind insulation) or HDD (magnetised regions), which stay put without any power.
- How long is one revolution of a 5,400 RPM hard disk, in milliseconds?
Show the answer
print(round(60_000 / 5400, 2))
11.11
About 11.1 ms, so the average wait for a sector is about 5.6 ms, slower than a 7,200 RPM disk.
- A QLC SSD stores 4 bits per cell. How many charge levels must each cell tell apart, and why does that make it wear out sooner?
Show the answer
2⁴ = 16 levels. The levels are packed close together, so a small amount of damage or leaked charge can shift a cell into the wrong level, and it becomes unreliable after fewer erase cycles than SLC or TLC.
- Why can't an SSD simply overwrite a page in place, and what does it do instead?
Show the answer
Flash pages must be erased before they're written again, and erasing only works on whole blocks of many pages. So the controller writes the new data to an empty page, updates its map, marks the old page as stale, and erases whole blocks later during garbage collection.
Interview questions
What is the difference between SRAM and DRAM?
SRAM stores each bit in a bistable latch of about six transistors; it's fast, needs no refresh and is used for caches. DRAM stores each bit as charge on a capacitor with one access transistor; it's denser and cheaper but slower and must be refreshed periodically. Both are volatile.
Why is flash memory non-volatile?
Each flash cell stores charge in a floating gate or charge-trap layer completely surrounded by insulating material, so the electrons can't escape without a deliberate high voltage. The stored charge changes the transistor's threshold voltage, which can be sensed to read the bit, and it persists without power.
What is wear levelling?
A technique in the SSD controller that spreads writes and erases evenly across all flash blocks, by remapping logical addresses to different physical blocks. It prevents frequently written areas from wearing out early, since each cell survives only a limited number of program/erase cycles.
Key takeaways
- SRAM holds bits in transistor loops (fast, for caches); DRAM holds them as capacitor charge (dense, for main RAM) and must be refreshed.
- RAM is volatile: without power, the loops stop and the capacitors drain, so unsaved work is lost.
- A hard disk stores bits as magnetised regions on spinning platters; magnetism stays without power, but moving parts make it slow.
- An SSD traps electrons in insulated flash cells, which stay for years without power; cells can hold 1 to 4 bits each.
- Flash writes in pages, erases in blocks and slowly wears out; the controller's wear levelling and garbage collection manage this.
Frequently asked questions
Is RAM faster than an SSD?
Yes, by a lot: RAM answers in about 100 nanoseconds, while even a fast NVMe SSD takes tens of microseconds. That's why programs and data are copied into RAM before the CPU works on them.
Can an SSD lose data if it is not used?
Over long periods without power, yes, slowly, especially if the drive is old, heavily used and kept somewhere hot. For backups you'll store for years, keep more than one copy, and plug drives in now and then.
Is a pen drive the same as an SSD?
Both use NAND flash, but a pen drive has a much simpler controller, cheaper flash and a slower connection, so it's slower and less durable. Memory cards and phone storage are flash too.
What to learn next
- See how programs organise RAM in stack and heap memory.
- Revise the speed of each kind of memory in CPU, GPU, RAM and storage.
- Revise the latch that SRAM uses in from logic gates to a CPU.