Mash's Musings


What do file extensions do?

Published Sep. 18, 2022

I recently read a funny blog post on things learned way too late in life. While there are certainly no shortage of such things to share, I have found some of my biggest "woah" moments in the last few years to be in the world of computers. Being pretty new to the field and largely self-taught, I consistently have the bittersweet experience of noticing a glaring blindspot and the lightbulb moment once the gap is filled in.

When I was younger, though not young enough that I want to divulge a specific age, my thought was that file extensions were something magical that dictated what a file was. Like some sort of digital cargo culter, I remember at some point attempting to rename some random file "Need for Speed.exe" in the hopes that I could manifest the video games my parents refused to purchase for me. My mental model of file extensions was akin to incantations in a spellbook: where the right set of words in the right order would produce a magic effect. I interpreted my inability to turn English homework into video games as a failure in execution, not understanding; and I was disappointed that I did not know the right set of magic words to achieve my noble goal.

Perhaps when Harry Potter introduced dementors and Hermione became hot, my magical fantasies shifted towards killing ghosts and kissing cuties, and I gave up on trying to manifest magic in the world. My understanding of file extensions at this time was updated to a conception that it was some sort of magic property of the file that was not to be tampered with. I'd imagine this had to do with the scary dialog boxes that previous versions of Windows would hit me with every time I veered to the right of the '.' when renaming a file. On the occasions when I steeled my nerves and boldly renamed the file in brazen defiance of the warnings, I found that, as promised, Windows no longer knew what to do with my file. Like poor Icarus, I had flown too close to the sun and I was grateful that while Daedalus had to watch his son perish, Bill Gates had provided me with the ability to ctrl+z my hubris away. My file extensions were restored and the damage was undone.

It wasn't until my 20s when I was learning the basics of programming that something clicked. One exercise had me create a text file for manipulation — not a Microsoft Word .doc which is what I had always thought was a text file — but the equivalent of opening up Notepad, typing "hello world", and saving the result as "hello_world.txt". Boiled down to such simplicity, it dawned on my that regardless of whether I changed this file name to "potato.txt", "hello_world.text", or "Need for Speed.exe", the actual file would only — no could only — contain the same 11 characters; the file name had nothing to do with the file contents. With that clarification made, it still left the question in my head: What do file extensions do?

It turns out that file extensions are simply hints to readers of that file name, human or computer program, of what that file should contain with no guarantee of what it does contain. Simple file extensions like .txt suggest that the file contains some text. More complex file extensions, such as .png or .mp3, suggest that the file conforms to a specification laid out in some official document so that a reader knows exactly how to read the file, akin to the jacket of a book specifying "French" or "Russian" as the language. The jacket provides helpful information about what I can expect in the book but doesn't define the book itself. And like a book jacket, a file extension can be misleading, ommitted, or ignored entirely while leaving the book unchanged. So while I can swap out the original "hello_world.txt" jacket for the "Need for Speed.exe" jacket, all that would accomplish is the confusion of future readers, a pattern commonly seen in malware masquerading as benign files. I can also remove the jacket altogether by renaming the file just "hello_world", and while that will cause Windows to get confused about how to read the file, I can open read its contents in Notepad all the same. Regardless of what I change the extension to, a reader can always attempt to read the book anyways and check for itself.

It turns out that these little extensions hardly contain the potency I once ascribed to them, yet through their relatively humble hints, still serve as a critical piece of the process that involves reading and writing all manner of files in composing complicated programs. Well it's either that, or I still haven't found out the right cheat code to manifest all the video games my heart desires.