Primary storage, secondary storage and virtual memory
A computer keeps data in two kinds of storage. Primary storage, the RAM and the ROM, is used directly by the CPU. Secondary storage keeps data when the power is off. This lesson explains both, why a computer needs RAM and ROM, and how virtual memory lets it run more than its RAM can hold.
about 25 min1 simulation1 practice question
Lesson 1 of 3Show all lessonsHide
Try the code and the simulations beside the lesson.
Two kinds of storage
Think of a desk and a cupboard. The desk holds what you are working on now, close at hand. The cupboard holds everything else, safe until you need it. A computer has the same two kinds of storage.
Primary storage
Primary storage is directly accessed by the CPU. It holds what the computer is using now. There are two kinds.
RAM (random access memory) holds the programs and data that are in use: the operating system, the open programs and the files you are working on. It can be read and written. RAM is volatile: everything in it is lost when the power is switched off.
ROM (read only memory) holds instructions that never change, such as the instructions that start the computer when it is switched on. It can be read but not changed. ROM is non-volatile: it keeps its contents with no power.
Why both? When the computer is switched on, RAM is empty. The CPU needs instructions at once, so the start-up instructions must be kept in ROM, which keeps them without power. But ROM cannot be changed. The programs and data that you use change all the time, so they need RAM, which can be written to.
Secondary storage
Secondary storage is not directly accessed by the CPU. It is necessary for the more permanent storage of data. It is non-volatile, so your files, your programs and the operating system stay there when the computer is off. A program is copied from secondary storage into RAM before it runs. Hard disk drives and solid-state drives are secondary storage. The next lesson explains how they work.
A diagram with the CPU in the middle. RAM and ROM sit right next to it, joined directly to it and labelled primary storage, directly accessed by the CPU. Further away is a box labelled secondary storage, such as an HDD or SSD, with an arrow showing that its data is copied into RAM before the CPU uses it.
The picture shows the CPU joined directly to the RAM and the ROM. The secondary storage is further away. Its data must be copied into RAM before the CPU can use it.
Virtual memory
What happens when you open so many programs that the RAM is full? The computer uses virtual memory.
How it is created. The operating system sets aside part of the secondary storage, on the hard disk drive or solid-state drive, to be used as if it were extra RAM.
How it is used. Data is split into blocks called pages. Pages that are not needed at this moment are moved out of RAM into virtual memory. When one of those pages is needed again, it is moved back into RAM, and another page may be moved out to make room. Pages of data are transferred between RAM and virtual memory when needed.
Why it is necessary. Without it, the computer could not open another program once the RAM was full, or it could stop working. Virtual memory lets it run more programs, or larger ones, than its RAM can hold.
Virtual memory is much slower than RAM, because secondary storage is slower. If pages move back and forth all the time, the computer becomes very slow. Fitting more RAM is the real cure.
Practise with new numbers
Try it in Python
The program is a simple model of virtual memory. RAM has room for three pages. When a page is needed and RAM is full, the page that has been in RAM longest moves out to virtual memory.
Common mistakes
Mixing up volatile and non-volatile. RAM is volatile and loses its data. ROM keeps its data.
Saying ROM holds your files. ROM holds fixed instructions, such as the start-up instructions. Your files are on secondary storage.
Saying virtual memory is extra RAM chips. It is part of the secondary storage, used as if it were RAM.
Saying the CPU runs programs straight from the hard disk. A program is copied into RAM first.
Remember these
Primary storage is directly accessed by the CPU: RAM and ROM.
RAM: read and write, volatile, holds what is in use. ROM: read only, non-volatile, holds the start-up instructions.
Secondary storage is not directly accessed by the CPU and keeps data permanently.
Virtual memory: part of secondary storage used as RAM. Pages move between RAM and virtual memory when needed.
Check yourself
Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.
What does volatile mean?
Where are the instructions that start the computer kept? Why there?
Is a solid-state drive primary or secondary storage?
What is moved between RAM and virtual memory?
Why does a computer slow down when it uses a lot of virtual memory?
References
Cambridge International, IGCSE Computer Science 0478 syllabus (2026, 2027 and 2028), section 3.3 Data storage, outcomes 1, 2 and 4: primary storage, secondary storage and virtual memory.
Enroll free in Storage, the Cloud and Network Hardware
Every lesson is open to read. Enrolling also lets you:
Mark lessons done and carry on where you stopped.
Take the tests of this lesson and its course.
Count the course towards the certificate for its chapter.