Blog · Tutorials

What Is a .nii File? NIfTI and .nii.gz Explained

By Nalvera Team · 1 November 2026

A .nii file is a NIfTI image: one file that holds a 3D medical scan, such as a CT or MRI volume, together with its voxel size and its position in space.

NIfTI is widely used in medical imaging research, and AI models such as TotalSegmentator read and write it.

What Does a NIfTI File Store?

NIfTI stands for Neuroimaging Informatics Technology Initiative, the US National Institutes of Health project that defined the format as a successor to the older Analyze format. A NIfTI file has two parts:

  • A header with the image dimensions, the voxel size in millimetres, the type of number stored per voxel, and the orientation: where each voxel sits in space.
  • The image data: one number per voxel. A CT stores Hounsfield units; an MRI stores signal intensities without a fixed unit.

A NIfTI file can also hold 4D data, such as the time series of a functional MRI scan.

.nii vs .nii.gz

A .nii.gz file is a .nii file compressed with gzip. The image inside is identical, and NIfTI programs open both without unpacking first. Compression makes scans smaller, and segmentation masks much smaller, since most of their voxels are zero. A single .nii or .nii.gz file is the usual form today.

How to Open a .nii or .nii.gz File

Free desktop viewers open NIfTI files directly:

  • ITK-SNAP: browsing the slices and outlining structures by hand.
  • 3D Slicer: viewing, segmentation and 3D rendering.
  • MRIcroGL: quick 2D and 3D views, common in brain imaging.
  • FIJI (ImageJ): general image analysis.

In Python, the nibabel library reads a NIfTI file in a few lines:

import nibabel as nib

img = nib.load("scan.nii.gz")
# dimensions and voxel size in mm
print(img.shape, img.header.get_zooms())
# the voxel values as a NumPy array
data = img.get_fdata()

Segmentation Masks as NIfTI Label Maps

A segmentation mask is a NIfTI file on the same grid as its scan. Each voxel holds a whole number: 0 for background and one number per structure, for example 1 for the spleen and 2 for the right kidney. A separate list gives the name of each number; the main TotalSegmentator task uses 117 of them. Viewers such as ITK-SNAP and 3D Slicer show the mask as coloured outlines over the scan.

DICOM vs NIfTI

Scanners and hospital systems store images as DICOM; research software and AI models mostly use NIfTI.

DICOMNIfTI
Files per scanUsually one file per sliceOne file per volume
HeaderDetailed patient, scanner and acquisition dataImage geometry and data type, with no patient fields
Used byScanners and hospital archives (PACS)Research software and AI models

dcm2niix is the common free converter from DICOM to NIfTI. Nalvera.AI already does this for you when you upload a DICOM folder. To run it yourself in Python:

# pip install dcm2niix
import dcm2niix

# -z y: compress to .nii.gz
# -f: file name, -o: output folder
dcm2niix.main([
    "-z", "y", "-f", "scan", "-o", ".",
    "dicom_folder",
])

Does a NIfTI File Contain Patient Data?

The NIfTI header has no fields for a patient's name, ID or date of birth. Two places can still identify someone: free-text fields in the header, where a converter may have written series or patient details, and the image itself, since a head scan can show the face. The file name can carry a name or an ID as well.

Nalvera.AI clears the free-text header fields of every NIfTI file on upload.

Frequently Asked Questions About NIfTI Files

Is .nii.gz the same as NIfTI?

Yes. A .nii.gz file is a NIfTI file compressed with gzip; programs that read NIfTI open both, and the image is the same.

Which program opens a .nii.gz file?

Free viewers such as ITK-SNAP, 3D Slicer, MRIcroGL and FIJI open it directly, and the nibabel library reads it in Python.

Can I convert NIfTI back to DICOM?

Yes, as a new DICOM series: 3D Slicer, for example, exports volumes to DICOM. The new files lack the original patient and scanner details, because the NIfTI file never held them.

Run AI Models on Your NIfTI Files

Nalvera.AI runs AI models on .nii.gz files and DICOM folders in your browser: segmentation of organs, bones and muscles, research reports from CT, and synthetic images.

Explore the AI models

Research use only. Nalvera.AI is not a medical device, and AI-generated outputs are not intended for clinical diagnosis or treatment.