{
  "schemaVersion": "1.0",
  "canonicalPage": "https://fileformat.co/ext/jpg",
  "inspectorUrl": "https://fileformat.co/inspect",
  "spec": {
    "slug": "jpg",
    "extension": ".jpg",
    "aliases": [
      ".jpeg"
    ],
    "name": "JPEG / JFIF / EXIF Image",
    "shortName": "JPEG",
    "category": "media-3d",
    "tier": 1,
    "summary": "Marker-segmented DCT lossy image format (`FF D8 FF ... FF D9`), where embedded APP1 EXIF TIFF headers carry camera rotation flags (`Orientation=6`) and GPS coordinates.",
    "technicalNotes": "Marker segment lengths are always big-endian (`uint16_be`), EXCEPT inside the APP1 `Exif\\x00\\x00` payload which embeds a standalone TIFF header whose endianness can be either `'II'` (little-endian) or `'MM'` (big-endian)!",
    "mimeTypes": [
      "image/jpeg"
    ],
    "identifiers": {
      "pronomPuid": "fmt/43",
      "specUrl": "https://www.w3.org/Graphics/JPEG/itu-t81.pdf"
    },
    "binarySignature": {
      "endianness": "mixed",
      "magicBytes": [
        {
          "offset": 0,
          "hex": "FF D8 FF",
          "description": "JPEG SOI marker (FF D8) followed by first marker prefix 0xFF"
        }
      ],
      "containerFamily": null,
      "headerLayout": [
        {
          "offset": "0x00 - 0x01",
          "byteOffset": 0,
          "byteLength": 2,
          "lengthLabel": "2 B",
          "dataType": "uint16_be",
          "fieldName": "soi_marker",
          "description": "0xFFD8 Start of Image"
        },
        {
          "offset": "0x02 - 0x03",
          "byteOffset": 2,
          "byteLength": 2,
          "lengthLabel": "2 B",
          "dataType": "uint16_be",
          "fieldName": "app_marker",
          "description": "0xFFE0 (JFIF) or 0xFFE1 (EXIF)"
        },
        {
          "offset": "0x04 - 0x05",
          "byteOffset": 4,
          "byteLength": 2,
          "lengthLabel": "2 B",
          "dataType": "uint16_be",
          "fieldName": "segment_len",
          "description": "Marker segment byte length (includes these 2 bytes)"
        }
      ]
    },
    "securityProfile": {
      "riskLevel": "low",
      "allowsArbitraryCodeOrMacros": false,
      "xxeRisk": false,
      "polyglotPrependRisk": false,
      "pickleDeserializationRisk": false,
      "uploadValidationNotes": "Auto-orient pixels according to EXIF Orientation (0x0112) before stripping APP1 EXIF/GPS metadata on user photo uploads."
    },
    "codeSnippets": {
      "python": "import struct, sys\nwith open(sys.argv[1], \"rb\") as f:\n    soi, mkr, slen = struct.unpack(\">HHH\", f.read(6))\n    assert soi == 0xFFD8 and (mkr & 0xFF00) == 0xFF00\n    print(f\"JPEG first marker=0x{mkr:04X}, len={slen}B\")",
      "typescript": "export async function checkJpeg(file: File) {\n  const b = new Uint8Array(await file.slice(0, 4).arrayBuffer());\n  return b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff;\n}",
      "rust": "use std::{fs::File, io::Read};\nfn main() -> std::io::Result<()> {\n    let mut b = [0u8; 4];\n    File::open(std::env::args().nth(1).expect(\"usage: <prog> <file>\"))?.read_exact(&mut b)?;\n    println!(\"JPEG SOI: {:02X} {:02X}\", b[0], b[1]);\n    Ok(())\n}",
      "go": "package main\nimport (\"fmt\"; \"io\"; \"os\")\nfunc main() {\n    f, err := os.Open(os.Args[1])\n    if err != nil {\n        fmt.Fprintln(os.Stderr, \"open:\", err)\n        os.Exit(1)\n    }\n    defer f.Close()\n    b := make([]byte, 4)\n    if _, err := io.ReadFull(f, b); err != nil {\n        fmt.Fprintln(os.Stderr, \"read:\", err)\n        os.Exit(1)\n    }\n    fmt.Printf(\"JPEG marker: %X\\n\", b)\n}"
    },
    "relatedFormats": [
      "heic",
      "webp",
      "png"
    ],
    "verifiedAt": "2026-11-14T16:09:03Z"
  },
  "samples": [
    {
      "id": "jpg-minimal",
      "filename": "minimal-8x8-jfif.jpg",
      "variant": "minimal",
      "title": "Minimal JFIF Baseline JPEG (8×8)",
      "description": "Real baseline JPEG encoded by Pillow: FF D8 SOI, JFIF APP0, Huffman-compressed 8×8 RGB pixels, FF D9 EOI.",
      "localPath": "/fixtures/v1/jpg/minimal-8x8-jfif.jpg",
      "cdnUrl": "https://fileformat.co/fixtures/v1/jpg/minimal-8x8-jfif.jpg",
      "sizeBytes": 644,
      "sha256": "72ad937c3cc136955b18dfa3209c4a86e6a6c739eab2e9d1d05fb3b75c051d62",
      "expectValid": true
    },
    {
      "id": "jpg-realistic",
      "filename": "photo-1080p-exif.jpg",
      "variant": "realistic",
      "title": "1920×1080 JPEG with Standard Orientation=1 EXIF",
      "description": "Real Pillow-encoded 1080p JPEG carrying an APP1 Exif TIFF directory with Orientation=1.",
      "localPath": "/fixtures/v1/jpg/photo-1080p-exif.jpg",
      "cdnUrl": "https://fileformat.co/fixtures/v1/jpg/photo-1080p-exif.jpg",
      "sizeBytes": 523936,
      "sha256": "0810b6422b4ef7f11b623036c6870f20cb7e75fadbdcc05f12b7c13b35825ba6",
      "expectValid": true
    },
    {
      "id": "jpg-edge-case",
      "filename": "exif-orientation-6-null-island-gps.jpg",
      "variant": "edge-case",
      "title": "EXIF Orientation=6 (90° CW Rotation Trap) + Benign (0,0) GPS Tag",
      "description": "Fully decodable JPEG whose EXIF IFD declares Orientation=6 and a GPSInfo IFD at Null Island — tests pipelines that strip tags without rotating pixels.",
      "localPath": "/fixtures/v1/jpg/exif-orientation-6-null-island-gps.jpg",
      "cdnUrl": "https://fileformat.co/fixtures/v1/jpg/exif-orientation-6-null-island-gps.jpg",
      "sizeBytes": 551116,
      "sha256": "9e84120c7d4e36e75154329a088f3226aaca6e96aa28a43fcff7b4cfd421ebaf",
      "expectValid": true,
      "edgeCaseTag": "EXIF Orientation=6 + GPS"
    }
  ]
}