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, 524 bytes in the layout of the Duotone Options settings file (below). Adobe’s specification says the layout is not documented; this one is what Photoshop writes. |
Duotone settings
| Size | Type | Name | Description |
|---|---|---|---|
| 2 | u16 | Version | 1. |
| 2 | u16 | Count | Number of plates: 1 monotone, 2 duotone, 3 tritone, 4 quadtone. |
| 40 | 4 × colour | InkColours | Four 10-byte colours (a 2-byte colour space and four 2-byte components), whatever the plate count; those beyond it are undefined (seen as space 65535 and zeros). |
| 256 | 4 × 64 bytes | InkNames | Four Pascal strings, each padded to 64 bytes (63 characters at most). |
| 112 | 4 × 28 bytes | InkCurves | Four curves: 13 signed 16-bit points (0 to 1000 for 0.0 to 100.0 percent, −1 for no point) and a 2-byte override (0). |
| 2 | u16 | DotGain | 20, kept for Photoshop 2.0 and ignored. |
| 110 | 11 × colour | Overprints | Eleven 10-byte overprint colours: none for a monotone, one for a duotone, four for a tritone, eleven for a quadtone; the rest are undefined. |
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 count for every row of every channel (Height × Channels counts, 2 bytes each, 4 bytes each in a PSB), then each row compressed on its own with PackBits. |
| 2 | ZIP | One zlib stream holding every row of every channel, in order, without prediction. (Photoshop writes ZIP in layer channels; the image data section is read this way by open-source readers.) |
| 3 | ZIP with prediction | The same after a prediction (difference) filter, described below. |
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. In CMYK images 255 means no ink.
The prediction filter
With compression 3 each row is replaced by its differences before it is deflated; a reader undoes it row by row, after inflating:
- 8 bits: each byte is the sum of itself and the byte before it in the row (modulo 256).
- 16 bits: the same with big-endian 16-bit words (modulo 65,536).
- 32 bits (floating point): the row’s bytes are first regrouped into four planes (the first byte of every sample, then every second byte, and so on), the differences are taken along the whole regrouped row as bytes, and after summing, the planes are interleaved again into samples.
- 1 bit: no prediction.
Transparency in the composite
When the layer count in the layer and mask information is
negative, the first channel after the colour channels is the transparency of the composite, and the
colour channels hold the picture blended with white wherever it is transparent. To get the
colour of a pixel back, take (c + a − 255) × 255 / a for a colour component c and
an alpha a above 0.
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).
In the image data section of a PSB the RLE byte counts are 4 bytes each, as in layer channel data. Nothing else about the image data changes. A PSB is also limited to 300,000 pixels in each direction, a PSD to 30,000.