CPU, RAM, and storage: the kitchen analogy
On This Lesson 11 topics
Lesson Overview
In the last lesson you learned that every computer does four jobs: input, processing, storage, and output. This lesson names the real parts that do the work, and explains the one idea beginners most often get wrong: a computer has two different kinds of storage, and it needs both.
We will use a kitchen as a picture to hold the ideas. A cook does the work, a counter holds what the cook is using right now, and a pantry and fridge keep ingredients for later. By the end, "Why did I lose my unsaved document when the power went out?" will have a clear answer.
Why this matters: when you build backend services you will constantly decide what to keep in fast, temporary memory and what to write to permanent storage. Those choices, and the performance and safety consequences that follow, all start from this lesson.
This lesson builds on "What a computer actually does". It needs no other background.
Learning Objectives
By the end of this lesson you will be able to:
- Name the main parts of a computer (CPU, RAM, storage, input and output devices, motherboard) and state each one's job.
- Map the four steps from Lesson 1 to the parts that carry them out.
- Explain, using the kitchen analogy, the difference between RAM and storage.
- Explain why data in RAM is lost when the power goes off while data on an SSD is not.
- Describe what "saving" a file really does.
- Say which of two statements about "memory" and "storage" is correct, and avoid confusing capacity of one with the other.
- Name where the analogy stops being accurate.
Written Explanation
The four parts you need to know
Open any computer, from a laptop to a server, and the following parts do the jobs from Lesson 1.
| Part | What it is | Job in the four steps |
|---|---|---|
| CPU (central processing unit) | The chip that follows instructions | Processing |
| RAM (random-access memory) | Fast, temporary working memory | Holds what is in use right now |
| Storage (SSD or hard drive) | Slower, permanent memory | Storage: keeps data for later |
| Input and output devices | Keyboard, touch screen, microphone, monitor, speakers, network card | Input and output |
A fifth part ties them together: the motherboard, the main circuit board that connects the CPU, the memory slots, the storage, and the other devices so that they can talk to one another. You rarely need to think about it, but it is why the parts work as one machine.
The Kansas State University CC 110 textbook describes the CPU as doing "all of the computation and calculation", RAM as the memory the computer uses for the program it is running and the data it is working on, and the hard drive or SSD as longer-term storage that persists "even while the computer is turned off". Those three sentences are the core of this lesson.
The kitchen analogy
Picture a busy kitchen.
| In the kitchen | In the computer | What it does |
|---|---|---|
| The cook | CPU | Does the work, one small step at a time, following the recipe |
| The recipe | A program | The instructions the cook follows |
| The counter | RAM | Holds the ingredients and the recipe the cook is using right now |
| The pantry and fridge | Storage (SSD or hard drive) | Keeps ingredients for days, weeks, or months |
The cook can only work on what is on the counter. Ingredients in the pantry are no use until someone fetches them and puts them on the counter. When you open a program or a file, the computer does exactly that: it copies the program and its data from storage onto the "counter" (RAM) so the CPU can work on it quickly.
The cook: the CPU
The CPU reads an instruction, does it, then reads the next one. An instruction is a very small step, such as adding two numbers or comparing them. Programs get their power from running huge numbers of these small steps very fast.
Two specifications you will see on a computer:
- Clock speed, measured in gigahertz (GHz). A 3 GHz CPU ticks about three billion times per second. The tick is the CPU's beat, not a count of finished jobs: how much work gets done per tick depends on the design of the CPU.
- Cores. A core is one worker inside the CPU. A CPU with four cores is like a kitchen with four cooks: it can work on several things at the same time. More cooks help only when there are separate jobs to share.
The counter: RAM
RAM is where the computer keeps whatever it is using right now: the apps that are open, the document you are editing, the web page you are reading. It is very fast, so the CPU is not kept waiting.
RAM has two key properties:
- It is fast.
- It is volatile, which means it loses its contents when the power is switched off.
Think of the counter: when the restaurant closes, it is wiped clean. Whatever was only on the counter is gone.
RAM is also limited. A counter is a fixed size. A typical laptop has somewhere in the range of 8 to 32 GB, though the amount varies a lot between machines. When the counter is full, the computer has to make hard choices, which is one reason a machine with too little RAM feels slow. The next modules explain how the operating system handles that.
The pantry and fridge: storage
Storage keeps your files, photos, apps, and the operating system itself, even with the power off.
Storage is non-volatile: data stays there when the power goes away. There are two common kinds:
- An SSD (solid-state drive) stores data in flash memory chips with no moving parts. It is the standard choice in current laptops and phones.
- A hard disk drive (HDD) stores data on spinning magnetic disks. It usually costs less per gigabyte, and is generally slower.
Compared with RAM, storage is slower and usually much larger: capacities of hundreds of gigabytes to several terabytes are common, as against a few gigabytes to tens of gigabytes of RAM. Storage is the pantry: large and long-lasting, but fetching from it takes longer than reaching for something on the counter.
The two kinds of memory are a trade-off, not a design mistake. If RAM were as big and permanent as storage, it would be far more expensive, and it would not be as fast. Computers use both for the same reason a kitchen has both a counter and a pantry.
What "saving" really does
Now you can answer the question from the overview.
When you type in a document, the text lives in RAM, because that is where the program is working with it. Nothing has been written to storage yet. If the power fails now, RAM is wiped and the text is gone.
When you press Save, the program copies the document from RAM to storage. The copy in storage survives a power cut, because storage is non-volatile. Many apps also save automatically every minute or so, so you lose less when something goes wrong, but the principle is the same: protect data by copying it from RAM to storage.
When you open a file, the opposite happens: the computer copies the file from storage into RAM, then the program works on it there.
Text version of this diagram
Three boxes in a row: CPU (the cook, follows instructions), RAM (the counter, fast and temporary, lost without power) and Storage (the pantry, slower and larger, kept without power). A two-way arrow joins CPU and RAM. A curved arrow from storage to RAM is labelled Open: copy from storage to RAM. A curved arrow from RAM to storage is labelled Save: copy from RAM to storage.
Where the analogy stops
Every analogy leaks. Remember these differences from a real kitchen:
- A cook can carry things back and forth by hand. In a computer, copying between RAM and storage is done by the computer's own components, at a speed that depends on the hardware.
- A real counter is visible. RAM holds many things at once from many programs, and the operating system decides who gets which part. You will meet that in Lesson 4.
- A computer has even smaller, faster places for the data the CPU is working on at this very moment (called cache and registers). They do not change the basic picture of cook, counter, and pantry, so we do not need them in this course.
Examples
Example 1: opening and editing a photo (simple)
- The photo is stored on the SSD. It stays there with the computer switched off.
- You open it in an editor. The computer copies the photo into RAM.
- The CPU works on the copy in RAM when you brighten it.
- You press Save. The edited version is copied back to the SSD.
Until step 4, the brightened version exists only in RAM.
Example 2: a power cut while writing (practical)
You have written three paragraphs of a report and saved after the first. Then the power fails.
- The first paragraph was copied to storage when you saved, so it is still there.
- Paragraphs two and three existed only in RAM. They are lost, unless the app has an automatic recovery feature that had already saved a copy.
This is not a defect of the computer. It is how volatile memory works.
Example 3: a laptop with little RAM (realistic)
A laptop has 4 GB of RAM and you open a browser with many tabs, a video call, and a spreadsheet at the same time. The "counter" is full. The operating system has to shuffle work between RAM and the much slower storage, and everything feels sluggish. Adding RAM or closing apps frees counter space. The CPU may be perfectly able to keep up: the slowdown is not about the cook, it is about a crowded counter.
Backend Insight
Backend design makes this choice over and over: what lives in RAM and what goes to storage?
- A server that stores data only in RAM is fast, but if the server restarts, that data is gone. A shopping basket kept only in RAM is lost when the program restarts.
- Data that must not be lost, such as orders and payments, is written to storage, usually through a database, before the server tells the customer "done".
- Servers are often chosen by how much RAM and how many CPU cores they have, because those decide how many requests the server can work on at once. Slow storage can also become the bottleneck, which is why databases run on fast SSDs.
Later lessons teach how a database and a cache fit in. The idea to take with you: fast and temporary versus slower and permanent is one of the central trade-offs in backend engineering.
Common Mistakes
Mistake 1: Mixing up memory and storage
- Incorrect: "My laptop has 512 GB of memory."
- Correct: "My laptop has 512 GB of storage and 16 GB of RAM."
In everyday speech people say "memory" for both. In this course, RAM is memory (working space) and storage is the SSD or hard drive. When someone says "memory", ask which one they mean.
Mistake 2: Thinking more storage makes the computer faster
A bigger pantry does not make the cook faster. A computer that is slow because RAM is full will not speed up by adding storage. Match the fix to the cause: more RAM for a crowded counter, a faster CPU for slow work, a faster drive for slow fetching.
Mistake 3: Believing unsaved work is "somewhere on the computer"
- Incorrect: "It was open a minute ago, so it must be on the disk."
- Correct: "If I did not save it, it only lived in RAM, which is cleared when the power goes."
Mistake 4: Thinking the CPU stores your files
The CPU processes data. It does not keep your files. Files live in storage, and the part currently being worked on is held in RAM.
Exercises
Try each exercise yourself before opening the solutions.
Level A: Foundation
A1. In one sentence each, say what the CPU, RAM, and storage do.
Show solution A1
A1. The CPU follows instructions and does the processing. RAM holds the programs and data in use right now, quickly and temporarily. Storage keeps data for the long term, even without power.
A2. Which of these is volatile: RAM or an SSD? What does "volatile" mean?
Show solution A2
A2. RAM is volatile. Volatile means the data is lost when the power is switched off. An SSD is non-volatile, so its data stays.
A3. Match each to CPU, RAM, or storage: (a) the music library you built over ten years, (b) the part that adds two numbers, (c) the apps open on your screen right now.
Show solution A3
A3. (a) Storage. (b) CPU. (c) RAM.
Level B: Application
B1. You are writing an essay and have not pressed Save. A thunderstorm cuts the power. Explain, with the terms RAM and storage, what happens to the essay.
Show solution B1
B1. The essay was being held in RAM, which is wiped when power is lost, so the unsaved text is gone. Only text that was copied to storage by saving (or by an automatic save) survives. Pressing Save regularly copies the essay from RAM to storage.
B2. In the kitchen analogy, what does it mean to "open" an app, and what does it mean to "close" it?
Show solution B2
B2. Opening an app copies its program and data from storage into RAM so the CPU can work with it. Closing it frees that space in RAM (the counter is cleared for other uses). The app is still in storage, ready to open again.
B3. A friend says: "My computer is slow, so I will buy a bigger hard drive." Give one situation where that helps and one where it does not.
Show solution B3
B3. It helps if the drive is almost full and the user cannot save or install things, or if the old drive is a slow HDD and files load slowly. It does not help if the slowness comes from too little RAM or a slow CPU, because a larger drive does not give the computer a bigger counter or a faster cook.
Level C: Challenge
C1. A computer has a very fast CPU but only 2 GB of RAM, and a user keeps many large apps open. Explain, using the analogy, why it may still be slow.
Show solution C1
C1. The cook (CPU) is fast, but the counter (RAM) is small. With many large apps open the counter is full, so the computer has to keep moving things between RAM and the slower storage. The cook spends a lot of time waiting instead of working, so the whole kitchen feels slow.
C2. A website keeps each visitor's shopping basket only in the server's RAM. Describe one good thing and one risky thing about that design.
Show solution C2
C2. Good: RAM is very fast, so reading and changing the basket is quick. Risky: RAM is volatile, so if the server restarts or crashes, every basket is lost. A safer design keeps baskets in storage (for example a database), possibly with a fast RAM copy in front for speed.
Mini Challenge
Make a "kitchen map" of a device you use every day, a phone or a laptop. Draw or list:
- The cook, the counter, and the pantry, with the real name of each part on your device. If you can find the model or amounts (the processor name, RAM size, storage size), write them down. If you cannot find them yet, write "to find in Lesson 6".
- One thing in the pantry right now, and one thing on the counter right now.
- What happens in the kitchen when you take a photo and press Save, one step at a time.
Check your work: you used RAM only for temporary working memory and storage for permanent keeping, and your save story copies data from RAM to storage.
Summary & Next Lesson
Key takeaways
- The CPU does the processing. RAM is fast, temporary working memory. Storage (SSD or HDD) is slower, larger, and permanent.
- RAM is volatile: it loses data without power. Storage is non-volatile: it keeps data without power.
- Opening a file copies it from storage to RAM. Saving copies it from RAM to storage.
- RAM and storage are different things with different sizes. "Memory" usually means RAM in this course.
- In backend work, deciding what to keep in RAM and what to write to storage is a basic design decision.
Next lesson
You now know the parts. The next lesson, "Bits, bytes, and binary numbers", looks at what the data inside RAM and storage actually is: how a computer represents numbers, text, and photos using only two symbols.
Self-check
- Which part follows instructions: CPU, RAM, or storage?
- Why does an unsaved document disappear in a power cut?
- What does pressing Save do?
- A laptop has 512 GB and 16 GB. Which is storage and which is RAM?
- Name one reason a backend server must write important data to storage.
Show answers
- The CPU.
- It only existed in RAM, which loses its contents when the power is off.
- It copies the document from RAM to storage.
- 512 GB is storage and 16 GB is RAM.
- RAM is volatile, so important data kept only there would be lost if the server restarted or lost power. Storage keeps it.
References
- Kansas State University, CC 110 textbook, Computer Hardware. It describes the CPU, RAM, storage devices that persist while the computer is off, and the motherboard. The term "volatile" and the kitchen analogy are this course's own teaching additions.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.