NC File Documentation


Summary

An .nc file is a netCDF (Network Common Data Form) file: a self-describing binary format from Unidata/UCAR for multidimensional scientific data such as temperature over latitude, longitude, and time. Its MIME type is application/x-netcdf. You do not read it in a text editor — open it with the free Panoply (NASA GISS) to plot variables, QGIS if it is geospatial, or Python with xarray. (The same extension is also used for CNC G-code machine programs, which are unrelated plain text.)

Technical details

FeatureValue
Full namenetCDF — Network Common Data Form
File extension.nc (also .nc4, .cdf)
MIME typeapplication/x-netcdf
Format typeSelf-describing binary multidimensional array data
DeveloperUnidata / UCAR
Introduced1988
Open standardYes — open specification and open-source libraries
Byte orderBig-endian (classic); XDR-based
Classic magic43 44 46 (“CDF”) + version byte (01/02/05)
netCDF-4 magic89 48 44 46 0D 0A 1A 0A (“\x89HDF”) — it is an HDF5 file
On-disk variantsClassic, 64-bit offset, CDF-5, netCDF-4/HDF5
Data modelNamed dimensions, variables (arrays), and attributes (metadata)
Typical fieldsClimate, weather, oceanography, satellite, GIS grids
Data sourcesNOAA, NASA, Copernicus / ECMWF
Related extensions.cdf, .nc4, .hdf5, .h5
Free toolsPanoply, ncview, QGIS, Python (xarray/netCDF4), CDO/NCO
Specificationdocs.unidata.ucar.edu
File signature (magic bytes)
43 44 46 01

Offset 0, 4 bytes. Classic netCDF begins with the ASCII string CDF (43 44 46) followed by a version byte: 01 for the classic format, 02 for 64-bit offset, 05 for CDF-5. Newer netCDF-4 files are HDF5 internally and instead start with the HDF5 signature 89 48 44 46 0D 0A 1A 0A (\x89HDF\r\n\x1A\n) at offset 0. Either way the file is binary scientific data, never human-readable text.

What is an NC (netCDF) file?

An .nc file is a netCDF (Network Common Data Form) file. It was created by Unidata/UCAR in 1988 as a self-describing, machine-independent binary format for array-oriented scientific data. A single .nc file stores multidimensional variables — for example temperature indexed by latitude, longitude, and time — together with the metadata that describes their units, dimensions, and coordinates. That “self-describing” design means a program can open a netCDF file it has never seen before and discover its full structure without any external schema, which is why the format dominates climatology, meteorology, oceanography, and geospatial science. Most people meet an .nc file after downloading climate, weather, ocean, or satellite data from NOAA, NASA, or Copernicus/ECMWF.

One caution up front: the same .nc extension is also used, unrelatedly, for CNC machine programs written in RS-274 G-code. Those are plain text full of G and M codes. If your file opens as readable text rather than binary, you have the machining meaning, not netCDF, and the tools below do not apply.

The data model: dimensions, variables and attributes

netCDF is built on three primitives. Dimensions are named axes with a length, such as lat = 180, lon = 360, and an unlimited time axis that can grow. Variables are typed multidimensional arrays defined over those dimensions; a variable temperature(time, lat, lon) is a cube of values. Attributes are the metadata attached either to a variable (its units, _FillValue, scale_factor) or to the whole file (global attributes recording title, source, and history).

The key convention is the coordinate variable: a one-dimensional variable with the same name as a dimension (for instance a variable lat(lat) holding the actual latitude values). This is how a reader turns array index 47 along the lat axis into a real latitude in degrees. The widely used CF (Climate and Forecast) metadata conventions build on this to standardise unit strings and coordinate semantics so that tools agree on what a variable means.

The classic on-disk header: CDF, numrecs and the lists

The original “classic” netCDF format has a compact binary header. The first four bytes are the ASCII string CDF followed by a version byte (0x01 classic, 0x02 64-bit offset, 0x05 CDF-5). Immediately after the magic number comes numrecs, the number of records along the unlimited dimension, and then three sequential lists that make the file self-describing:

magic     : 'C' 'D' 'F' version_byte      (4 bytes)
numrecs   : int32  number of records
dim_list  : the named dimensions and their lengths
gatt_list : the global attributes
var_list  : each variable's name, dimensions, attributes,
            data type, size, and the byte offset where its
            data begins in the file

An empty classic file is just 32 bytes: the 4-byte magic followed by seven 32-bit zeros representing an empty record count and three empty lists. Crucially, var_list records the absolute byte offset of each variable's data, so a reader can seek straight to the array it wants without scanning the whole file — the header is a complete map of the payload.

netCDF-4 is HDF5 underneath

Since version 4, netCDF gained a second on-disk representation: a netCDF-4 file is actually an HDF5 file, and it begins with the HDF5 signature 89 48 44 46 0D 0A 1A 0A rather than CDF. Layering the netCDF data model onto HDF5 added features the classic format never had: hierarchical groups (a directory tree of variables inside one file), per-variable chunking (storing an array as tiles so a sub-region can be read without the whole array), and transparent compression (usually zlib/deflate per chunk). This is why a large climate dataset in netCDF-4 can be far smaller than the same data in classic format, and why an old tool that only understands the classic CDF header will fail to open a modern .nc until its netCDF/HDF5 library is updated.

Reading, plotting and subsetting an .nc file

Because netCDF is binary and multidimensional, you work with it through data tools rather than a text editor. Panoply from NASA GISS plots any variable as a map or line chart and browses the metadata; ncview gives a fast visual scrub through a variable; QGIS loads a georeferenced .nc as a raster or mesh layer. The standard free programming toolchain is Python with xarray and the netCDF4 library:

import xarray as xr
ds = xr.open_dataset("air.mon.mean.nc")
print(ds)                       # dimensions, variables, attributes
t = ds["air"].sel(time="2023-01").mean("time")   # one slice
t.to_dataframe().to_csv("jan2023.csv")           # export a slice

Two common real tasks are exporting a chosen variable or slice to CSV, and exporting a georeferenced variable to GeoTIFF for GIS (via QGIS or GDAL's gdal_translate with the NETCDF driver). Note that you extract a slice — a multidimensional file has no single flat CSV representation, so you pick the variable and the time or level you need. For large files, command-line operators CDO and NCO (cdo, ncks, ncdump) subset and inspect without loading everything into memory.

References