Technologeez: How computers store stuff

A couple of months ago, I asked people to share with me their questions about technology. I received a large variety of questions, most of which I don’t know how to answer well! I can only hope reading these posts will be as fun for you as it was for me to research them.

The question I’m going to start with is the hardest of them all, because it’s one of the most basic, yet most difficult:

I don’t actually understand how memory works. How is it possible for so much information to be stored on a tiny chip?

Shout out to Amy for this question :)

What this question is asking about, in general, is how computers understand and store data. Hard drives, memory chips, flash drives, CDs, floppy disks, punch cards…these are all data storage devices that use the exact same fundamental concepts I will describe. We will, for this post, use the example of a drive, because these are pretty much everywhere. But you can use these same ideas to understand the RAM chips in your laptop, the USB drive in your desk drawer, the SD card in your camera, and even things like WiFi (though we will leave that another post).

A hard drive is a pretty small thing. A modern smart phone, for example, can store 128 GB in a “hard drive” that is about the size of your thumb and 1 mm thick! How indeed is it possible for so much information to be stored in such a small amount of space? In my day-to-day life, I have a simple answer to this question: “Magic.” But, in an effort to be more thorough, I will attempt to expand upon the magic. Buckle your seat belts, because we’re about to start talking in 1’s and 0’s. Literally.

Let’s pretend we live in a world that has only two colors: red and blue. Here’s a picture that we could store on a computer in this mythical dichromatic reality.

Red & Blue, a.k.a. The Liechtenstein flag

This image, to a computer, is a bunch of tiny little dots crammed so close together on your screen that you can’t see where one dot starts and the other begins. Each of these dots is called a pixel. We have lots of red pixels, then lots of blue pixels. If we use numbers instead of colors to represent each pixel, this is what our image looks like:

Sorry, that’s kinda small. Here is a zoomed in version:

I used 0 for red and 1 for blue, then represented each pixel of the image with the corresponding number for its color. In our two-color world, we can describe any image that exists using only 0’s and 1's, plus some knowledge about the dimensions of the image. By the way, these single digits- 1’s and 0's- are called “bits.”

Let’s get down to business and store this image on a computer using numbers like we just did, because computers don’t speak colors. From a laptop, we right click on our beautiful picture and click “Save Image As…” and save it to our Desktop. The Desktop is actually somewhere on the drive inside the computer. Most newer computers contain a solid state drive, slightly older ones contain a hard disk drive, but both types drives use the same general concept to store stuff. The drive needs to store the image, made up of 0s and 1s, using physical stuff that you can actually touch. How is it supposed to do that? Using physics magic!

Physics is full of pairs, which is handy in two-color land. Magnets can have positive or negative polarity, a switch can be on or off, every action has an equal and opposite reaction, etc etc. So if we’re in a two-color world, with an image that’s just red & blue, we can easily take advantage of physics to store the image on a magnetic disk: if the pixel is blue (1), put a positive magnetic charge on that spot of the disk, if it is red (0), put a negative magnetic charge. The pattern of positive/negative charge on the disk can accurately represent the image in an extremely small amount of physical space. But let’s think even smaller, down to the smallest possible way to distinguish between a 1 or a 0…an electron is the smallest bit of electric charge physics has discovered. So, all we really need is a single electron, or lack thereof, per pixel in the image!

The reality ends up slightly larger than this, because a hard drive made entirely out of electrons is…mythical. Something about the nature of charged subatomic particles? Instead, modern drives use tiny transistors (a.k.a. little bits of semiconducting material) as electron “cages,” though I prefer to call them electron baskets because I support the humane treatment of electrons. One of the smallest transistors in use today, for reference, is 10 nanometers wide (that’s soon to be 1 nanometer wide!). 10 nanometers is approximately the length of 20 atoms, so we’re talking microscopic here. If you’re using transistors, you can fit something like 800,000,000,000 different 1’s and 0’s (bits) onto a drive because electrons and their baskets are so astoundingly tiny. That is 800 BILLION, in case you lost count of the zeros in that number. So, if our image is 900 pixels wide and 600 high, that’s only 540,000 pixels total, which is roughly 0.0000675 percent of the number of bits the drive can hold. Electrons and electron baskets- that’s the magic of computer storage.

But I simplified the problem, unfortunately. We started talking about a two color image, and the only numbers we needed to store were 0’s and 1’s. How do we use electrons to store an image in the real world of many colors? It involves finding a way to describe every color using only 0’s and 1's, so that we can still use electrons.

Though there are infinitely many colors, the human eye can distinguish something like 10 million different ones. How do we count to 10 million using only bits? A computer does it by starting with zero, then counts up from there, adding digits when necessary and carrying 1’s from right to left across the digits. This is the exact same way you “carry” numbers to the next digit in addition:
0 → 0
1 → 1
2 → 10 (carried a 1 to the second digit)
3 → 11
4 → 100 (carried a 1 to the third digit)
5 → 101
6 → 110 (carried a 1 to the second digit)

10,000,000 → 100110001001011010000000

16,777,215 → 111111111111111111111111

Oops, I counted to just over 16 million. That’s both to leave us some wiggle room for those with superhuman visual acuity, and also because both 10 million and 16,777,215 are 24 bits long. Consequently, most computers can represent at least 16,777,216 colors by default, because it’s the same number of bits to store on the drive either way. Computers render each of these numbers as a different color, starting with black as color 0 and ending with white as color 16,777,215 (which is twenty-four 1's).

Goodbye, red & blue land! Hello, land of many colors!

So let’s store an image to our computer again, but this time, let’s make it an image with many colors! In the worse case, every single pixel of our image may need 24 bits on the drive/24 electrons in baskets. So if we have a 900x600 pixel image, like our previous example, that’s 540,000 pixels x 24 bits per pixel to describe the color = 12 million bits. That seems like a lot! But remember we can fit 800 BILLION bits on a drive, so we’re still talking only 12 million/800 billion, which is a mere 0.0015% of the available space on the drive! And 12 million bits is about 1.5 MB, to equate it to a measure you’ve likely seen before.

The moral of the story: Storing color images….12 million bits, no big deal! And we didn’t even talk about how computers apply compression algorithms to images to make them even smaller, which is why any 900x600 image you have on your computer is likely to show up as less than 1.5 MB on your drive. But we won’t talk about that in this post…I don’t want to give away all of the magic!

The exact same concepts of bits and electron baskets are used to store anything and everything on a computer, not just images. Videos, for example, are stored as a big stack of images (frames) and then played like a really fast slideshow. So, the same idea of storing color pixels to 1’s and 0’s works the same way for videos. And text (like Word documents)- text is even simpler than images! It’s the exact same idea, except instead of there being 16ish million different colors, there’s only however many different things you can type using your keyboard. It requires at most 8 bits (instead of 24) to uniquely represent each letter/number/etc: “A” is 10, and “q” is 1110001, as examples. This is why text documents take up less space on a drive than images, and both are smaller than videos.

Bam! You have just learned how computers store literally everything. You must be a super nerd genius! Will you pretty please teach me how to post a picture of my dog to Facebook? And while you’re at it, fix my computer!! It’s flooded with viruses!

jk…we’ll get to other nerdy topics later. Leave a comment if you have a question about technology you’d like answered, and tune in next time for more fun :)

I like communities and quiet places. www.natamead.com