A PSD file has five sections in a fixed order: the file header, colour mode data, image resources, layer and mask information, and image data. This page covers the first two and the last. Every number in the file is big-endian. A Large Document Format (PSB) file has the same layout; the differences are listed at the end.
00000000 38 42 50 53 00 01 00 00 00 00 00 00 00 03 00 00
00000010 01 00 00 00 01 00 00 08 00 03 00 00 00 00
File header
The header is 26 bytes long. A reader should stop if the signature or version does not match.
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 0 | 4 | char[4] | Signature | Always 8BPS (38 42 50 53). |
| 4 | 2 | u16 | Version | 1 for PSD, 2 for PSB. |
| 6 | 6 | bytes | Reserved | Must be zero. |
| 12 | 2 | u16 | Channels | Number of channels in the image, alpha channels included. 1 to 56. |
| 14 | 4 | u32 | Height | Rows of pixels. 1 to 30,000 in PSD, up to 300,000 in PSB. |
| 18 | 4 | u32 | Width | Columns of pixels. Same ranges as the height. |
| 22 | 2 | u16 | Depth | Bits per channel: 1, 8, 16 or 32. |
| 24 | 2 | u16 | ColorMode | The colour mode, below. |
Colour modes
| Value | Mode | Notes |
|---|---|---|
| 0 | Bitmap | One bit per pixel, used with a depth of 1. |
| 1 | Greyscale | One grey channel. |
| 2 | Indexed | One channel of palette indexes; the palette is in the colour mode data. |
| 3 | RGB | Red, green and blue channels. |
| 4 | CMYK | Cyan, magenta, yellow and black channels. |
| 7 | Multichannel | Independent channels with no colour model. |
| 8 | Duotone | A greyscale channel printed with one to four inks; the ink settings are in the colour mode data. |
| 9 | Lab | CIE L*a*b* channels. |
Values 5 and 6 are not used. Any channels beyond those the mode needs are alpha or spot channels; their names are in the image resources 1006 and 1045.
Colour mode data
| Offset | Size | Type | Name | Description |
|---|---|---|---|---|
| 26 | 4 | u32 | Length | Length of the data that follows. 0 for every mode except indexed and duotone. |
| 30 | Length | bytes | Data | Indexed: a 768-byte colour table, not interleaved: 256 red values, then 256 green, then 256 blue. Duotone: the duotone settings, which Adobe does not document; a reader should keep them unchanged. |
An indexed image with fewer than 256 colours still stores 768 bytes. The number of colours actually used is in image resource 1046, and a transparent index in 1047.
Image data
The last section is the flattened composite of the whole document, with no length field of its own: it runs to the end of the file. Programs that cannot read layers show this image.
| Size | Type | Name | Description |
|---|---|---|---|
| 2 | u16 | Compression | Compression method, below. |
| rest | bytes | ImageData | The pixels, planar: every row of the first channel, then every row of the second, and so on. No padding between rows. |
| Value | Method | Layout |
|---|---|---|
| 0 | Raw | Uncompressed samples, ceil(Width × Depth / 8) bytes per row. |
| 1 | RLE | First a table of byte counts, one 2-byte count for every row of every channel (Height × Channels counts), then each row compressed on its own with PackBits. |
| 2 | ZIP | Deflate (zlib) without prediction. |
| 3 | ZIP with prediction | Deflate after a prediction (difference) filter. Adobe’s specification names the method but does not describe the filter. |
PackBits reads a count byte n: 0 to 127 copies the next n + 1 bytes; −1 to −127 repeats the next byte 1 − n times; −128 is skipped.
Samples of 16 and 32 bits are big-endian. 32-bit images hold floating-point values. In a bitmap image (mode 0) a set bit is black.
PSB differences
A PSB file has version 2 in its header and allows sizes up to 300,000 pixels. These length fields grow from 4 to 8 bytes:
- the length of the layer and mask information section, and of the layer info inside it;
- the data length in each layer’s channel information;
- the per-row byte counts of RLE layer channel data (4 bytes instead of 2);
- the length of some additional layer information blocks (see additional layer information).
Adobe’s specification does not list any PSB change for the image data section.