Introduction
The classic format is the original NetCDF file layout from Unidata: a header that describes every dimension, variable and attribute, followed by the arrays themselves, stored uncompressed. Its simplicity, and the fact that every NetCDF reader supports it, keep it in wide use for climate and weather data.
It has three versions, which share the same design and differ in the size of their numbers: the original (CDF-1), the 64-bit offset format (CDF-2), which lifts the 2 GB limit on where data can start, and the 64-bit data format (CDF-5), which allows larger arrays and adds unsigned and 64-bit integer types. See all the NetCDF variations.
Structure
All numbers are big-endian. The file begins with the header:
- the magic
CDFand a version byte,01,02or05 - the number of records along the unlimited dimension
- the dimension list: each dimension’s name and length, where a length of 0 marks the one unlimited dimension
- the global attribute list: name, type and values
- the variable list: each variable’s name, dimensions, attributes, type, size and the offset where its data begins
After the header come the arrays of the fixed-size variables, one after another, and then the records: for each step along the unlimited dimension, one slice of every variable that uses it. Offsets are 32-bit in CDF-1 and 64-bit in CDF-2 and CDF-5.
0MagicCDFand the version byte4 bytes4Header record count, dimensions, attributes, variablesvaries…Fixed-size data each non-record variable in fullvaries…Record data one slice of each record variable per recordvaries
Telling .NC files apart
Read the first four bytes. CDF with 01, 02 or
05 is this format. The HDF5 signature 89 48 44 46 means a
NetCDF-4 file.
Not described
The reference follows Unidata's NetCDF classic format specification and PnetCDF's
CDF-5 specification. The header page's name rules (the same grammar in classic and
CDF-5, with the name regular expression) and the CDF-5 tiny example (1 padding byte
after dim) were corrected on 2026-11-13. The viewer was added on 2026-11-18; its test is
parser-test/test-nc-built.mjs.
Known, not yet covered
- Viewer: the viewer reads these parts of the CF conventions (version 1.13):
valid_range,valid_minandvalid_max, and, when none of the three is there, the valid range the_FillValue(or the type’s default fill value) implies (Unidata’s attribute conventions: a difference of 1 for the integer types, two units in the last place for the floating-point types; a byte variable with no_FillValuehas no range); time units of the form<unit> since <date>with the calendarsstandard(gregorian),proleptic_gregorian,julian,noleap(365_day),all_leap(366_day),360_day,utc(with the 27 leap seconds of the IERS list),taiand an explicitly defined calendar (month_lengths,leap_year,leap_month), as a Date column (noneis said to have no date); the leap-second rule of thestandardcalendar since CF 1.13 (time coordinates are computed as if there were no leap seconds) and how it differs fromutc;boundsandclimatology(a link to the boundary variable, its first intervals as dates, its dimensions);cell_methods(eachname: methodpair with itswhere,over,withinand parenthesis parts and the meaning of the method);grid_mapping(the grid mapping variable, the mapping named as known or unknown among the 17 of CF Appendix F, its parameters, the missing ones and the coordinatestandard_namevalues); andflag_values,flag_masksandflag_meanings(the meaning of each value). - Viewer: not read or not checked in those parts: CF 1.13 has no
leap_secondsattribute (CF 1.12 letunits_metadatacarry aleap_seconds: …value and CF 1.13 withdrew it; the viewer says so when it finds one and does not apply it); theutclist ends where the IERS file expires (2027-06-28), so a later datetime is converted without leap seconds that may follow and is marked; the standard names ofcell_methodsand thearea_typenames afterwhereandover(no standard-name or area-type table is read), the UDUNITS units afterinterval:, and the rules of CF 7.4 on cell methods beyond the three allowed sequences of phrases; the values of the grid mapping parameters (ranges, the HEALPix rule onrefinement_level, the sweep axes), thecrs_wkttext (shown as present, not parsed), and the dates inside a climatology bounds variable beyond the first three; auxiliary and multi-dimensional coordinates (coordinates) andformula_terms, which are shown as stored. - Viewer: the plot has axes with the values of the coordinate variable of each dimension (the 1-D variable of the same name, with its units; a time coordinate as dates) and a colour scale; a dimension with no coordinate variable shows indices. The five ticks sit at evenly spaced indices, not at evenly spaced values, so the numbers are the coordinate at those positions. There is no map projection: a grid mapping is described, not drawn. A variable of three or more dimensions is plotted one slice at a time (the options bar has an index box for each leading dimension, up to 32 of them).
- Viewer: a NetCDF-4 file (an HDF5 file named
.nc) is read by the NetCDF-4 view, described on its page: it lists the dimensions, variables and attributes as NetCDF does, but does not yet plot a NetCDF-4 variable or read its CF attributes. This classic viewer does not read it.
Where the specification and the libraries differ
Two places cannot be settled from the bytes. The viewer reads them the way netcdf-c and PnetCDF do and shows an option at the top of the viewer, only for a file where it changes something, that reads them the other way.
- numrecs all ones (STREAMING). The Unidata text says all ones means an unknown number of records,
found from the file length, and adds that it is not yet implemented; it defines only the 4-byte value. PnetCDF's
CDF-5 specification defines the 8-byte value (
FF× 8). netcdf-c, PnetCDF and scipy read the field as the number it spells, so the default is that number (and the problem says the file is shorter than numrecs); the option “numrecs all ones” counts the whole records from the file length instead. Sources: the Unidata file format specification, PnetCDF's CDF-5 page, netcdf-cnc3internal.c, PnetCDFncmpio_header_get.c, scipy_netcdf.py. - A lone
NC_UBYTEorNC_USHORTrecord variable (CDF-5). The note that the only record variable has no padding between records names char, byte and short; CDF-5 says its notes are unchanged. netcdf-c and PnetCDF compute the record size without padding for every type, so the default is “No padding between records”; the option “Lone record variable” reads the words of the specification, padding the record to 4 bytes. Sources: the same files.
Padding after data: the Unidata text says “In data, padding uses variable's fill value” without a MUST or SHOULD, and calls fill values “not required” (“no fill” mode), so the viewer reports a padding byte that is not the fill value as a note, not a problem.
Variants
- NetCDF classic – the original layout: a CDF header of dimensions and variables, then the arrays
- NetCDF-4 – NetCDF data stored in an HDF5 file, with compression, chunks and groups
Links
Software
- Panoply – NASA’s free viewer that plots gridded data on maps (Windows, macOS, Linux)
- NetCDF utilities – Unidata’s
ncdump,ncgenandnccopycommand-line tools - QGIS – free GIS that loads NetCDF grids as map layers (Windows, macOS, Linux)
Developers
Reference
- NetCDF file format specifications – Unidata’s specification of the classic format and its versions