After the primary HDU, a FITS file can hold any number of extensions: further header and data units, each starting on a 2880-byte boundary. The record syntax of their headers is on the header page.
Extension header
| Position | Keyword | Value |
|---|---|---|
| 1 | XTENSION | The extension type, a string (below). Not allowed in the primary header. |
| 2 | BITPIX | Bits per value. |
| 3 | NAXIS | Number of axes. |
| 4 | NAXISn | Length of each axis, n = 1 to NAXIS. |
| 5 | PCOUNT | Parameter count: extra bytes after the main data (the heap of a binary table). |
| 6 | GCOUNT | Group count. |
| … | Other keywords | |
| Last | END |
The data holds |BITPIX| × GCOUNT × (PCOUNT + NAXIS1 × … × NAXISm) bits,
padded to a whole block. A reader can skip an extension it does not know with this
formula alone.
Extension types
XTENSION | Status | Content |
|---|---|---|
'IMAGE ' | Standard | An array, like the primary array |
'TABLE ' | Standard | A table of ASCII text fields |
'BINTABLE' | Standard | A table of binary fields |
'IUEIMAGE' | Conforming, not approved | An early form of the image extension |
'A3DTABLE' | Conforming, not approved | An early form of the binary table |
'FOREIGN ' | Conforming, not approved | A file of another format wrapped in FITS |
'DUMP ' | Conforming, not approved | A dump of raw data |
New types must not reuse these names. After the last HDU a file may have special
records, whose first 8 bytes are never XTENSION; their use needs the
approval of the IAU FITS Working Group.
IMAGE
XTENSION = 'IMAGE ', then BITPIX, NAXIS
(0 to 999), NAXISn, PCOUNT = 0 and GCOUNT = 1.
The data is stored exactly like the primary array, with the same scaling keywords; see
data.
ASCII TABLE
| Position | Keyword | Value |
|---|---|---|
| 1 | XTENSION | 'TABLE ' |
| 2 | BITPIX | 8 |
| 3 | NAXIS | 2 |
| 4 | NAXIS1 | Characters in a row |
| 5 | NAXIS2 | Number of rows |
| 6 | PCOUNT | 0 |
| 7 | GCOUNT | 1 |
| 8 | TFIELDS | Number of fields, up to 999 |
Each field n then has these keywords:
| Keyword | Required | Meaning |
|---|---|---|
TBCOLn | Yes | Column where the field starts, counting the first character of the row as 1 |
TFORMn | Yes | Fortran-style format, below |
TTYPEn | Recommended | Field name; names should be unique without regard to case |
TUNITn | No | Physical units |
TSCALn | No | Scale, default 1.0; not for A fields |
TZEROn | No | Offset, default 0.0; not for A fields |
TNULLn | No | The string that marks an undefined value in this field |
TDISPn | No | Display format, below |
TDMINn, TDMAXn | No | Smallest and largest physical value in the column |
TLMINn, TLMAXn | No | Smallest and largest physical value that has a meaning |
TFORMn | Field |
|---|---|
Aw | Character string of width w, ASCII 32 to 126 |
Iw | Integer of width w: an optional sign, then digits |
Fw.d | Real number, fixed point, d digits after the point |
Ew.d | Real number with an exponent |
Dw.d | Real number with an exponent, implying double precision |
On reading, F, E and D are the same: the text
decides the value. A blank numeric field is zero. The physical value is
TZEROn + TSCALn × field value. The last block is padded with
spaces.
BINTABLE
| Position | Keyword | Value |
|---|---|---|
| 1 | XTENSION | 'BINTABLE' |
| 2 | BITPIX | 8 |
| 3 | NAXIS | 2 |
| 4 | NAXIS1 | Bytes in a row |
| 5 | NAXIS2 | Number of rows |
| 6 | PCOUNT | Bytes after the main table: the gap and the heap |
| 7 | GCOUNT | 1 |
| 8 | TFIELDS | Number of fields, up to 999 |
Field keywords are those of the ASCII table except TBCOLn, plus
TDIMn and THEAP. Fields follow each other in the row with no
gaps and no alignment; rows follow each other with no gaps. TFORMn is
rT: a repeat count r (default 1, and 0 for an empty field) and a type
code T:
| Code | Type | Bytes per element | Undefined value |
|---|---|---|---|
L | Logical: ASCII T or F | 1 | Byte 00 |
X | Bit; r bits padded with zero bits to whole bytes | r/8 rounded up, in all | None |
B | Unsigned byte | 1 | TNULLn |
I | 16-bit integer | 2 | TNULLn |
J | 32-bit integer | 4 | TNULLn |
K | 64-bit integer | 8 | TNULLn |
A | Character; r is the string length | 1 | – |
E | Single-precision float | 4 | NaN |
D | Double-precision float | 8 | NaN |
C | Single-precision complex: real, then imaginary | 8 | NaN in either part |
M | Double-precision complex | 16 | NaN in either part |
P | Array descriptor, two 32-bit integers | 8 | – |
Q | Array descriptor, two 64-bit integers | 16 | – |
- All numbers are big-endian; integers of 2, 4 and 8 bytes are two’s complement.
- A string of r characters may end early with a
00byte; what follows it is undefined. A full-length string has no terminator. - The physical value of a number is
TZEROn + TSCALn × stored value. - Unused bytes at the end of the last block are zero.
TFORMn | Stored as | Physical type | TZEROn |
|---|---|---|---|
B | Unsigned | Signed byte | -128 |
I | Signed | Unsigned 16-bit | 32768 |
J | Signed | Unsigned 32-bit | 2147483648 |
K | Signed | Unsigned 64-bit | 9223372036854775808 |
For these columns TSCALn must be 1.
Multi-dimensional fields
TDIMn = '(l,m,n…)' shapes the r elements of a field as an array, first
dimension fastest. The product must not exceed r. For example
TFORM1 = '60A' with TDIM1 = '(5,4,3)' is a 4 × 3 array of
five-character strings. Unused trailing elements are undefined fill.
The heap and variable-length arrays
A field of type rPt(emax) or rQt(emax) holds a
variable-length array of type t (any code above except P and
Q), at most emax elements long; r is 0, 1 or absent. For example
TFORM8 = 'PB(1800)' is a byte array of up to 1800 elements.
| Descriptor field | P | Q | Meaning |
|---|---|---|---|
| Count | 32-bit | 64-bit | Number of elements in this row’s array |
| Offset | 32-bit | 64-bit | Byte offset of the array from the start of the heap |
- The heap starts
THEAPbytes after the start of the main table. The default, which is also the minimum, isNAXIS1 × NAXIS2; a larger value leaves a gap.THEAPis not used whenPCOUNTis 0. - Arrays may be in any order, with gaps, and two descriptors may point at the same bytes. No alignment is needed. Offsets are never negative, and an array must lie wholly inside the heap.
- An empty array has count 0, and its offset should be 0.
TSCALnandTZEROnapply to the values in the heap, not to the descriptor.
Display formats
TDISPn suggests how to show a field as text. It is advice for software
and does not change the data.
TDISPn | For | Display |
|---|---|---|
Aw | Characters | A string of width w |
Lw | Logicals | T or F in width w |
Iw.m | Integers | Decimal, at least m digits |
Bw.m | Integers | Binary, at least m digits |
Ow.m | Integers | Octal, at least m digits |
Zw.m | Integers | Hexadecimal, at least m digits |
Fw.d | Reals | Fixed point, d decimals |
Ew.dEe | Reals | Exponential, e exponent digits |
ENw.d | Reals | Engineering: exponent a multiple of 3 |
ESw.d | Reals | Scientific: one digit before the point |
Gw.dEe | Any | General: fixed or exponential as fits |
Dw.dEe | Reals | Exponential, double precision |
Tiled image compression
A compressed image is stored as a BINTABLE with
ZIMAGE = T. The image is cut into tiles (by default one row each), and
each table row holds one compressed tile, the first tile in the first row.
| Keyword | Meaning |
|---|---|
ZIMAGE | T: this table holds a compressed image (required) |
ZCMPTYPE | Compression algorithm (required), below |
ZBITPIX | BITPIX of the image (required) |
ZNAXIS, ZNAXISn | NAXIS and axis lengths of the image (required) |
ZTILEn | Tile length along axis n; default the full first axis and 1 for the others |
ZNAMEi, ZVALi | Name and value of algorithm parameter i, up to 999 |
ZMASKCMP | Algorithm used for the null pixel mask |
ZQUANTIZ | How floats were quantised: NO_DITHER (default), SUBTRACTIVE_DITHER_1 or SUBTRACTIVE_DITHER_2 |
ZDITHER0 | Seed of the dither sequence, 1 to 10000 |
ZSIMPLE, ZEXTEND, ZBLOCKED, ZTENSION, ZPCOUNT, ZGCOUNT, ZHECKSUM, ZDATASUM | The original SIMPLE, EXTEND, BLOCKED, XTENSION, PCOUNT, GCOUNT, CHECKSUM and DATASUM of the uncompressed HDU |
ZCMPTYPE | Algorithm | Parameters |
|---|---|---|
RICE_1 | Rice coding | BLOCKSIZE 16 or 32 (default 32); BYTEPIX 1, 2, 4 or 8 (default 4) |
GZIP_1 | Gzip of the tile’s bytes | None |
GZIP_2 | Gzip after shuffling the bytes, most significant bytes of all values first | None |
PLIO_1 | IRAF pixel list coding, for integers 0 to 224; stored as 16-bit arrays | None |
HCOMPRESS_1 | H-transform coding, two-dimensional images only | SCALE, default 0.0 (lossless) |
NOCOMPRESS | Tile stored uncompressed | None |
| Column | Content |
|---|---|
COMPRESSED_DATA | Required. The compressed tile, as 1PB, 1PI or 1PJ (or 1Q, needed when the heap passes 2.1 GB) |
GZIP_COMPRESSED_DATA | A tile that could not be quantised, gzipped; its COMPRESSED_DATA is then empty |
ZSCALE, ZZERO | Scale and offset used to quantise a float tile; absent for lossless tiles |
ZBLANK | Value marking undefined pixels (also allowed as a keyword; the column wins). Recommended −2147483648. Integer images use BLANK instead |
NULL_PIXEL_MASK | Compressed mask of undefined pixels, for lossy algorithms |
Quantisation and dithering
A floating-point tile that is quantised becomes integers I =
round((F − ZZERO) / ZSCALE). With subtractive dithering,
a random number R between 0 and 1 is added to the scaled value and 0.5 subtracted before
rounding. NO_DITHER uses no random numbers. SUBTRACTIVE_DITHER_2
keeps pixels that are exactly 0.0 undithered, by coding them with the reserved integer
−2147483647. NaN pixels are never dithered: they are set to the ZBLANK
value.
The random sequence RN has 10,000 values, from the generator in the standard’s
informative appendix (Park’s portable generator: seed = 16807 × seed mod 2147483647,
starting from seed 1, each value seed / 2147483647; the 10,000th seed should be
1043618065). For the tile in table row N, I0 = (N − 1 +
ZDITHER0) mod 10000 and I1 = INT(RN(I0) × 500).
Each pixel uses RN(I1) and then I1 increases by one (NaN pixels
also advance it); at 500 the generator moves on: I0 increases by one, wrapping
from 10000 to 0, and I1 is recomputed from it.
Algorithms
- RICE_1 is lossless and for integers only. The standard names only its two parameters; the block coding itself is not described in the text read.
- PLIO_1 is run-length coding in 16-bit instructions: one unused sign bit, a 3-bit opcode and 12 data bits. It is for integers from 0 to 224, and the “high value” starts at 1 for each line. The standard lists the opcodes (named ZN, HN, PN, SH, IH, DH, IS and DS); the opcode numbers read here (00, 04, 05, 02, 03, 06, 07) are not enough to build a decoder and are left unmatched to names on this page.
- HCOMPRESS_1 is for two-dimensional images: an H-transform, quantisation
and quadtree coding.
SCALEis at least 0.0, and 0.0 is lossless. A smoothing flag exists in the software but is not part of the standard. - GZIP_1 is DEFLATE (LZ77 with Huffman coding); GZIP_2 orders the bytes by decreasing significance first and applies to integer and floating-point data only.
Compression directives for table writers are FZTILELN, FZALGOR
and FZALGn; FZALGn wins over FZALGOR. Each
compressed table column is a 1QB column.
Tiled table compression
A compressed binary table is itself a BINTABLE with
ZTABLE = T. The rows are cut into tiles of ZTILELEN rows; each
column of a tile is compressed on its own and stored as a 1QB
variable-length byte array, one tile per row.
| Keyword | Meaning |
|---|---|
ZTABLE | T (required) |
ZNAXIS1, ZNAXIS2 | Row width and row count of the original table (required) |
ZPCOUNT | Original PCOUNT (required) |
ZFORMn | Original TFORMn of each column (required) |
ZCTYPn | Algorithm for column n: RICE_1, GZIP_1, GZIP_2 or NOCOMPRESS, all lossless (required) |
ZTILELEN | Rows per tile (required); tiles should not exceed 100 MB |
ZTHEAP, ZHECKSUM, ZDATASUM | Original THEAP, CHECKSUM and DATASUM |
Byte shuffling with GZIP_2 applies only to integer and float columns.
Variable-length arrays in the original table are compressed one by one, and their
descriptors are stored as 64-bit Q descriptors compressed with
GZIP_1.
Sources
- FITS Standard, version 4.0 – IAU FITS Working Group (language-edited LaTeX source): the extension sections, the tiled compression sections, the random-number appendix and the reserved extension names appendix (re-read 13 November 2026, apart from the final 30,000 characters)