File Extension

Share

What is a File Extension?

A file extension is the part of a file's filename after the last dot character (.). For example, if a file's filename is photo.jpg, then the file's extension is .jpg.

File extensions are hidden in Windows by default, so you don't normally see them(How to Show File Extensions in Windows 11). On Linux, they're generally shown by default.

What are File Extensions Used For?

File extensions are used to determine the type of a file from its filename. Programs can do different things when given different types of files, which in turn means what a program does to a file exactly can depend on its file extension.

If you change the extension of a file, that doesn't change the data saved inside the file, because changing the extension is the same thing as just renaming the file. However, some programs may not know what to do with that file if it stops having a supported file extension, even though it's the same data inside.

. For example, when you save an image file, generally you'll be given the option to save in a some of the most common and widely supported image formats, such as PNG, JPG, and Bitmap. Each of these formats comes with an encoder that turns pixel data into bytes that get stored inside the file, and a decoder that turns those bytes back into pixel data to be displayed on screen. This means that to get the pixel data back from the file, we need to know which encoder was used when it was saved. There are a few ways to do this. The simplest way is to save the file with an unique extension for each format, so a PNG file has a .png extension, a JPG file has a .jpg or .jpeg extension, and a BMP file has a .bmp extension. That way when loading the file, we just check the extension and use the appropriate decoder to get those pixels back.

Some image viewer do this, and as a consequence if you have a file called photo.jpg and you rename it to photo.png, changing only the extension, the image viewer won't be able to load the photo anymore, because it thinks it's a PNG file and its bytes are in the PNG format, when it's actually just a JPG file that looks like a PNG file.

There is another method to tell the file type: there are several file formats whose files always start with the same pattern of bytes. For example, JPG files always start with 0xffd8ffe0(what is 0x?) or 0xffd8ffe1.

Sometimes a file may have multiple extensions. For example, .jinja.html for HTML files that are also files used by a program called Jinja.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *