Skip to main content

Does Renaming the Extension Change the Format?

5 min read

A photo downloaded as photo.jpg won't open in some program, or an upload form rejects it as an unsupported format. A frequent cause: the name says JPG, but the contents are WebP or HEIC. The opposite move, renaming a .webp to .jpg to make a problem go away, is common too. That is not a format conversion.

The extension is just a label

The extension (.jpg, .png) is part of the file name. The operating system reads that label to decide which program opens the file, but renaming doesn't change a single byte inside. WebP-compressed data is still WebP data after the name becomes .jpg.

So a renamed file can run into trouble like this:

  • A program that trusts the extension and hands the file to a JPG decoder may report it as damaged and refuse to open it.
  • An upload form that only checks the extension may accept it, and then a later step that processes the contents fails.
  • A program that looks at the contents opens it fine whatever the name, which is where the "it opens on my PC but not over there" confusion comes from.

Which behavior you get depends on the program or service. The reliable fix is to check the real format and, if needed, actually convert it.

Every format starts with a signature

Most image formats put a fixed value in the first few bytes of the file that says what format it is. This is called a signature or magic number. The same 64×64 picture was saved in several formats, and the first 16 bytes of each file were read. The highlighted cells below are the signatures.

The first 16 bytes, in hexadecimal, of one picture saved in nine formats plus a renamed file. sample.png has 89 50 4E 47 0D 0A 1A 0A, sample.jpg FF D8 FF, sample.gif 47 49 46 38 37 61, sample.webp 52 49 46 46 and, from byte 8, 57 45 42 50, sample.bmp 42 4D, sample.ico 00 00 01 00, sample.tif 49 49 2A 00, and sample.heic and sample.avif have heic and avif highlighted after ftyp starting at byte 4. The last row, renamed-photo.jpg, is named jpg but shows RIFF and WEBP

FormatOffsetSignature (hex)As text
PNGbyte 089 50 4E 47 0D 0A 1A 0A.PNG....
JPG0FF D8 FF(not text)
GIF047 49 46 38 + 37 61 or 39 61GIF87a / GIF89a
WebP0 and 852 49 46 46 … 57 45 42 50RIFF + 4-byte size + WEBP
BMP042 4DBM
ICO000 00 01 00(not text)
TIFF049 49 2A 00 or 4D 4D 00 2AII* / MM*
HEIC466 74 79 70 then a brandftyp + heic, mif1 and so on
AVIF466 74 79 70 then a brandftyp + avif

A few notes:

  • WebP lives inside a general-purpose container called RIFF. Bytes 4 to 7 hold the file size and differ from file to file, so you have to read on to WEBP at byte 8 to know it's WebP (Google's WebP container documentation).
  • In HEIC and AVIF the first four bytes are a box size, so the signature starts at byte 4. Both use an ftyp box and are told apart by the brand names that follow. In the files made here, the HEIC continued with mif1heicmiaf and the AVIF with mif1avifmiaf. Both list mif1, so mif1 alone can't distinguish them.
  • In TIFF, II and MM mark the byte order used for numbers (Intel style and Motorola style).
  • An ICO can carry a whole PNG inside it. The ICO made with Pillow here showed the PNG signature (89 50 4E 47) again starting at byte 22.
  • SVG is a text (XML) file rather than image data, so it has no fixed byte signature. Open it in a text editor and you'll see text that begins with <svg or <?xml.

The W3C PNG specification says this 8-byte signature distinguishes PNG from other data and allows early detection of some transmission errors.

Checking a renamed file

A copy of a WebP file was renamed to renamed-photo.jpg; it's the last row in the figure. The name says JPG, but instead of the JPG signature FF D8 FF it starts with RIFF and WEBP. The contents are still WebP.

Windows: PowerShell's Format-Hex

Open PowerShell from the Start menu and enter the following, with the path changed to your file. This output is from Windows PowerShell 5.1, the version that ships with Windows.

Format-Hex -Path .\renamed-photo.jpg | Select-Object -First 1
           00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F

00000000   52 49 46 46 14 03 00 00 57 45 42 50 56 50 38 20  RIFF....WEBPVP8

Select-Object -First 1 keeps only the first part; without it the whole file is printed. According to Microsoft's documentation, PowerShell 6.2 and later (including PowerShell 7) also accept an option such as -Count 16 to set the number of bytes. Only 5.1 was tried for this guide.

Mac and Linux: xxd

In a terminal, xxd shows just the first 16 bytes. The output below comes from the xxd bundled with Git Bash on Windows. Macs usually have xxd as well, but it wasn't run on a Mac for this guide.

xxd -l 16 renamed-photo.jpg
00000000: 5249 4646 1403 0000 5745 4250 5650 3820  RIFF....WEBPVP8

Where the file command is available, it names the format outright. In Git Bash, file renamed-photo.jpg answered RIFF (little-endian) data, Web/P image.

This site's converter decides the same way

This site's converter determines the format from the leading bytes of the file, not from the extension. It reads the first 1,024 bytes and matches them against signatures like those above. Inside an ftyp box it checks the AVIF brands before the HEIC ones, because AVIF files list mif1 too. And since the two letters BM can match by accident, it also checks the header size that follows before calling a file BMP.

Running the same detection code over the ten files above identified nine as the format their extension says and renamed-photo.jpg as WebP. So a misnamed file is still read and converted by its real format, and the file list notes which files had an extension that didn't match.

To make a WebP that's only named .jpg into a real JPG, it has to be converted. The result is a new file that starts with the chosen format's signature.

Convert WebP to JPG Convert HEIC to JPG

The files and tools used here are listed in how the measurements on this site were made.

More guides