---
title: "Memory and Storage"
book: "Primary & Middle School Computer Science"
subject: computer-science
language: en
chapter: 8
exercises: 11
source: https://one-course.com/books/computer-science/1/en/chapter/8-memory-and-storage
license: CC-BY-NC-SA-4.0
credit: "One Computer Science Book, One Course (one-course.com)"
---

# Chapter 8 — Memory and Storage

Mia has been playing a game for an hour. She has crossed three rivers and opened two castles. Suddenly the lights go out: the power is cut in the whole street. When it comes back and she starts the game again, she is back at the first river, where the game last saved her progress. The [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) forgot everything since then. Why does a [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) forget some things and keep others?

**You already know.**

The [processor](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-processor) carries out the [instructions](https://one-course.com/books/computer-science/1/en/chapter/2-instructions-in-order#def-g1-instructions-in-order-instruction); the [memory](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-memory) holds the work in progress and forgets it when the power goes off; the [storage](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-storage) keeps the saved work ([Chapter 6](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#ch-g3-inside-the-computer)).

## 8.1 RAM: fast, and emptied when the power goes

**Definition 8.1 (RAM).**

*RAM* (random-access [memory](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-memory)) is the [memory](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-memory) of a [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer): chips on small boards that hold the information the [processor](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-processor) is working on. The [processor](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-processor) can read and change any part of it very fast, in any order (this is what “random access” means), but everything in it is lost when the power goes off.

[RAM](#def-g4-memory-and-storage-ram) keeps information as tiny electric charges, which must be refreshed many times a second. When the electricity stops, the charges leak away within a moment, and the [RAM](#def-g4-memory-and-storage-ram) is empty. That is what happened to Mia’s game: her progress since the last save was only in the [RAM](#def-g4-memory-and-storage-ram).

![What Mia’s computer holds before and after the power cut. Only what was saved to the storage is still there.](https://one-course.com/images/onecourse/chapters/computer-science-1/g4-memory-and-storage/fig-397843c33cf3.svg)

*What Mia’s [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) holds before and after the power cut. Only what was saved to the [storage](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-storage) is still there.*

## 8.2 Storage that keeps everything

A [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) also needs a place where information stays without electricity. There are two main kinds.

**Definition 8.2 (Hard disk).**

A *hard disk* stores information on spinning metal disks covered with a thin magnetic layer. A read–write head, at the end of a moving arm, flies just above the surface: it writes by making tiny areas magnetic in one direction or the other, and reads them back.

The head never touches the disk: it floats on a cushion of air thinner than a hair. The disks turn thousands of times a minute, so a [hard disk](#def-g4-memory-and-storage-hard-disk) hums and gets warm, and a hard knock while it is running can make the head scratch the disk.

![A hard disk seen from above, and the head seen from the side (the gap is drawn far larger than it is).](https://one-course.com/images/onecourse/chapters/computer-science-1/g4-memory-and-storage/fig-9ec4306bbb95.svg)

*A [hard disk](#def-g4-memory-and-storage-hard-disk) seen from above, and the head seen from the side (the gap is drawn far larger than it is).*

![A real hard disk with its lid removed: the shiny disk, the arm with the head at its tip, and the pivot at the bottom. Photograph: Zzubnik, public domain.](https://one-course.com/images/onecourse/chapters/computer-science-1/g4-memory-and-storage/img-b9492c92ee7e.jpg)

*A real [hard disk](#def-g4-memory-and-storage-hard-disk) with its lid removed: the shiny disk, the arm with the head at its tip, and the pivot at the bottom. Photograph: Zzubnik, public domain.*

**Definition 8.3 (Flash memory and SSD).**

*Flash memory* keeps information as electric charges trapped in tiny cells of a chip, so tightly that they stay without electricity for years. An *SSD* (solid-state drive) is a [storage](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-storage) made of flash [memory](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-memory) chips, with no moving part.

USB sticks and the [memory](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-memory) cards of cameras and phones are made of [flash memory](#def-g4-memory-and-storage-flash) too. Phones, tablets and most new laptops have an [SSD](#def-g4-memory-and-storage-flash) instead of a [hard disk](#def-g4-memory-and-storage-hard-disk).

|  | [hard disk](#def-g4-memory-and-storage-hard-disk) | [SSD](#def-g4-memory-and-storage-flash), USB stick, [memory](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-memory) card |
| --- | --- | --- |
| how it keeps information | magnetic layer on spinning disks | charges trapped in chips |
| moving parts | yes: disks and an arm | none |
| speed | slower: the head must move | faster |
| noise | a soft hum | silent |
| if dropped while running | the disk can be scratched | usually no harm |

## 8.3 Measuring size in bytes

How much work can a [storage](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-storage) hold? We count it in [bytes](#def-g4-memory-and-storage-byte).

**Definition 8.4 (Byte).**

The *byte* is the unit used to measure the size of information in a [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer): one byte holds one letter of plain text.

**Definition 8.5 (Kilobyte, megabyte, gigabyte, terabyte).**

A *kilobyte* (kB) is $1000$ [bytes](#def-g4-memory-and-storage-byte). A *megabyte* (MB) is $1000$ kilobytes. A *gigabyte* (GB) is $1000$ megabytes. A *terabyte* (TB) is $1000$ gigabytes.

Each unit is a thousand times the one before, as a kilometre is a thousand metres. Let us compute a few sizes.

**Example 8.6 (A page, a photo, a film).**

- A page of a story has about $2000$ letters and spaces: about $2000$ [bytes](#def-g4-memory-and-storage-byte) , so about 2 [kilobytes](#def-g4-memory-and-storage-units) .
- A photo of $1000$ by $1000$ coloured dots has $1\,000\,000$ dots. If each dot is kept as 3 [bytes](#def-g4-memory-and-storage-byte) (one for each of three colours), the photo takes $3\,000\,000$ [bytes](#def-g4-memory-and-storage-byte) : 3 [megabytes](#def-g4-memory-and-storage-units) .
- A film shows 25 pictures every second. If each picture were kept like that photo, one second would take $25 \times 3 = 75$ [megabytes](#def-g4-memory-and-storage-units) , and one minute $60 \times 75 = 4500$ [megabytes](#def-g4-memory-and-storage-units) : 4.5 [gigabytes](#def-g4-memory-and-storage-units) . Real films are packed much more tightly; how this works comes in a later year.

![The ladder of sizes, from one letter to a terabyte. Each step is a thousand times the one below. A book of 250 pages of 2 kilobytes takes 500 kilobytes, so a terabyte holds two million such books.](https://one-course.com/images/onecourse/chapters/computer-science-1/g4-memory-and-storage/fig-601bff930166.svg)

*The ladder of sizes, from one letter to a [terabyte](#def-g4-memory-and-storage-units). Each step is a thousand times the one below. A book of 250 pages of 2 [kilobytes](#def-g4-memory-and-storage-units) takes 500 [kilobytes](#def-g4-memory-and-storage-units), so a [terabyte](#def-g4-memory-and-storage-units) holds two million such books.*

**Remark 8.7 (102410241024 instead of 100010001000).**

Some programs count a [kilobyte](#def-g4-memory-and-storage-units) as $1024$ [bytes](#def-g4-memory-and-storage-byte) instead of $1000$, for reasons we meet in a later year. The difference is small, but it is why a [storage](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-storage) sold as 500 [gigabytes](#def-g4-memory-and-storage-units) may be shown by the [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) as a little less. The careful name for $1024$ [bytes](#def-g4-memory-and-storage-byte) is a kibibyte (KiB).

**History — Five million letters on fifty disks.**

The first [hard disk](#def-g4-memory-and-storage-hard-disk) sold for a [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) was shipped in June 1956. It was a cabinet about $1.5\,\mathrm{m}$ high and $1.8\,\mathrm{m}$ wide that weighed, with its air pump, more than a tonne. Inside, 50 metal disks, each about $61\,\mathrm{c}\mathrm{m}$ across, turned $1200$ times a minute. All together they held five million letters: less than 4 [megabytes](#def-g4-memory-and-storage-units), the size of a single photo today.

![The stack of disks of a 1956 hard disk, in a museum. Photograph: Arnold Reinhold, CC BY-SA 3.0.](https://one-course.com/images/onecourse/chapters/computer-science-1/g4-memory-and-storage/img-e47c4bb8e5cf.jpg)

*The stack of disks of a 1956 [hard disk](#def-g4-memory-and-storage-hard-disk), in a museum. Photograph: Arnold Reinhold, CC BY-SA 3.0.*

## 8.4 Why keep a backup

[Storage](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-storage) keeps work when the power is off, but it is not safe forever. A [hard disk](#def-g4-memory-and-storage-hard-disk) can wear out, a laptop can be dropped, lost or stolen, a [file](https://one-course.com/books/computer-science/1/en/chapter/7-files-and-folders#def-g3-files-and-folders-file) can be deleted by mistake.

**Definition 8.8 (Backup).**

A *backup* is a second copy of [files](https://one-course.com/books/computer-science/1/en/chapter/7-files-and-folders#def-g3-files-and-folders-file), kept on another [storage](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-storage), in another place, so that they can be brought back if the first copy is lost.

![Backing up the family photos on an external disk.](https://one-course.com/images/onecourse/chapters/computer-science-1/g4-memory-and-storage/img-f1b9691e88b2.jpg)

*Backing up the family photos on an external disk.*

**Safe use.**

Keep a [backup](#def-g4-memory-and-storage-backup) of the work you care about, on another [device](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-device) and in another place (a disk kept at home for a school laptop, for example). Update it often: a [backup](#def-g4-memory-and-storage-backup) only holds what was there on the day it was made.

## 8.5 Exercises

**Exercise 8.1 ★.**

The power goes off. Which keeps the work: the [RAM](#def-g4-memory-and-storage-ram) or the [SSD](#def-g4-memory-and-storage-flash)?

**Solution of Exercise 8.1.**

The [SSD](#def-g4-memory-and-storage-flash). The [RAM](#def-g4-memory-and-storage-ram) is emptied when the power goes off.

**Exercise 8.2 ★.**

Give two differences between a [hard disk](#def-g4-memory-and-storage-hard-disk) and an [SSD](#def-g4-memory-and-storage-flash).

**Solution of Exercise 8.2.**

For example: a [hard disk](#def-g4-memory-and-storage-hard-disk) has moving parts (spinning disks and an arm), an [SSD](#def-g4-memory-and-storage-flash) has none; an [SSD](#def-g4-memory-and-storage-flash) is faster; a [hard disk](#def-g4-memory-and-storage-hard-disk) hums, an [SSD](#def-g4-memory-and-storage-flash) is silent; a [hard disk](#def-g4-memory-and-storage-hard-disk) can be scratched if it is knocked while running.

**Exercise 8.3 ★.**

How many [kilobytes](#def-g4-memory-and-storage-units) are there in 3 [megabytes](#def-g4-memory-and-storage-units)?

**Solution of Exercise 8.3.**

$3 \times 1000 = 3000$ [kilobytes](#def-g4-memory-and-storage-units).

**Exercise 8.4 ★.**

A page of text takes 2 [kilobytes](#def-g4-memory-and-storage-units). How many such pages fit in 1 [megabyte](#def-g4-memory-and-storage-units)?

**Solution of Exercise 8.4.**

1 [megabyte](#def-g4-memory-and-storage-units) is $1000$ [kilobytes](#def-g4-memory-and-storage-units), and $1000 \div 2 = 500$ pages.

**Exercise 8.5 ★.**

Put these sizes in order, from the smallest to the largest: 3 GB, 500 kB, 2 TB, 40 MB, 900 [bytes](#def-g4-memory-and-storage-byte).

**Solution of Exercise 8.5.**

900 [bytes](#def-g4-memory-and-storage-byte), 500 kB, 40 MB, 3 GB, 2 TB.

**Exercise 8.6 ★.**

Why should a [backup](#def-g4-memory-and-storage-backup) be kept in another place than the [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) it copies?

**Solution of Exercise 8.6.**

If the [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) is lost, stolen, or broken by a fire or a flood, a copy kept next to it may be lost at the same time. A copy kept elsewhere survives.

**Exercise 8.7 ★.**

Read the ladder of sizes: how big is one photo? About how many such photos fit in 1 [gigabyte](#def-g4-memory-and-storage-units)?

**Solution of Exercise 8.7.**

3 [megabytes](#def-g4-memory-and-storage-units). 1 [gigabyte](#def-g4-memory-and-storage-units) is $1000$ [megabytes](#def-g4-memory-and-storage-units), and $1000 \div 3$ is 333 with 1 left over: about 333 photos.

**Exercise 8.8 ★.**

A USB stick holds 64 [gigabytes](#def-g4-memory-and-storage-units). Each photo takes 4 [megabytes](#def-g4-memory-and-storage-units). How many photos fit on the stick?

**Solution of Exercise 8.8.**

64 [gigabytes](#def-g4-memory-and-storage-units) are $64 \times 1000 = 64\,000$ [megabytes](#def-g4-memory-and-storage-units), and $64\,000 \div 4 = 16\,000$ photos.

**Exercise 8.9 ★★.**

A story has $12\,000$ letters and spaces. How many [kilobytes](#def-g4-memory-and-storage-units) does it take?

**Solution of Exercise 8.9.**

$12\,000$ letters and spaces take $12\,000$ [bytes](#def-g4-memory-and-storage-byte), and $12\,000 \div 1000 = 12$ [kilobytes](#def-g4-memory-and-storage-units).

**Exercise 8.10 ★★.**

In the story at the start of this chapter, which part of the [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer) forgot Mia’s progress? Where was the progress she found again?

**Solution of Exercise 8.10.**

The [RAM](#def-g4-memory-and-storage-ram) forgot it: her progress since the last save was only there, and the [RAM](#def-g4-memory-and-storage-ram) is emptied when the power goes off. The progress she found again (the first river) was the game’s last save, kept in the [storage](https://one-course.com/books/computer-science/1/en/chapter/6-inside-the-computer#def-g3-inside-the-computer-storage).

**Exercise 8.11 ★★.**

The class keeps all its work on one school [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer). Make a plan of [backups](#def-g4-memory-and-storage-backup): on what, where, and how often.

**Solution of Exercise 8.11.**

Many plans are good. For example: every Friday, the teacher copies the class [folder](https://one-course.com/books/computer-science/1/en/chapter/7-files-and-folders#def-g3-files-and-folders-folder) onto an external disk; there are two such disks, used in turn, and one of them is always kept in another room or at home. A good plan says on what the copy is made, where it is kept (not next to the [computer](https://one-course.com/books/computer-science/1/en/chapter/1-what-is-a-computer#def-g1-what-is-a-computer-computer)), and how often (at least once a week).
