Lesson 0.4

Files: the unit of storage

Artifact: Knowing what a file is, in bytes, with metadata, and why renaming doesn't transform it

1. The promise

You'll know what a file actually is, why a file can be moved, copied, renamed, or deleted without changing its contents, and why every file on your machine is just a long list of bytes.

2. The mental model

A file is a labelled box on a shelf.

  • The label is the file's name.
  • The contents are bytes.
  • The shelf is the disk.

The OS keeps an index of where every box is so it can find any one of them again. When you rename a file, you change the label on the box. The contents don't move.

The vocabulary, said properly:

  • A byte is the smallest addressable lump of storage. A number from 0 to 255.
  • A text file is a file whose bytes encode characters using a known encoding (the agreed-on way to turn characters into bytes). Almost all text files today use UTF-8.
  • A binary file is a file whose bytes encode something other than characters — image data, compiled code, a compressed archive. Only a specific program knows how to read it.

(DIAGRAM: a file as a name + bytes + metadata — annotated SVG — three labelled regions: name on the left, contents (bytes shown as a strip of numbers) in the middle, metadata (size, dates, permissions) on the right)

3. You do it, with me

We're going to make a tiny file and inspect it.

Step 1. Open a plain text editor.

  • macOS: open TextEdit (Cmd+Space, type "TextEdit"). Once open, click Format -> Make Plain Text from the menu bar. TextEdit defaults to rich text, which adds invisible formatting.
  • Windows: open Notepad (Win, type "Notepad").

Step 2. Type hello — five letters, no newline.

(SCREENSHOT: TextEdit or Notepad with "hello" typed — full window)

Step 3. Save it as hello.txt in your Documents folder.

Step 4. Check the file's size.

  • macOS: in Finder, right-click hello.txt -> Get Info. Look at the Size row.
  • Windows: in File Explorer, right-click hello.txt -> Properties. Look at the Size and Size on disk rows.

(SCREENSHOT: macOS Finder Get Info window for hello.txt — full window — Size field highlighted)

(SCREENSHOT: Windows Properties window for hello.txt — full window — Size and "Size on disk" fields highlighted)

The size is 5 bytes. One byte per letter. The bytes are the numbers 104, 101, 108, 108, 111 — the UTF-8 codes for h, e, l, l, o.

Step 5. Change the contents. Open hello.txt again and change it to héllo (with the accented é). Save. Check the size again.

(SCREENSHOT: TextEdit or Notepad with "héllo" typed — full window — same file path)

The size is now 6 bytes. The é takes two bytes in UTF-8, not one. This is what an encoding does — it picks how to turn each character into bytes.

Step 6. Look at a binary file. Find any photo in your Pictures folder. Check its size. A typical phone photo is around 2 to 5 million bytes (2 to 5 MB). The contents are still bytes — many millions of them — but they only make sense to an image viewer.

If you try to open a photo in TextEdit or Notepad, you'll see garbled characters. That's the bytes interpreted as text when they're actually image data. The bytes are the same; the interpretation changed.

4. What you should be seeing

A hello.txt file in your Documents folder. Six bytes. You can see the size in Get Info or Properties. You can see the contents by opening the file. You understand that the size went up when you added one accented character because UTF-8 uses two bytes for it.

5. Common stumbles

  • "My size is 5 bytes but 'size on disk' is 4 KB." Disks store data in fixed-size blocks (usually 4 kilobytes). A 5-byte file still takes one whole block. Tiny files round up. Big files round up too, but the waste is fewer than 0.01% of the file's size, so nobody cares.
  • "I opened a photo in TextEdit and saw garbage." That's expected. A text editor reads the bytes as if they were UTF-8 characters. The bytes of a photo aren't characters, so the text editor shows garbled output. Use the right program for the right file type.
  • "I renamed hello.txt to hello.jpg and it didn't become a photo." Renaming changes the label on the box. It doesn't change the contents. The bytes are still the five letters of "hello", which an image viewer can't interpret as a picture.
  • "TextEdit added formatting and now my file is bigger than expected." TextEdit defaults to rich text (RTF), which writes formatting bytes alongside your text. Always use Format -> Make Plain Text first when working with .txt files.

6. You should know

5/16
Next