This page follows Unidata’s NetCDF File Format Specification, a grammar for the classic format (CDF-1) and the 64-bit offset format (CDF-2), and PnetCDF’s CDF-5 specification for the 64-bit data format, both read 2026-11-12. All numbers are big-endian, and every item is padded to a multiple of 4 bytes.
Header
| Item | Form |
|---|---|
| magic | C D F and a version byte: 01 classic, 02 64-bit offset, 05 64-bit data. |
| numrecs | Number of records: 4 bytes (8 in CDF-5). FFFFFFFF means streaming: count unknown. |
| dim_list | Absent, or NC_DIMENSION (0000000A), a count, and dimensions: a name and a length. Length 0 marks the record (unlimited) dimension; there is at most one. |
| gatt_list | Absent, or NC_ATTRIBUTE (0000000C), a count, and attributes. |
| var_list | Absent, or NC_VARIABLE (0000000B), a count, and variables. |
“Absent” is written as two zero words (ZERO ZERO); in CDF-5 the
second is 8 bytes. Counts are 4 bytes, 8 in CDF-5.
| Element | Fields |
|---|---|
| name | Length, then the UTF-8 name (normalised to NFC), padded with zeros to 4 bytes. |
| attribute | Name, type, number of values, the values padded to 4 bytes. |
| variable | Name; number of dimensions and their dimension IDs (a record variable is one whose first dimension is the record dimension); its attributes (a vatt_list, same form as gatt_list); type; vsize; begin. |
vsize | Bytes of one variable (or of one record of it), padded to 4. The field is redundant; a size over 232 − 4 bytes is written as 232 − 1. |
begin | File offset of the variable’s data: 4 bytes in CDF-1, 8 in CDF-2 and CDF-5. |
Types
| Code | Type | Size | Default fill value |
|---|---|---|---|
| 1 | NC_BYTE | 1, signed | −127 |
| 2 | NC_CHAR | 1 | 0 |
| 3 | NC_SHORT | 2 | −32,767 |
| 4 | NC_INT | 4 | −2,147,483,647 |
| 5 | NC_FLOAT | 4, IEEE | 9.9692099683868690 × 1036 |
| 6 | NC_DOUBLE | 8, IEEE | 9.9692099683868690 × 1036 |
| 7 | NC_UBYTE | 1 (CDF-5 only) | 255 |
| 8 | NC_USHORT | 2 (CDF-5 only) | 65,535 |
| 9 | NC_UINT | 4 (CDF-5 only) | 4,294,967,295 |
| 10 | NC_INT64 | 8 (CDF-5 only) | −9,223,372,036,854,775,806 |
| 11 | NC_UINT64 | 8 (CDF-5 only) | 18,446,744,073,709,551,614 |
A _FillValue attribute on a variable replaces the default.
Data
- Fixed-size variables come first, each stored whole at its
begin, in row-major order, padded to 4 bytes. - Then the records: for each step of the record dimension, one slice of every
record variable in turn. The record size is the sum of their
vsizes. - When there is exactly one record variable, its slices are not padded, so byte and short data is packed tightly.