A NetCDF-4 file is an HDF5 file written by the NetCDF library under the conventions in the “NetCDF-4 format” part of Unidata’s file format specification, read 2026-11-12. This page lists how each NetCDF object is stored.
Objects
| NetCDF | HDF5 |
|---|---|
| Group | Group. The root group is /. Global attributes become attributes of each group. |
| Variable | Dataset with the same name. If a variable has a dimension’s name but is not its coordinate variable, the dataset name gets the prefix _nc4_non_coord_. |
| Attribute | Attribute on the group or dataset. |
| Dimension with a coordinate variable | The variable’s dataset, made an HDF5 dimension scale of the same type, holding the coordinate data. |
| Dimension without a variable | An empty dimension scale of type char; only its name and length matter. Its NAME attribute is This is a netCDF dimension but not a netCDF variable. |
| Variable’s dimensions | HDF5 dimension scales, with the attributes the HDF5 dimension scale API keeps: CLASS, NAME, REFERENCE_LIST, DIMENSION_LIST. When NetCDF writes, every dimension has a scale. |
Types and values
- The atomic types map to HDF5 native types:
NC_BYTEsigned char,NC_UBYTEunsigned char,NC_SHORT/NC_USHORT,NC_INT/NC_UINT,NC_INT64/NC_UINT64(long long),NC_FLOAT,NC_DOUBLE;NC_CHARisH5T_C_S1andNC_STRINGa variable-length array ofH5T_C_S1. - Data is written in the writing machine’s byte order unless the user sets one for a variable; HDF5 swaps on reading as needed.
- Each user-defined type corresponds exactly to an HDF5 user-defined type; only base types that NetCDF-4 has may be used (no HDF5 reference types).
- Compression: NetCDF-4 writes only zlib (deflate levels 1 to 9; asking for 0 turns deflation off). It can read szip data if its HDF5 library supports it, but cannot write it.
- The library writes variables in creation order.
Creation order, features NetCDF-4 leaves out, classic model, HDF4
- Creation order. HDF5 keeps objects in alphabetical order unless creation order is switched on (HDF5 1.8 and later). NetCDF-4 requires, for every group, link creation order and attribute creation order both tracked and indexed (
H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXEDin the group creation property list), and for every dataset attribute creation order set the same way. - Groups must be strictly hierarchical (HDF5 would allow, for instance, a group that is its own grandparent). Each group has its own global attributes.
- Not allowed in NetCDF-4 files though HDF5 has them: non-hierarchical group structures, HDF5 reference types, multiple links to one object, user-defined atomic data types, stored property lists, more permissive object names, the HDF5 date/time type, and attributes attached to user-defined types.
- Reserved names. Attribute names starting with an underscore are reserved for the library: the hidden attributes above (
_NCProperties,_Netcdf4Dimid,_Netcdf4Coordinates,_nc3_strict), and on the classic side_FillValue,_Unsigned(whether byte data is unsigned) and_Encoding(the encoding of char data). The dataset prefix_nc4_non_coord_is also reserved. - Classic model. Every classic and 64-bit offset file can be represented in NetCDF-4 with no loss. A file made with the classic-model flag gets the root attribute
_nc3_strictand the library then refuses groups, the added primitive types (NC_UBYTE,NC_USHORT,NC_UINT,NC_INT64,NC_UINT64,NC_STRING) and user-defined types, so that older programs relinked to a NetCDF-4 library can still read the data. Per-variable compression, chunking, dynamic schema changes and larger variable sizes remain available. - HDF4 SD files (library 4.1 and later): readable, read-only, only if made with the Scientific Dataset API. Types translate:
DFNT_CHARtoNC_CHAR;DFNT_UCHARandDFNT_UINT8toNC_UBYTE;DFNT_INT8toNC_BYTE;DFNT_INT16toNC_SHORT;DFNT_UINT16toNC_USHORT;DFNT_INT32toNC_INT;DFNT_UINT32toNC_UINT;DFNT_FLOAT32toNC_FLOAT;DFNT_FLOAT64toNC_DOUBLE.
Filters: Zstandard, Blosc, bzip2 and the others
From Unidata's “Appendix D. NetCDF-4 Filter Support” (netcdf-c 4.10.1 documentation, filters.html) and the HDF Group's registry of filter plugins (RegisteredFilterPlugins.md in HDFGroup/hdf5_plugins), read 2026-11-13.
- Mechanism. A variable needs chunking; each chunk passes through its filters in the order they were defined when writing and in reverse when reading. A filter is a numeric HDF5 filter id (ids above 32767 may be used for testing unregistered) plus a vector of 32-bit unsigned parameters, supplied by
nc_def_var_filter, by the special CDL attribute_Filter("307,9|4,32,32": pipeline separated by|, here bzip2 then szip), or bynccopy -F. Filters cannot be defined on variable-sized types (NC_STRING, vlen types, compounds containing them). Once defined a filter cannot be removed or reordered;fletcher32is always first, and shuffle, if enabled, goes before the others. The filter's shared library must be found in the plugin path by HDF5 (it exportsH5PLget_plugin_typeandH5PLget_plugin_info). Parameters wider than 32 bits (doubles, 64-bit integers) are passed as two 32-bit words, the value stored as little-endian split into two integers, with byte swaps on big-endian machines (Appendix A of the filter document). The text form of a parameter allows tags:b/ubbyte,s/usshort, none oru32-bit integer,ffloat,ddouble,l/ul64-bit. - The four built-in HDF5 filters inherited by NetCDF-4 are shuffle, fletcher32, deflate (zlib) and szip; they have their own API calls (
nc_def_var_deflate,nc_def_var_szip, …). zlib deflate is the only compression NetCDF-4 will create by itself (levels 0 to 9; level 0 does not compress but costs time). - bzip2 (filter id 307): one parameter,
cd_values[0]= block size in units of 100 kilobytes, 1 to 9. - Zstandard (filter id 32015): zero or one parameter;
cd_values[0]is the optional compression level (default 3; regular levels 1 up toZSTD_maxCLevel(), currently 22, levels above 20 use much more memory; negative levels trade ratio for speed). Needslibzstdand an HDF5 wrapper plugin; for NCZarr also a Codec wrapper. - Blosc (filter id 32001): up to 7 parameters, the first four reserved:
[0]plugin revision,[1]Blosc format version,[2]datatype size,[3]pre-computed chunk size in bytes (all four filled in by the filter), then optional[4]compression level 0 (none) to 9,[5]shuffle 0 none, 1 byte-wise, 2 bit-wise,[6]compressor 0 BLOSCLZ, 1 LZ4, 2 LZ4HC, 3 SNAPPY, 4 ZLIB, 5 ZSTD. For example0,0,0,0,5,1,1is level 5, byte shuffle, LZ4. In Zarr it is the JSON codec{"id": "blosc", "cname": "lz4", "clevel": 5, "shuffle": 1}. The registry also lists Blosc2 as filter 32026 (not described here). - Other registry ids relevant to NetCDF: BitGroom 32022 and Granular BitRound 32023 (the original CCR quantization filters, which the library now replaces with built-in quantization that needs no filter on reading), BitRound 32032 (parameters:
[0]NSB, mandatory;[1]datum size 4 or 8,[2]fill-value-defined flag,[3],[4]raw fill value low and high words;[1]to[4]are internal). ncdump -s -hshows filter ids, parameters and Codecs of a file without needing the filter.
Quantisation attributes
From Unidata's “Lossy Compression with Quantize” (netcdf_quantize.html, read 2026-11-13). Quantisation is applied only when writing, to NC_FLOAT and NC_DOUBLE variables; the output is legal data, so readers need no filter. It does not shrink data by itself, only helps a later compressor such as deflate. Enable it per variable after definition and before nc_enddef with nc_def_var_quantize(ncid, varid, mode, nsd); nc_inq_var_quantize inquires. Modes: NC_QUANTIZE_BITGROOM, NC_QUANTIZE_GRANULARBR, NC_QUANTIZE_BITROUND, and NC_NOQUANTIZE to switch off. Fill values are never quantised.
| Algorithm | Integer attribute added to the variable | Parameter and range | How it works |
|---|---|---|---|
| Bit Groom | _QuantizeBitGroomNumberOfSignificantDigits | NSD, 1–7 (float) or 1–15 (double) significant decimal digits | Computes once the mantissa bits needed for NSD digits and sets the excess bits to zero in one value, to one in the next, alternating, which keeps the mean. |
| Granular Bit Round | _QuantizeGranularBitRoundNumberOfSignificantDigits | NSD, 1–7 or 1–15 | Determines the bits needed for each value and uses IEEE rounding; better compression. |
| Bit Round | _QuantizeBitRoundNumberOfSignificantBits | NSB, 1–23 (float) or 1–52 (double) mantissa bits | Keeps a fixed number of explicit mantissa bits and rounds the rest. |
The attribute records the setting; without it readers cannot know quantisation was applied. Documented maximum relative errors: Bit Groom for NSD 1 to 6 is 3.1e-2, 3.9e-3, 4.9e-4, 3.1e-5, 3.8e-6, 4.7e-7; Granular Bit Round 1.4e-1, 1.9e-2, 2.2e-3, 1.4e-4, 1.8e-5, 2.2e-6; the error of Bit Groom for any value V is within 0.5 × V × 2−NSB. To match Bit Groom's definition of decimal precision with Bit Round use NSB 3, 6, 9, 13, 16, 19, 23 for NSD 1 to 7.
NCZarr
From Unidata's “The NetCDF NCZarr Implementation” (nczarr_head.html, read 2026-11-13; netcdf-c 4.8.0 and later, version 2 of Zarr). NCZarr stores the NetCDF-4 data model in the Zarr v2 layout and is meant to remain readable as ordinary Zarr, and vice versa.
- Addressing and storage. A dataset is opened through a URL (
file:,s3:orhttps:) with a fragment ofmodeflags:nczarrorzarr(format),file,zipors3(storage medium),v2,consolidated(use the/.zmetadataobject) andnoxarray; reading infers the format by probing. Storage is a key-value map: keys are UTF-8 paths with/separators and the dataset root is marked by/.zgroup; backends are an S3 bucket (keys limited to 1024 bytes), a directory tree, or a zip file (needs libzip). - Objects.
.zgroupfor a group,.zarrayfor a variable,.zattrfor the attributes of a group or variable (JSON dictionaries), and chunk objects named by the chunk indices separated by dots (n1.n2...nr). NCZarr adds its own attributes inside.zattr, all with JSON-string values:_nczarr_superblock(root only: version, deprecated, plus keys that only keep older libraries from crashing),_nczarr_group(dimensions: names, sizes and an optional unlimited flag;arrays: variable names;groups: sub-group names),_nczarr_array(dimension_references: fully qualified shared dimension names;storage: chunked versus contiguous and the scalar marker) and_nczarr_attr(types: the type of every attribute, as a NumPy dtype). The keys are lower-case since 2022 (upper-case is still read). - Differences from Zarr. Zarr has only anonymous dimensions, untyped attributes and no unlimited dimensions; NCZarr has shared named dimensions, typed attributes and unlimited dimensions. NetCDF scalars are written as arrays of shape [1] with a note in
_nczarr_array. Contiguous and compact storage are treated as chunked with a single chunk. Unsupported: user-defined types (enum, opaque, vlen, compound). Atomic types: char, byte, ubyte, short, ushort, int, uint, int64, uint64, string. - Reading plain Zarr. The
_nczarr_groupcontents are inferred by searching for.zgroup,.zattr,.zarray; dimension references from the array shape (creating phantom shared dimensions); attribute types by parsing the first value. Zarr types not recognised includec(complex),m(timedelta) andM(datetime); unknown filters are not usable; column-major arrays are read in the wrong order. The Xarray attribute_ARRAY_DIMENSIONS(a list of dimension names) is read and written for root-group variables unlessnoxarray. - Attribute values may be any JSON: an atomic value or array maps to a typed vector; an
NC_CHARvalue that parses as JSON is written as that JSON with dtype|J0, otherwise as a JSON string with dtype>S1; other JSON structures are read back as text of typeNC_CHAR. - Strings. Fixed-length:
_nczarr_default_maxstrlen(root attribute, default 128) and per-variable_nczarr_maxstrlen; dtypes>S1forNC_CHAR,|S1and|SnforNC_STRINGof maximum length 1 and n. - Filters. A Zarr codec is a JSON dictionary with an
"id"plus algorithm keys; NCZarr reuses the HDF5 filter implementations through a pair of well-known library entry points (HDF5:H5PLget_plugin_type/H5PLget_plugin_info; codec:NCZ_get_codec_info), converting between the id-plus-integers model and the JSON model. The Zarr metadata splits a filter chain into onecompressor(the last filter) and an orderedfiltersarray. The special attribute_Codecsshows the JSON codecs of a variable, and the plugin librarieslib__nczh5filtersandlib__nczstdfiltersprovide shuffle, fletcher32, deflate, szip, bzip2, zstandard and blosc support. NCZarr is not thread-safe. - Zarr version 3. The document says an appendix on Zarr version 3 support was added in 2024; the content of that appendix was not part of the text read here.