system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: how do file formats work?

Also, how do formats like for example jpeg/png, or pdf/xps differentiale?
gpt
A file is a bunch of bytes, and that's **all** a file is.

A file format says what the bytes mean. ASCII text files are pretty simple - each byte means a letter or symbol (except for a few of them that mean other things). 72 then 105 then 33 means `Hi!`.

Bitmap files are a bit more complicated. There's a certain number of bytes at the start of the file, called the *header*, which tells you things like how big the picture is, and the number of bytes per pixel. After that, each group of 1 to 4 bytes (depending on what the header said) represents the colour of one pixel. Put the colours together in the right order, and you get a picture.

Most other formats are a lot more complicated. A ZIP file contains a header for the first file in it (unlike the BMP header, this one tells you things like the filename and the compression level), and then the compressed data for that file, and then a header for the second file, and the compressed data for the second file, and so on. Then at the end it has an extra copy of all the headers but without any compressed file data in-between.

JPEG and PNG both store images, but they do it in completely different ways, *and* they use completely different compression algorithms. The result of that is that JPEG is sometimes better and PNG is sometimes better.