The basics
What is a FITS file?
FITS, the Flexible Image Transport System, is how astronomers store and exchange data. It was worked out in the late 1970s by astronomers in the United States and Europe so that observatories could swap data on magnetic tape: the first FITS files were exchanged in 1979, the definition was published in 1981, and the International Astronomical Union endorsed it in 1982. The IAU's FITS Working Group has looked after it since 1988.
Despite the name, FITS isn't only for pictures. A file can hold a 1-D spectrum, a 2-D image, a 3-D data cube, catalogues and photon lists in tables, or several of these together. Data from the Hubble Space Telescope, Chandra, the Sloan Digital Sky Survey, ESO and ESA comes in FITS, and in 2010 the Vatican Library announced it would store its digitised manuscripts in FITS.
The guiding rule is "once FITS, forever FITS": a change to the standard must never make existing files invalid. Files written decades ago are still valid FITS, and current software reads them; for the same reason, files don't record which version of the standard they follow.
What a FITS file is not:
- Not a photo format. The values are measurements, often 32-bit floats or 16-bit counts, with no fixed brightness range. A viewer has to choose how to stretch them to screen brightness, and the choice changes what you see.
- Not compressed by default. Files are as big as their data. Compression is an add-on (see below).
- Not shown by browsers. You need an astronomy tool, or a conversion to PNG or TIFF.
Anatomy
What's inside a FITS file
A FITS file is a series of 2880-byte blocks. The header is plain ASCII, in 80-character lines called cards; the data follows in binary. Here is a tiny FITS file made with Astropy for this page: a 4 × 3 image of 16-bit integers. Its header fits in one block, and so does its data, so the whole file is 5,760 bytes.
offset 0: header, 2880 bytes (one block)
SIMPLE = T / conforms to FITS standard
BITPIX = 16 / array data type
NAXIS = 2 / number of array dimensions
NAXIS1 = 4
NAXIS2 = 3
EXTEND = T
OBJECT = 'TEST PATTERN' / fictional target
TELESCOP= 'NONE '
DATE-OBS= '2026-10-27T21:00:00'
EXPTIME = 30.0 / exposure time in seconds
END
(25 more cards of spaces fill the block: 36 × 80 = 2880)
offset 2880: data, 2880 bytes (one block)
00 00 00 64 00 C8 01 2C 0 100 200 300 first row
01 90 01 F4 02 58 02 BC 400 500 600 700
03 20 03 84 03 E8 04 4C 800 900 1000 1100
00 00 00 00 … zeros up to 5,760 bytes- 1
SIMPLE = TThe first card
Every FITS file starts with
SIMPLE, padded to 8 characters,=in columns 9 and 10, andT(true) in column 30: "this file conforms to the standard". Those 30 bytes are the format's signature, registered in RFC 4047. - 2
BITPIX = 16The data type
Bits per value and their kind:
8(unsigned bytes),16,32or64(signed integers),-32or-64(floating point). 16 here: two bytes per pixel. - 3
NAXIS = 2The dimensions
NAXISis the number of axes, thenNAXIS1,NAXIS2… give their lengths.NAXIS1is the fastest-changing axis, the width: 4 values per row, 3 rows. A spectrum has one axis, a data cube three. - 4
EXTEND = TMore HDUs may follow
Says the file may contain extensions after the primary data: more images or tables, each with its own header.
- 5
OBJECT = 'TEST PATTERN' / fictional targetKeywords, values, comments
Every card is a keyword of up to 8 characters (capital letters, digits,
-and_), a value and an optional comment after a/. Strings are in single quotes. Real observations carry dozens or hundreds of cards: telescope, instrument, exposure, filter, and the world coordinate system that maps pixels to positions on the sky. - 6
ENDThe end of the header
ENDhas no value. The rest of the block is filled with spaces so the header is a whole number of 2880-byte blocks: 36 cards per block. - 7
00 00 00 64 00 C8 01 2CThe data
The pixels, row by row, as big-endian 16-bit integers:
00 64is 100,00 C8200. 12 values take 24 bytes; the rest of the 2880-byte block is zeros.
Under the hood
HDUs, extensions and data types
A FITS file is a sequence of header and data units (HDUs). The first is the primary HDU: its header starts with SIMPLE and its data, if any, is an array. Every HDU after it is an extension, whose header starts with XTENSION and names its type:
| Extension | Holds | Typical use |
|---|---|---|
IMAGE | An N-dimensional array, like the primary HDU | Several images in one file: science, error and quality maps; one per detector chip |
BINTABLE | A table of binary columns; a cell can hold a whole array | Catalogues, event lists, spectra, and compressed images |
TABLE | A table of ASCII text columns | Older and rarer; simple catalogues |
Many files from space telescopes have an empty primary HDU (NAXIS = 0) that holds only the common header, followed by image extensions: NASA's sample files include a Hubble NICMOS observation with a null primary array and five image extensions for science, error, data quality, samples and time.
| BITPIX | Type | Bytes per value |
|---|---|---|
8 | Unsigned 8-bit integer | 1 |
16 | Signed 16-bit integer | 2 |
32 | Signed 32-bit integer | 4 |
64 | Signed 64-bit integer | 8 |
-32 | IEEE 32-bit floating point | 4 |
-64 | IEEE 64-bit floating point | 8 |
There are no unsigned 16-bit or 32-bit types. Instead, a camera's unsigned 16-bit counts are stored as signed integers with the header keyword BZERO = 32768: a reader adds BZERO (and multiplies by BSCALE, if present) to get the real value. Astropy and CFITSIO do this automatically. All numbers are big-endian, and the 2880-byte blocks are filled out with zeros after the data, or spaces after a header.
Metadata
Reading a FITS header
The header is the part people read most. It's ASCII, so head -c 2880 image.fits | fold -w 80 in a terminal shows the first block card by card. Beyond the required keywords, observatories record everything about an observation:
- What and when:
OBJECT,DATE-OBS,EXPTIME,TELESCOP,INSTRUME,FILTER,OBSERVER. - Where on the sky: the World Coordinate System (WCS) keywords, such as
CTYPE1,CRPIX1,CRVAL1andCDELT1, map pixel positions to right ascension and declination, or wavelength for a spectrum. - Units and scaling:
BUNIT,BZERO,BSCALE. - History:
HISTORYandCOMMENTcards record processing steps in free text.
Header conventions
The standard reserves some keywords; projects add their own, and conventions extend the format, such as long string values continued over several cards (CONTINUE, now part of the standard) and keywords longer than 8 characters (HIERARCH, used by ESO). Readers ignore keywords they don't know.
File size
Compressed FITS: .fits.gz and .fits.fz
Plain FITS is uncompressed, and astronomical data is large. Two approaches are common:
| `.fits.gz` | `.fits.fz` (tile compression) | |
|---|---|---|
| How | The whole file gzipped | The image split into tiles, each compressed (Rice, gzip, HCOMPRESS) and stored in a binary table |
| Still a FITS file | No, until it's unzipped | Yes: the headers stay readable |
| Read part of an image | No, the whole file must be decompressed | Yes, tile by tile |
| Tools | gzip; CFITSIO and Astropy read it directly | fpack and funpack (from CFITSIO); Astropy reads it |
Integer images are usually tile-compressed losslessly with Rice, which NASA's fpack documentation says typically beats gzip by about 30%. Floating-point images are usually compressed lossily: values are quantised first, which discards some of the noise. Check the settings if you need exact values.
How to
How to open, view and convert a FITS file
- SAOImage DS9 is the standard viewer: it displays FITS images and binary tables with many scaling methods and colour maps, overlays coordinate grids and regions, and runs on Windows, macOS and Linux.
- Astropy in Python:
from astropy.io import fits, thenfits.info("image.fits")lists the HDUs,fits.getheader("image.fits")returns the header andfits.getdata("image.fits")the data as a NumPy array. - ImageMagick reads and writes FITS:
magick image.fits -auto-level image.png. It doesn't know about WCS or tables, and a high dynamic range can come out almost black or white without an explicit stretch. - GIMP opens FITS images for editing; Siril and other astrophotography programs stack and process them.
- CFITSIO, NASA's C library, underlies many of these tools and comes with small utilities for listing, copying and compressing files.
Why does my FITS image look black, or upside down?
Black: the values span a range far wider than a screen can show, so most pixels map to the darkest grey. Use a logarithmic, square-root or z-scale stretch (DS9 has them all) or -auto-level in ImageMagick. Upside down: DS9 draws the first row of data at the bottom, the way astronomers plot data, and so did ImageMagick in our test; code that shows the array directly, such as Matplotlib with its default settings, puts the first row at the top. Check orientation against the coordinates, not against another program.
Comparison
FITS vs TIFF and PNG
| FITS | TIFF | PNG | |
|---|---|---|---|
| Data types | 8-bit unsigned, 16/32/64-bit signed, 32/64-bit float | Integers and float, many layouts | 8- or 16-bit integers |
| Dimensions | Any number of axes | 2-D, multiple pages | 2-D |
| Tables | Yes | No | No |
| Header | Human-readable ASCII | Binary tags | Binary chunks |
| Compression | Optional add-on | Many options | Always (lossless) |
| Opens in a browser | No | Only Safari | Yes |
Keep the FITS file as the record of a measurement; export a stretched PNG or JPG to show someone the picture. Astrophotographers often work in FITS or TIFF and publish in JPG.
Security
Is a FITS file safe to open?
A FITS file holds numbers and text and runs nothing. Some points still matter when you handle files from elsewhere:
- Header text is input. RFC 4047 notes that local conventions where keywords refer to other files, or even control telescope hardware, need a security review. Software shouldn't act on header values it doesn't validate.
- Size claims.
NAXISnvalues can describe arrays far bigger than the file or than memory. Servers and pipelines should check them before allocating. - Headers can reveal more than intended. Observer names, site coordinates, file paths and processing history are often recorded. Read the header before publishing a file.
Sample files
There are no sample FITS files on this page yet. NASA's FITS Support Office offers sample FITS files from Hubble and other missions; to make your own, write a NumPy array with Astropy: fits.PrimaryHDU(data).writeto("test.fits").
Put it online
Have a FITS file? Give it a link.
Drop a FITS file on 99helpers and it gets its own web address. Browsers can't display FITS, so anyone who opens the link downloads it and opens it in DS9, Astropy or another astronomy tool; add a PNG preview if people should see the image in their browser.
Questions
FITS files, frequently asked
What is a FITS file?
The standard file format of astronomy: one or more images, data cubes or tables, each with a human-readable header describing the data, the observation and its sky coordinates.
How do I open a FITS file?
Use SAOImage DS9 (free, on Windows, macOS and Linux) to view it, or Astropy in Python to read it. ImageMagick and GIMP can open FITS images too, but they ignore tables and coordinates.
Are .fit, .fits and .fts the same?
Yes. All three are FITS files; .fits is the most common, and RFC 4047 says the extension is a convention rather than a rule.
How do I convert FITS to PNG or JPG?
In DS9, set a scale and colour map, then File, Save Image. On the command line: magick image.fits -auto-level image.png. The stretch you choose decides what's visible, so check the result.
Why is my FITS image black?
Its values cover a huge range and a linear display maps almost everything to black. Use a logarithmic, square-root or z-scale stretch in your viewer.
Why is every FITS file a multiple of 2880 bytes?
The standard requires headers and data to fill whole 2880-byte blocks: 36 header cards of 80 characters. The rule exists for historical reasons and has never changed, so old files stay valid.
What is the current FITS version?
Version 4.0. Its content was approved by the IAU FITS Working Group in July 2016 and the final language-edited document in August 2018.
Related formats
Other file types explained
Keep going
Related
Sources
- NASA FITS Support Office: the FITS Standard (version 4.0)
- RFC 4047: MIME sub-type registrations for FITS
- Library of Congress: FITS format description
- NASA HEASARC: a FITS primer (CFITSIO user guide)
- SAOImage DS9 reference manual
- NASA HEASARC: fpack and funpack, FITS image compression
Last reviewed 27 October 2026.