# File Formats and Extensions

> What a file format is, and why the end of a file name is only a hint. How a label tells a browser what kind of file it got.

**Course:** [JSON, YAML and File Formats](https://learn.benibix.com/learn/development-formats)  
**Time:** 10 min

**After this lesson you can:**

- Say what a file format is
- Explain why renaming a file does not change it
- Read a media type like image/png

## What a file format is, and what the ending tells you

A file format is the set of rules for how a file stores its data: what each byte means and in what order. The file extension is the short ending after the last dot, like .png or .json. It is only a hint. Every PNG picture starts with the same 8 bytes, whatever the file is called.

A program needs to know the format to read a file. A photo app knows how PNG lays out its colours. A music app knows how a song file is laid out. Hand a program a format it does not know, and it shows an error or a mess.

Your computer uses the extension to pick an app. Double-click report.pdf, and the PDF reader opens it. That is all the extension does. The bytes inside decide what the file really is.

So renaming a file does not change its format. Rename photo.png to photo.jpg, and the bytes are still a PNG. Some apps open it anyway, by reading the first bytes. Others trust the name and refuse.

To change a format, you convert the file. A tool reads the old format and writes the data again in the new one. That is what Save As does when you pick a new type.

On the web, a file has no name ending the browser can trust. So the sender adds a label, the media type, also called a MIME type. It has two parts and a slash, like text/html or image/png. The browser reads it to decide whether to show a page, play a video or save a file.

A wrong media type causes odd bugs. A script sent as text/plain may not run at all. A page sent as a download is saved, not shown. When a file acts strangely in a browser, check the label it came with.

```console
$ file --mime-type icon.png
icon.png: image/png
$ head -c 8 icon.png | xxd
00000000: 8950 4e47 0d0a 1a0a                      .PNG....
```
The file tool reads the bytes, not the name. Every PNG starts with these same 8 bytes.

![Two panels. On the left, notes.txt, with .txt picked out, holds two readable lines, Buy milk and Call Jack at 5, and carries the label text/plain. On the right, photo.png, with .png picked out, holds rows of hex bytes starting 89 50 4E 47, and carries the label image/png. Notes under them say the ending after the dot is the file extension and the label is the media type a server sends.](https://learn.benibix.com/diagrams/dev2-file-types.svg)

### Example: Lucy renames a photo

A form asks Lucy for a JPG, and her photo is a PNG of 2 megabytes. She renames it to photo.jpg, and the form rejects it as a broken file.

She opens it in a photo app and uses Save As with JPG picked. The new file is 400 kilobytes, and the form takes it.

**Words in this lesson:** [File Format](https://learn.benibix.com/term/development/file-format), [File Extension](https://learn.benibix.com/term/development/file-extension), [Media Type (MIME Type)](https://learn.benibix.com/term/development/mime-type)

**Question:** If I rename photo.png to photo.jpg, is it a JPG now?

**Answer:** No, the bytes inside are still a PNG. The name only changes the label. To change the format, a tool has to read the PNG and write the picture again as a JPG.

---

Source: https://learn.benibix.com/learn/development-formats/file-formats-and-extensions
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
