Files, folders, extensions, and formats
You have used files for most of your life, but a file is more than a digital version of a paper document.
In the previous lessons, you learned that computers represent information using bytes. A fileConcept · lights on your mapfileA collection of bytes saved together and given a name. Photos, songs, spreadsheets, and applications are all files; what differs is how their bytes are meant to be read. is a collection of those bytes saved together and given a name.
A photograph, song, spreadsheet, video, application, and font can all be stored as files. They contain different information, but underneath, each one is made of bytes.
What is a folder?
A folderConcept · lights on your mapfolderA container that organizes files and other folders into the tree structure every machine uses. Engineers usually say directory; the sequence of folders leading to a file is its path. is used to organize files and other folders.
Engineers often call a folder a directory, and the two words generally refer to the same idea, although “directory” is more common in technical conversations and command-line tools.
Folders can be placed inside other folders, creating a structure that resembles a tree. For example, a photograph might be stored inside:
Photos → Vacation → Italy → Rome.jpg
This sequence describes the file’s path, meaning its location within the computer’s folder structure.
A folder does not transform the contents of a file. It helps the operating system and the user organize and locate it.
What is a file extension?
If every file contains bytes, how does a computer know whether those bytes represent a photograph, spreadsheet, song, or document?
One clue is the file’s extensionConcept · lights on your mapfile extensionThe part of a filename after the final dot (.jpg, .pdf, .xlsx) that helps the operating system decide which application should open the file. It’s a label, not a spell. Renaming the extension doesn’t convert the file, it just mislabels the bytes..
A file extension is the part of a filename that appears after the final dot. Common examples include:
.jpgfor an image.pdffor a document.mp3for audio.xlsxfor an Excel spreadsheet.txtfor plain text.zipfor a compressed archive
The extension helps the operating system decide which application should open the file, so double-clicking a .jpg file may open an image viewer, while double-clicking an .xlsx file may open a spreadsheet application.
However, an extension is only a label. It does not determine what the file’s bytes actually contain.
Renaming cat.jpg to cat.pdf does not convert the image into a PDF but only changes the label attached to the file, like placing a soup label on a can of paint. The label changes, but the contents do not. The paint stays paint.
Computers and applications may also inspect the contents of a file or use additional stored information to determine its real type.
What is a file format?
A file format is the set of rules describing how the information inside a file is organized and should be interpreted.
For example, the JPEG format defines how image information is arranged and compressed, while the PDF format defines how text, images, fonts, and page layouts can be represented in a document.
The extension usually tells you which format the file claims to use:
.jpgusually indicates the JPEG image format..pdfusually indicates the PDF document format..csvusually indicates comma-separated tabular data.
An application must understand the format in order to interpret the bytes correctly. A photo application knows how to decode JPEG files, while a spreadsheet application knows how to interpret Excel files.
The extension is the label. The format is the actual set of rules governing the file’s contents.
Text files and binary files
One useful distinction is between text files and binary files.
All files ultimately contain bytes. The difference is how those bytes are meant to be interpreted.
A text fileConcept · lights on your maptext fileA file whose bytes follow a text encoding, so any editor can open and read it. Code and configuration are text. Unlike a binary file, it stays human-readable without a specific program. stores bytes according to a text encoding. Its contents can usually be opened and read in a basic text editor.
Examples include:
.txtfiles- Many source-code files
.htmlfiles.cssfiles.jsonfiles.csvfiles
Software engineers usually write source code in text files. A Python file ending in .py, for example, contains text that both a person and the appropriate software can read.
A binary fileConcept · lights on your mapbinary fileA file whose bytes follow a structure that needs the right program to interpret. Photos, audio, and most office documents are binary. Unlike a text file, opening one in an editor shows meaningless symbols. uses a format whose bytes are not intended to be read directly as ordinary text. A specialized application must interpret the file’s internal structure.
Photographs, videos, compiled applications, and many office documents are binary files, and opening one in a text editor may display meaningless symbols because the editor is interpreting structured binary information as though it were normal text.
A Microsoft Word .docx file is an interesting example. Internally it is a compressed collection of text-based XML files and other assets, yet users normally treat it as a binary document format because it requires software that understands its overall structure.
The distinction is not that text files are simple and binary files are advanced but about how the bytes are meant to be read. Text files are designed to be interpreted as characters, while binary files require software that understands their particular format.
Text file or binary file?
What is compression?
Files can sometimes be represented using fewer bytes through compressionConcept · lights on your mapcompressionRe-encoding information so it takes fewer bytes, like storing “repeat blue 1,000 times” instead of the word a thousand times. Lossless compression restores the original exactly; lossy compression, used for photos and video, discards some detail to save more space..
Compression looks for patterns or unnecessary repetition and stores the information more efficiently. Imagine a file containing the word “blue” one thousand times. Instead of recording the word repeatedly, a compressed version might store an instruction resembling: Repeat “blue” 1,000 times.
A ZIP fileConcept · lights on your mapZIP fileA compressed archive that bundles several files and folders into one. Unzipping restores the originals exactly, because ZIP compression is lossless. is a common example. It can combine several files and folders into one compressed archive.
ZIP compression is normally lossless, meaning the original files can be restored exactly. No information needs to be permanently removed.
Other forms of compression may be lossy, meaning some information is discarded to make a file much smaller. JPEG photographs and many audio or video formats may use lossy compression, where the goal is to remove detail that people are unlikely to notice while substantially reducing the file size.
This is why a heavily compressed image may appear blurry or blocky. Some of its original information has been removed.
Connecting files to applications
Applications depend on files for many purposes.
An application itself may be installed using files containing code, images, settings, and other resources, and when it runs, it may open existing files, create new ones, or change information stored inside them.
For example, a photo-editing application reads the bytes in an image file, interprets them according to the image format, displays the image, and then writes new bytes when you save your changes.
The application must know which format it is reading and how to correctly organize the information it writes back.
The mental model to remember
A file is a named collection of bytes stored together.
A folder, also called a directory, organizes files and other folders.
A file extension is the suffix after a filename’s dot and helps identify the type of file.
A file format is the actual set of rules describing how the bytes inside the file are organized.
A text file stores information as encoded characters, while a binary file requires software that understands its particular structure.
Compression represents information using fewer bytes. It can be lossless, preserving everything exactly, or lossy, permanently removing some information.
A designer emails: “I renamed the file from .png to .jpg like the upload form wanted, but the site still rejects it.” What actually happened?
▼ answer the check to continue ▼