Portable Network Graphics is a image format commonly identified by .png. Use the listed signatures, MIME types, and structure notes to validate files beyond the extension.
offset 0Portable Network Graphics leading signature
89 50 4E 47 0D 0A 1A 0A
.PNG....
Structure
Signature
IHDR chunk
Optional chunks
IDAT chunk
IEND chunk
Caveats
Do not trust the extension alone. Check the MIME type, the first bytes such as 89 50 4E 47 0D 0A 1A 0A, and format-specific structure when possible.
Container formats and damaged files can share the same opening bytes, so deeper validation may be required for production upload, preview, or conversion flows.
Detection example
SIGNATURE = bytes.fromhex("89504e470d0a1a0a")
OFFSET = 0
def is_png(path: str) -> bool:
with open(path, "rb") as f:
f.seek(OFFSET)
head = f.read(len(SIGNATURE))
return head == SIGNATURE
const SIGNATURE = [0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a];
const OFFSET = 0;
// bytes: a Uint8Array / Buffer holding the start of the file
export function isPng(bytes) {
return SIGNATURE.every((byte, i) => bytes[OFFSET + i] === byte);
}
Portable Network Graphics is commonly used for image previews, thumbnails, metadata checks, and upload validation. Test multiple sizes because resolution, alpha support, compression, and file size often affect implementation behavior.
Common detection mistakes
The .png extension alone does not prove the file contents. Upload and conversion flows should combine extension, MIME type, leading bytes, and format-specific structure checks.
Portable Network Graphics can start with signatures such as 89 50 4E 47 0D 0A 1A 0A, but related containers and damaged files may require additional validation.
Security notes
Media files can still stress decoders through corrupt metadata, extreme dimensions, long durations, or unusual chunks. Read size, dimensions, and duration before processing.
Using samples
8 samples help test tiny images, high-resolution images, alpha channels, and hard-to-compress assets.
Blue Sky PNG is a Portable Network Graphics sample based on Wikimedia Commons, 512 x 384. It can be used to test downloads, parsers, previews, and file type detection.
Flower Garden PNG is a Portable Network Graphics sample based on Wikimedia Commons, 640 x 360. It can be used to test downloads, parsers, previews, and file type detection.
Navy Blue Sky PNG is a Portable Network Graphics sample based on Wikimedia Commons, 768 x 383. It can be used to test downloads, parsers, previews, and file type detection.
Nature Sky PNG is a Portable Network Graphics sample based on Wikimedia Commons, 720 x 540. It can be used to test downloads, parsers, previews, and file type detection.
Sky Landscape PNG is a Portable Network Graphics sample based on Wikimedia Commons, 768 x 576. It can be used to test downloads, parsers, previews, and file type detection.
Blue Night Sky PNG is a Portable Network Graphics sample based on Wikimedia Commons, 960 x 640. It can be used to test downloads, parsers, previews, and file type detection.
NASA Earth 2048x2048 PNG is a Portable Network Graphics sample based on Wikimedia Commons, 2048 x 2048. It can be used to test downloads, parsers, previews, and file type detection.
NASA Blue Marble PNG is a Portable Network Graphics sample based on NASA Image and Video Library, 640 x 640. It can be used to test downloads, parsers, previews, and file type detection.
What is the magic number (file signature) of Portable Network Graphics?
Portable Network Graphics files begin with the byte signature 89 50 4E 47 0D 0A 1A 0A (".PNG...."). Detect the format by reading these leading bytes rather than trusting the file extension alone.
What is the MIME type of Portable Network Graphics?
The MIME type for Portable Network Graphics is image/png.
What file extension does Portable Network Graphics use?
Portable Network Graphics files use the .png extension. The extension is a convention only and does not guarantee the file contents, so combine it with signature and structure checks.