Portable Network Graphics file (.png)
.png file signature | image/png
Portable Network Graphics (PNG) is a raster image file format originally developed by the PNG Development Group and standardized by the W3C and ISO/IEC. It is commonly used for web graphics, screenshots, icons, and images that require lossless compression or transparent backgrounds, and it is supported by most operating systems, browsers, and image editors. PNG files are generally considered safe, although malformed images have occasionally exposed vulnerabilities in rendering software.
Magic Bytes
Offset 0
89 50 4E 47 0D 0A 1A 0A
Sources: Apache Tika, Wikipedia, Gary Kessler, Neil Harvey FileSignatures
Extension
.png
MIME Type
image/png
Byte Offset
0
Risk Level
Safe
Validation Code
How to validate .png files in Python
def is_png(file_path: str) -> bool:
"""Check if file is a valid PNG by magic bytes."""
signature = bytes([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A])
with open(file_path, "rb") as f:
return f.read(8) == signature
How to validate .png files in Node.js
function isPNG(buffer: Buffer): boolean {
const signature = Buffer.from([0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A]);
return buffer.subarray(0, 8).equals(signature);
}
How to validate .png files in Go
func IsPNG(data []byte) bool {
signature := []byte{0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}
if len(data) < 8 {
return false
}
return bytes.Equal(data[:8], signature)
}
API Endpoint
/api/v1/png
curl https://filesignature.org/api/v1/png
See the full API documentation for all endpoints and parameters.
Related Formats
Frequently Asked Questions
What is a .png file?
A .png file is a Portable Network Graphics file file. Portable Network Graphics (PNG) is a raster image file format originally developed by the PNG Development Group and standardized by the W3C and ISO/IEC. It is commonly used for web graphics, screenshots, icons, and images that require lossless compression or transparent backgrounds, and it is supported by most operating systems, browsers, and image editors. PNG files are generally considered safe, although malformed images have occasionally exposed vulnerabilities in rendering software.
What are the magic bytes for .png files?
The magic bytes for Portable Network Graphics file files are 89 50 4E 47 0D 0A 1A 0A at byte offset 0. These bytes uniquely identify the file format regardless of the file extension.
How do I validate a .png file?
To validate a .png file, read the first bytes of the file and compare them against the known magic bytes (89 50 4E 47 0D 0A 1A 0A) at offset 0. This is more reliable than checking the file extension alone, as extensions can be renamed.
What is the MIME type for .png files?
The primary MIME type for .png files is image/png.
Is it safe to open .png files?
Portable Network Graphics file (.png) files are generally safe to open. They are classified as low risk because they primarily contain data rather than executable code. However, always ensure files come from a trusted source.