A PNG file begins with 8 bytes: 89 50 4E 47 0D 0A 1A 0A. This is the png file signature, and it is the first thing any PNG reader checks. If these bytes are missing or altered, the file fails to open. Here is what each byte does, why the signature exists, and how a damaged signature produces the “Not a PNG file” error.
The 8 Bytes at the Start of Every PNG
The png magic number is the byte sequence 89 50 4E 47 0D 0A 1A 0A. Bytes 2 to 4 (50 4E 47) spell “PNG” in ASCII. The remaining five bytes are not decoration. Each serves a specific job to help the file survive different transmission systems and operating systems. Open the file in a hex editor to see these bytes directly. On macOS or Linux, run xxd -l 8 file.png to dump the first 8 bytes of any PNG.
Why Each Byte Exists
The signature is more than an identifier. Each byte was chosen to catch common file-corruption scenarios.
Byte 1: 0x89
The first byte has the high bit set. It detects transmission systems that strip the eighth bit of each byte. If a system removes the high bit, 89 becomes 09 and the PNG reader immediately knows the file was corrupted in transit.
Bytes 2 to 4: 50 4E 47 (“PNG”)
These three bytes spell “PNG” in ASCII. They are the human-readable part of the signature. A hex dump shows 50 4E 47, which maps to the letters P, N, G. This makes the format easy to identify even in a raw byte view.
Bytes 5 and 6: 0D 0A (CR LF)
The carriage return (0D) and line feed (0A) bytes detect line-ending conversions. If a file was transferred via FTP in ASCII mode, the system might convert line endings and alter these bytes. A PNG reader spots the changed signature and warns you.
Byte 7: 0x1A
1A is a DOS end-of-file character. Under the DOS type command, this byte stops the display of the file. It prevents the binary garbage of a PNG from being printed to the screen on older systems.
Byte 8: 0x0A (LF)
The final line feed provides another check for line-ending corruption. Combined with the earlier CR LF pair, the signature can detect both Unix-style and DOS-style line-ending modifications.
How a Damaged Signature Causes “Not a PNG” Errors
When a PNG viewer or library such as libpng reads a file, it checks the signature first. If the first 8 bytes do not match 89 50 4E 47 0D 0A 1A 0A, the file is rejected. libpng reports “Not a PNG file”. The error message may also say png signature invalid or not a png file error depending on the software.
Common causes of a bad signature
- The file was saved with the wrong extension. A JPEG or WebP renamed to .png.
- The file was transferred via FTP in ASCII mode, altering the CR/LF bytes.
- A text editor opened and re-saved the PNG, adding or removing bytes at the start.
- The file was truncated, so the first 8 bytes are missing or partial.
Open a file with a .png extension. If it starts with FF D8 FF, it is a JPEG. If it starts with “RIFF” and contains “WEBP”, it is a WebP image. Check the header hex with a hex editor or the xxd command shown above.
How to Inspect the PNG Signature Yourself
Verify the signature of any PNG file in a few steps. No special software is required.
- Open a terminal or command prompt.
- Navigate to the folder containing your PNG file.
- Run
xxd -l 8 file.pngon macOS or Linux. On Windows, use a hex editor or install xxd via a Unix environment. - Compare the output to 89 50 4E 47 0D 0A 1A 0A. A match means the signature is intact. No match means the file may be corrupted or mislabeled.
Without a terminal, open the file in a hex editor. Look at the very first byte. It should be 89.
What to Do When the Signature is Wrong
A png signature invalid error caused by a missing or altered header may still be recoverable if the image data itself is intact. Some online tools rebuild the header. To recover a corrupted PNG, try a dedicated repair service such as png.repair. The site recovers corrupted PNG files online with no watermark added.
Before attempting any repair, make a backup copy of the original file. If the signature is wrong because the file is a different format, rename the extension to the correct one. That is usually enough.