Format:DICOM
| Magic | 128 bytes preamble, then "DICM" at offset 128 |
|---|---|
| Extensions | .dcm, .dicom, .dic |
| Endianness | File meta little endian; data set little endian except the retired Explicit VR Big Endian syntax |
| On this wiki | Facts · Code · Notes · Topics |
DICOM Part 10 files (.dcm): a 128-byte free preamble, the bytes DICM at offset 128, a File Meta Information group (0002) in explicit VR little endian, then the data set as tag/VR/length/value elements in the transfer syntax named by (0002,0010), with pixel data possibly encapsulated in compressed fragments.
Overview
A DICOM file (PS3.10 media format, often called Part 10) is a stream of data elements. Identify it by the 4 bytes DICM at file offset 128; the 128 bytes before it are a free-form preamble (often zeros). Very old or stripped files have no preamble and start directly with a data set; readers such as pydicom then need a force option, see #Reader behaviour.
Layout
- Preamble: 128 bytes, no defined content.
DICMprefix.- File Meta Information: all elements of group 0002, always explicit VR little endian regardless of the data set: (0002,0000) group length, (0002,0001) version, media storage SOP class/instance, (0002,0010) Transfer Syntax UID, implementation class UID, and so on.
- Data set: elements in ascending tag order, encoded as the transfer syntax in (0002,0010) says.
Data element encoding
- Tag: group u16 then element u16, in the data set byte order (so on a little-endian file the bytes of tag (0010,0010) are
10 00 10 00). - Implicit VR (transfer syntax 1.2.840.10008.1.2): tag, then a 4-byte length, then the value. The VR must come from a data dictionary.
- Explicit VR: tag, two ASCII VR letters, then either a 2-byte length (short form) or 2 reserved zero bytes plus a 4-byte length (long form). The long form is used by OB, OD, OF, OL, OV, OW, SQ, SV, UC, UN, UR, UT, UV. All other standard VRs (AE AS AT CS DA DS DT FD FL IS LO LT PN SH SL SS ST TM UI UL US) use the short form. See Fact:DICOM/behavior/Explicit VR length forms.
- Unverified: value lengths are even and strings are padded with a space (NUL for UI); check PS3.5 section 6.2.
Undefined length
A length of FF FF FF FF means the value ends at a delimiter instead of a byte count. It is used for SQ values and for encapsulated pixel data. Sequence items are introduced by the Item tag (FFFE,E000) with their own 4-byte length; an undefined-length item is closed by the Item Delimitation tag (FFFE,E00D), and an undefined-length sequence by the Sequence Delimitation tag (FFFE,E0DD). See Fact:DICOM/enum/Item and delimiter tags.
Transfer syntaxes
Common UIDs are in Fact:DICOM/enum/Common transfer syntax UIDs. Implicit VR LE, Explicit VR LE and Explicit VR BE are uncompressed; the Deflated syntax (…1.2.1.99) is a deflated variant of explicit VR little endian (Unverified: the deflate stream covers the data set after the file meta group); the 1.2.4.x syntaxes (JPEG, JPEG-LS, JPEG 2000) and 1.2.5 (RLE) store compressed pixel data.
Encapsulated pixel data
Unverified: with a compressed transfer syntax, Pixel Data (7FE0,0010) has VR OB and undefined length; its content is a sequence of Items: first a Basic Offset Table item (possibly empty), then one or more fragment items each holding bytes of the compressed stream, closed by the Sequence Delimitation item. Check PS3.5 section A.4 before relying on this. In pydicom a dataset with an encapsulated transfer syntax is always explicit VR little endian (filereader.py comment near line 921).
Reader behaviour
pydicom reads the preamble and checks DICM; without it, it raises an error unless forced, in which case it assumes there is no header and rewinds. The file meta is parsed as explicit VR little endian and retried as implicit VR if the first element cannot be interpreted. See Fact:DICOM/magic/Preamble and DICM.
Privacy
DICOM data sets routinely contain patient names, IDs and dates in tags such as (0010,0010); never publish real files or values, use fictional examples only.
Code & repositories
See the linked repositories of this page.
- https://github.com/pydicom/pydicom @
a6374203fe842a2936647cf75ed749227a384ccb· license: MIT (declared by the contributor; GitHub's detector did not recognize LICENSE)
Python DICOM library: readers for preamble, file meta, VR rules (valuerep.py), transfer syntax UIDs (uid.py) and tag dictionary
Tested on: source read, not run: source reading only · checked 2026-10-19; last activity 2026-10-14 - https://github.com/file/file @
4ee5ca8fb938c3168bcededd0ce7c2e03daea485· license: BSD-2-Clause (declared by the contributor for the files used; GitHub reports BSD-2-Clause (read from COPYING; GitHub's detector did not classify it) for the repository)
file(1) magic database: magic/Magdir/printer (PostScript, EPS, PJL, PCL signatures) and magic/Magdir/images (DICOM at offset 128)
Tested on: source read, not run: source reading only · checked 2026-10-19; last activity 2026-10-16