How HEIC Compression Works: A Technical Guide
Understand HEIC compression technology including HEVC intra-frame coding, transform blocks, quantization, and why it achieves 50% smaller files than JPEG.
HEIC compression uses HEVC intra-frame coding to achieve 50% smaller files than JPEG at equivalent visual quality. The compression pipeline processes images through coding tree units, prediction, transform coding, quantization, and entropy coding. Each stage is more advanced than its JPEG counterpart.
This guide breaks down every stage of the HEIC compression pipeline. It explains the specific technical mechanisms that make HEIC twice as efficient as JPEG, a format designed over 30 years ago.
HEVC: The Codec Behind HEIC
HEIC is a container format defined by the HEIF (High Efficiency Image Format) standard. The actual compression work is performed by HEVC, also known as H.265. HEVC was developed jointly by ITU-T and ISO/IEC and finalized in 2013. It was originally designed for video compression, where it replaced H.264/AVC.
For still images, HEVC uses only its intra-frame coding mode. Video codecs compress sequences by exploiting similarities between consecutive frames (inter-frame prediction). Still images have no neighboring frames. HEVC's intra-frame mode compresses each image independently, using only spatial redundancy within the single frame.
Apple adopted HEVC intra-frame coding for iPhone photos starting with iOS 11 in 2017. The A11 Bionic chip and every subsequent Apple processor include dedicated hardware for HEVC encoding and decoding. This hardware acceleration makes HEIC compression fast enough to capture burst photos without lag.
Coding Tree Units: The Foundation
JPEG divides images into fixed 8x8 pixel blocks called macroblocks. HEVC replaces this rigid structure with coding tree units (CTUs) that range from 8x8 to 64x64 pixels. This flexible block partitioning is the single largest contributor to HEIC's compression advantage.
How CTUs Work
The encoder starts by dividing the image into a grid of CTUs. Each CTU is 64x64 pixels at maximum size. The encoder then recursively subdivides each CTU into smaller coding units (CUs) using a quadtree structure. A 64x64 CTU splits into four 32x32 CUs. Each 32x32 CU splits into four 16x16 CUs. Subdivision continues down to a minimum of 8x8 pixels.
The encoder chooses the split depth based on image content. Flat, uniform areas like clear skies use large 64x64 blocks because there is little detail to encode. High-detail areas like foliage or text use smaller 8x8 or 16x16 blocks to capture fine structure precisely.
Why Larger Blocks Matter
Larger blocks reduce overhead. Every block boundary requires header bits for prediction mode, motion vectors, and transform coefficients. A single 64x64 block has one set of header data covering 4,096 pixels. The equivalent area in JPEG requires 64 separate 8x8 blocks, each with its own header. That is 64 sets of overhead data for the same pixel area. In smooth regions, the overhead savings alone account for significant file size reduction.
JPEG Macroblocks by Comparison
JPEG uses a fixed two-level structure. The image is divided into 16x16 macroblocks. Each macroblock contains four 8x8 DCT blocks for luminance and two 8x8 blocks for chrominance (under 4:2:0 subsampling). There is no adaptive subdivision. A patch of blue sky gets the same 8x8 block treatment as a patch of intricate texture. This rigidity wastes bits on simple regions and limits precision in complex ones.
Prediction Modes
Before transform coding, the encoder predicts each block's pixel values using neighboring pixels that have already been encoded. The encoder stores only the residual -- the difference between the prediction and the actual pixels. Better predictions produce smaller residuals, which compress to fewer bits.
HEVC: 35 Intra Prediction Modes
HEVC offers 35 distinct intra prediction modes for each coding unit:
- Planar mode (mode 0): Generates a smooth surface fitted to the block's top and left boundary pixels. It excels at gradual gradients, such as out-of-focus backgrounds and sky regions.
- DC mode (mode 1): Fills the entire block with a single value -- the average of the top and left boundary pixels. It handles flat, uniform areas with minimal residual.
- 33 angular modes (modes 2-34): Project boundary pixels at specific angles into the block interior. The 33 angles span from near-horizontal to near-vertical at intervals of approximately 5.6 degrees. An angular mode matching a diagonal edge, such as a roofline at 45 degrees, produces near-zero residuals along that edge.
The encoder tests each of the 35 modes and selects the one that produces the smallest residual. For a block containing a strong diagonal edge, an angular mode aligned to that edge is chosen. For a smooth gradient, planar mode wins. For a solid region, DC mode is selected.
JPEG: 9 Prediction Options
JPEG's baseline specification has no spatial prediction at all. The DCT operates directly on raw pixel values. JPEG's lossless mode defines a simple prediction scheme with just 7 predictors based on adjacent pixels. Even JPEG 2000, the most advanced JPEG variant, offers only 9 prediction modes. The gap between 9 and 35 is large. More prediction options mean better matches to real image content, which means smaller residuals and smaller files.
Transform Coding
After prediction, the encoder transforms the residual data from the spatial domain to the frequency domain. This step concentrates the image's energy into a small number of coefficients, making quantization and entropy coding more efficient.
HEVC Transform Blocks
HEVC uses the Discrete Cosine Transform (DCT) and Discrete Sine Transform (DST) on transform units (TUs) ranging from 4x4 to 32x32 pixels. The 4x4 DST is used specifically for intra-predicted luma blocks, where it provides better energy compaction than DCT. Larger blocks use DCT.
The transform size is chosen independently from the coding unit size. A 32x32 CU can use a single 32x32 transform or be split into four 16x16 transforms. This flexibility allows the encoder to match the transform size to the local frequency content. Low-frequency regions use large transforms for better energy compaction. High-frequency regions use smaller transforms to avoid ringing artifacts.
JPEG Transform Blocks
JPEG uses a fixed 8x8 DCT for every block without exception. There is no DST option, no size flexibility, and no adaptation to local content. The 8x8 size is a compromise: too small for optimal energy compaction in smooth areas, adequate but not ideal for textured areas. This one-size-fits-all approach is a fundamental limitation of the JPEG standard.
Quantization
Quantization is the lossy step. The encoder divides each transform coefficient by a quantization parameter (QP), rounding the result to an integer. Larger divisors produce smaller integers (more compression, more quality loss). Smaller divisors preserve more precision (less compression, less quality loss).
HEVC Quantization
HEVC uses a QP range of 0 to 51. The quantization step size doubles for every increase of 6 in QP. At QP 0, quantization is negligible. At QP 51, quantization is aggressive. Apple's default HEIC encoding for iPhone photos uses a QP value in the range of 22 to 28, depending on scene complexity. This range achieves roughly 50% size reduction compared to JPEG at visually equivalent quality.
HEVC also supports adaptive quantization within a single frame. The encoder assigns different QP values to different CTUs based on visual importance. Regions with high perceptual sensitivity, such as faces, receive lower QP values (higher quality). Flat backgrounds receive higher QP values (more compression). This spatial adaptation allocates bits where the human eye notices the most.
JPEG Quantization
JPEG uses a fixed 8x8 quantization matrix. The JPEG standard includes two default matrices: one for luminance and one for chrominance. The quality slider in image editors scales these matrices uniformly. A quality setting of 75% multiplies every entry in the matrix by the same factor. There is no per-block adaptation, no content-aware bit allocation, and no spatial variance within a single image.
Entropy Coding: CABAC vs Huffman
The final compression stage converts the quantized coefficients into a compact bitstream. This is lossless -- no information is lost during entropy coding. The efficiency of the entropy coder determines how tightly the data is packed.
HEVC Uses CABAC
HEVC uses Context-Adaptive Binary Arithmetic Coding (CABAC). CABAC converts each syntax element into a sequence of binary decisions. Each binary decision is coded using an arithmetic coder that adapts its probability model based on the context -- the values of previously coded neighboring elements.
CABAC achieves near-theoretical-optimum compression. It adapts its probability estimates continuously, so symbols that are locally frequent use fewer bits. For typical photographic content, CABAC produces a bitstream that is 5-15% smaller than Huffman coding on the same quantized data.
JPEG Uses Huffman Coding
JPEG's baseline uses Huffman coding, a simpler entropy coding method defined in 1952. Huffman coding assigns fixed-length codewords based on global symbol frequencies across the entire image. It does not adapt to local patterns. A symbol that is rare globally but common in one region still gets a long codeword. JPEG does support arithmetic coding as an option, but virtually no software enables it because of patent concerns and limited decoder support.
HEIC vs JPEG: Compression Feature Comparison
| Feature | HEIC (HEVC) | JPEG | | --- | --- | --- | | Block size range | 8x8 to 64x64 (adaptive) | Fixed 8x8 | | Block partitioning | Recursive quadtree | Fixed grid | | Intra prediction modes | 35 (planar + DC + 33 angular) | None (baseline) or 9 (lossless) | | Transform types | DCT + DST | DCT only | | Transform sizes | 4x4, 8x8, 16x16, 32x32 | Fixed 8x8 | | Quantization | Adaptive per-CTU, QP 0-51 | Fixed matrix, uniform scaling | | Entropy coding | CABAC (adaptive arithmetic) | Huffman (fixed codewords) | | Color depth | Up to 16-bit per channel | 8-bit per channel | | Lossy mode | Yes | Yes | | Lossless mode | Yes | Limited (rarely used) | | Typical 12 MP photo | ~1.8 MB | ~3.5 MB | | Compression ratio advantage | Baseline | ~50% larger at same quality |
Why HEIC Achieves 50% Smaller Files
The 50% size advantage is not from a single feature. It is the cumulative result of improvements at every stage of the pipeline. Each improvement contributes a measurable portion:
- Larger adaptive blocks save 10-15% in overhead. Encoding a smooth sky region as one 64x64 block instead of sixty-four 8x8 blocks eliminates 63 sets of block header data.
- 35 prediction modes save 15-20% in residual energy. Angular prediction aligned to edges, combined with planar and DC modes for flat areas, produces tighter predictions than JPEG's raw DCT approach.
- Flexible transform sizes save 5-10%. Matching the transform size to local content improves energy compaction. Large transforms pack low-frequency content efficiently. Small transforms handle high-frequency edges without ringing.
- Adaptive quantization saves 5-10%. Allocating more bits to perceptually important regions and fewer bits to backgrounds produces better subjective quality at the same total bitrate.
- CABAC saves 5-15% over Huffman. Context-adaptive arithmetic coding compresses the final bitstream more tightly than fixed Huffman tables.
Combined, these gains compound. A 15% savings at the prediction stage means fewer residual bits enter the transform stage, which means fewer coefficients survive quantization, which means CABAC has less data to encode. The pipeline effects multiply.
Lossy vs Lossless HEIC Compression
HEIC supports both lossy and lossless compression modes. The difference lies in the quantization step.
Lossy Mode
Lossy compression sets the QP above 0, introducing quantization error. This is the default mode for all iPhone photos. Apple's encoder balances quality against file size, targeting a QP range that produces files roughly 50% smaller than equivalent JPEG. At this setting, the quantization error is below the threshold of human visual perception for standard viewing conditions.
Lossless Mode
Lossless compression sets QP to 0 and uses a special coding path that preserves every sample value exactly. The prediction, transform, and entropy coding stages still operate, but quantization introduces zero error. Lossless HEIC files are larger than lossy -- typically 2-3 times the size of lossy HEIC -- but still 20-30% smaller than lossless PNG for photographic content. The savings come from HEVC's superior prediction and entropy coding.
Apple does not use lossless mode for standard iPhone photos. ProRAW images on iPhone Pro models use a different pipeline (DNG format). Lossless HEIC is primarily used in professional imaging workflows where exact sample preservation is required.
Decoding: How HEIC Images Are Displayed
Decoding reverses the compression pipeline. The decoder reads the CABAC-coded bitstream, reconstructs quantized coefficients, applies the inverse transform, adds the prediction, and outputs pixel values. Modern Apple devices perform this in hardware. The A11 chip and later include a dedicated HEVC decoder that processes a 12 MP image in under 50 milliseconds.
Software decoding is slower but widely available. Libraries like libheif and libde265 decode HEIC on any platform. HEICify uses libheif-js to decode HEIC files directly in the browser via WebAssembly, with no server-side processing required. The decoded pixels are then re-encoded into JPEG or PNG for universal compatibility.
Practical Implications
Understanding HEIC compression explains several practical behaviors.
HEIC quality degrades gracefully. Because HEVC adapts block sizes and quantization to local content, increasing compression affects flat backgrounds first and preserves edges and textures longer. JPEG degrades uniformly, producing visible blocking artifacts across the entire image at lower quality settings.
Re-encoding HEIC to JPEG loses efficiency. Converting a 1.8 MB HEIC photo to JPEG at equivalent visual quality produces a 3.5 MB file. The JPEG encoder cannot replicate HEVC's adaptive block structure, superior prediction, or CABAC efficiency. The same visual information simply requires more bytes under JPEG's older algorithm.
Lossless round-trips within HEIC preserve quality perfectly. Decoding and re-encoding a lossless HEIC file produces a bit-identical output. This is not true for JPEG, where each encode-decode cycle introduces additional quantization error.
For converting HEIC files to widely compatible formats, HEICify's HEIC to JPG converter and HEIC to PNG converter process everything locally in your browser. The conversion decodes the HEVC-compressed data and re-encodes it in your chosen output format with full quality control.
Frequently Asked Questions
What compression algorithm does HEIC use?
HEIC uses HEVC (H.265) intra-frame compression with coding tree units, transform coding, and context-adaptive binary arithmetic coding (CABAC). HEVC was finalized in 2013 by ITU-T and ISO/IEC. It applies only the intra-frame coding subset for still images, using spatial prediction within a single frame rather than temporal prediction across video frames.
Why are HEIC files smaller than JPEG?
HEIC achieves 50% smaller files through improvements at every compression stage. Larger coding blocks (64x64 vs 8x8) reduce overhead. More prediction modes (35 vs 0 in baseline JPEG) produce smaller residuals. Flexible transform sizes (4x4 to 32x32 vs fixed 8x8) improve energy compaction. Adaptive quantization allocates bits based on visual importance. CABAC entropy coding compresses the bitstream 5-15% tighter than Huffman coding.
Is HEIC compression lossy or lossless?
HEIC supports both lossy and lossless compression. Apple uses lossy compression by default for iPhone photos, achieving roughly 50% size reduction compared to JPEG. Lossless mode preserves every pixel value exactly but produces files 2-3 times larger than lossy HEIC. Lossless HEIC is still 20-30% smaller than lossless PNG for photographs due to HEVC's superior prediction and entropy coding.
Does HEIC compression affect image quality?
At equivalent file sizes, HEIC produces visibly better quality than JPEG. The 35 intra prediction modes generate more accurate predictions, leaving smaller residuals. Adaptive quantization preserves quality in perceptually important regions. The result is cleaner edges, smoother gradients, and fewer blocking artifacts compared to JPEG at the same bitrate. At Apple's default quality settings, HEIC compression artifacts are below the threshold of human perception for standard viewing.
For a broader overview of the HEIC format, read What Is HEIC Format?. To understand how HEIC relates to its parent standard, see HEIF vs HEIC. For a practical comparison of HEIC and JPEG features, check HEIC vs JPG.
Frequently Asked Questions
What compression algorithm does HEIC use?
Why are HEIC files smaller than JPEG?
Is HEIC compression lossy or lossless?
Does HEIC compression affect image quality?
Related Guides
Does Converting HEIC to JPG Lose Quality?
Understand exactly how much quality is lost when converting HEIC to JPG, what causes the loss, how to minimize it, and when it matters for your photos.
HEIC 10-Bit vs 8-Bit Color: What It Means for Photos
Learn the difference between 10-bit and 8-bit color depth in HEIC files, how it affects photo quality, and what happens when converting to 8-bit formats like JPEG.
HEIC vs JPG: Which Format Should You Use?
A detailed comparison of HEIC and JPG image formats covering compression, quality, file size, compatibility, and features to help you choose the right format.
HEIF vs HEIC: What Is the Difference?
Understand the relationship between HEIF and HEIC file formats — what each abbreviation means, how they relate technically, and why the distinction matters.
What is HEIC Format? Everything You Need to Know
Learn what HEIC is, why Apple uses it, how it compares to JPG, and the easiest ways to open or convert HEIC files on any device.
Ready to Convert Your Images?
Try our free, browser-based converter tools. No uploads required -- your files never leave your device.