Saving one file format with a different file extension. JPG - PNG; MOV - MP4

Most programs don't look at the extension AT ALL. They look at the file-header content to determine what it really is and act accordingly.
Almost every well-known standard file-format has recognizable identification in the first bytes of the file. (E.g Every GIF image has the characters "GIF87a" as the first 6 bytes.)
If the software knows how to handle it, it just does (some do give a warning that the extension is wrong), if it doesn't it gives you an error message (or just crashes if it is badly programmed).

The extension mainly serves as a visual indicator for you indicating what the file most likely is.
And it allows your OS to quickly determine what application is best suited to handle it, without having to actually read the content of the file.


Changing the name of the file does exactly that: change the name of the file. Nothing more. In particular, changing the name of the file does not change the content of the file, only the name and nothing but the name.

(In fact, changing the name of the file will actually not touch the file at all, since the "name" is actually just an entry in the directory. It isn't associated with the file.)

Since nothing about the content of the file itself changed, it should not be surprising that a program that was able to correctly decode the content of the file when it was named Fred will also be able to correctly decode the content of the file when it is named Wilma, for the simple reason that the content is exactly the same.


Almost all file formats embed information about what the file type is right near the beginning of the file. For example, a real PNG file always starts with the eight bytes 0x89 0x50 0x4E 0x47 0x0D 0x0A 0x1A 0x0A (note that bytes 2 through 4 are the ASCII characters 'PNG', the rest of the header is binary data designed to detect the file being handled in ways that would result in data corruption), or an ELF object file (used for executables on most systems other than Windows and macOS) starts with 0x7F 0x45 0x4C 0x46 (with bytes 2-4 being 'ELF' in ASCII). These are known as file signatures, and while they are not the only way to determine a file type based on contents, they're generally the first step. Wikipedia has a list of them for many common file types that may be of interest.

The near ubiquitous use of file signatures means that you can look at the contents of the file itself to figure out what type of file it is, and almost all software does exactly that for two reasons:

  • It's significantly more reliable than matching on file extensions (or on the MIME type reported by the server you're downloading the file from) because you can't modify this data and still have it be a valid file of that type but you can change the extension (or MIME type) to whatever you want and the file will not change what type it is.
  • Validating the file type is an important layer of protection against crashing the application or exploiting bugs in it. If you blindly trust other sources of information about the file type, you run the risk of trying to parse something as one type of data when it is in fact a different type, which can cause all kinds of problems. Insufficient validation of the file structure given the expected file type has historically been a very common attack vector for malware.

Windows is largely the anomalous case here in that it predominantly favors file extensions over actual file contents for deciding what to tell users the file type is, while most other systems and most applications only fall back to the file extension if they can't figure out the type by looking at the file contents. The sole practical purpose of a file extension these days is to act as a generic indicator of what the file type might be, making it easier to determine what type of file you're dealing with or find files of a specific type without having to inspect the file contents, though in some cases people just choose to inspect the contents anyway (see for example the file command from UNIX systems).