Skip to main content
v2026.11,986 entries · CC-BY 4.0

NEXUS File Format: Blocks, Syntax and the NeXus Look-Alike

NEXUS (.nex) is a plain-text phylogenetics format built from blocks; this guide shows its syntax and separates it from HDF5 NeXus.

Written and maintained by CASRAI Editorial Board

Published

On this page

The NEXUS file format is a plain-text format for exchanging phylogenetic data, usually saved as a .nex file. It stores taxa, character matrices and trees in labelled blocks, and it was described by Maddison, Swofford and Maddison in Systematic Biology in 1997. A second, unrelated format with a near-identical name, NeXus, is an HDF5-based format for neutron, x-ray and muon science.

What is a nexus, and which one do you have?

Searches for “nexus” mix several unrelated things. Two are file formats, and they are easy to confuse because both are spelled “Nexus” and both are used in laboratories.

  • NEXUS (phylogenetics). A text file that begins with #NEXUS and holds sequence or morphological data and trees. Programs such as PAUP*, MrBayes, Mesquite, MacClade and SplitsTree read and write it. This is the main subject of this page.
  • NeXus (neutron, x-ray and muon science). A data format maintained for large-facility experiments and built on HDF5. It is covered in its own section below so you can rule it out quickly.
  • Sonatype Nexus Repository and other products. These are software tools that share the name and have nothing to do with either file format. This page does not cover them.

If the file ends in .nex and a text editor shows readable lines starting with #NEXUS, it is the phylogenetics format. A binary-looking file from a synchrotron, neutron or muon facility is the other one.

What is a .nex file?

A .nex file is the usual container for NEXUS data. The format was published by David R. Maddison, David L. Swofford and Wayne P. Maddison in Systematic Biology 46(4):590-621 (1997), “NEXUS: an extensible file format for systematic information” (doi:10.1093/sysbio/46.4.590). According to the abstract, a NEXUS file is organised into separate blocks, each containing one particular kind of information. The paper describes the commands used in the blocks and gives guidelines for programs that read, write and extend the format.

The abstract divides blocks into two kinds. Public blocks hold information that several programs can use: taxa, morphological and molecular characters, distances, genetic codes, assumptions, sets and trees. Private blocks hold information meant for a single program. This split is the reason one file can pass from an alignment program to a tree-search program to a tree viewer: each program reads the public blocks it understands.

The common extensions are .nex and .nxs, and the content type is plain text, so any text editor can open the file (Wikipedia, “Nexus file”, read 2026-11-20).

Anatomy of a NEXUS file

A lecture handout from the Delwiche laboratory at the University of Maryland (PAUP lecture notes, read 2026-11-20) shows the minimal pattern. Reproduced as an annotated example:

#NEXUS
Begin Taxa;
  Dimensions NTax=4;
  TaxLabels fish frog snake mouse;
End;
Begin Characters;
  Dimensions NChar=20;
  Format DataType=DNA;
  Matrix ... ;
End;
Begin Trees;
  Tree best=(fish, (frog, (snake,mouse)));
End;

The syntax rules this example shows

  • The header. The file begins with the string #NEXUS (Delwiche lab notes).
  • Blocks. A block starts with begin followed by the block name and a semicolon, and ends with end; or endblock;. A program that does not understand a block ignores it, which is how private blocks can sit in the same file without breaking other programs (Delwiche lab notes).
  • Semicolons. Each command ends with a semicolon (Delwiche lab notes).
  • Comments. Comments are written in square brackets; keywords are not case-sensitive; and each predefined block may appear once per file (Wikipedia, “Nexus file”, read 2026-11-20).

What each part of the example does

The Taxa block declares how many taxa there are and names them. The Characters block declares how many characters each taxon has, the data type (here DNA) and the matrix itself. The Trees block stores a tree as a nested, parenthesised list with a name, here best. Wikipedia describes the tree notation in the Trees block as Newick.

Reading the example line by line

Each count in the example matches something visible elsewhere in the file. NTax=4 agrees with the four labels after TaxLabels (fish, frog, snake, mouse). NChar=20 states how many characters each taxon has in the matrix, and DataType=DNA says what kind of characters they are. The tree in the Trees block uses the same four taxon names, nested to show which are grouped together. When a program rejects a NEXUS file, a mismatch between a declared dimension and the data that follows is one of the first things worth checking.

A quick checklist before loading a file

  • The first line is #NEXUS.
  • Every begin has a matching end; (or endblock;).
  • Every command ends with a semicolon.
  • No predefined block appears twice in the same file.
  • Any commentary is inside square brackets, so programs skip it.
  • The names in the Taxa block match the names used in the Characters and Trees blocks.

These checks restate the syntax rules above; the last item is a practical consequence of the format sharing one taxon list across blocks.

Block types

The 1997 paper and the Wikipedia article together name the following predefined blocks. The table lists only what these sources state.

Block What it holds Source
TAXA The taxa (names of the units being compared) Maddison et al. 1997; Delwiche lab notes
CHARACTERS Morphological or molecular character data Maddison et al. 1997; Delwiche lab notes
DATA Equivalent to a CHARACTERS block that also defines the taxa (the NewTaxa form) Wikipedia, “Nexus file”
TREES One or more trees, in Newick notation Maddison et al. 1997; Wikipedia
DISTANCES Distance data Maddison et al. 1997
SETS Named sets such as CHARSET and TAXSET Maddison et al. 1997; Wikipedia
ASSUMPTIONS Assumptions used in analysis Maddison et al. 1997; Wikipedia

Genetic codes are also listed among the public blocks in the paper’s abstract. Anything beyond these, such as a program’s own settings block, is a private block that only that program uses.

NeXus (HDF5) compared with NEXUS (phylogenetics)

The data table below the article sets the two formats side by side: domain, underlying file type, basic structural unit, stewardship and the quickest way to recognise each. In short, NeXus is described on nexusformat.org as “a common data format for neutron, x-ray, and muon science”. The NeXus manual states that it is built on top of the scientific data format HDF5, that NXentry is the only class required in a valid NeXus data file, and that application definitions give the minimum information needed for a particular use and are written in NXDL, an XML-based language. The format is maintained by the NeXus International Advisory Committee (NIAC), and the reference citation is J. Appl. Cryst. (2015) 48, 301-305 (doi:10.1107/S1600576714027575).

The practical difference follows from the underlying file type. A NEXUS phylogenetics file is text and can be read line by line. A NeXus file is an HDF5 container organised into classes such as NXentry and NXdata, and you inspect it with HDF5-aware tools rather than a text editor.

How to open and read a .nex file

Questions such as “how do I set up Nexus” usually mean one of two things: install a program that reads the phylogenetics format, or open a file someone has sent. For a NEXUS file, there is nothing to install to read it, because it is plain text.

  1. Open it in a text editor and check that the first line is #NEXUS.
  2. Read the block names after each begin to see what the file contains.
  3. For analysis, load it in a program that supports the format. The Wikipedia article names PAUP*, MrBayes, Mesquite, MacClade and SplitsTree as programs that use it.

On this site, the PAUP guide and the Biopython guide cover two tools that work with phylogenetic data, and how to make a phylogenetic tree places file formats in the wider workflow. Tree and matrix repositories are described in the TreeBase guide.

Where it matters in phylogenetics workflows

The point of the block structure is interchange. Because public blocks are shared and unrecognised blocks are ignored, a data set assembled for one program can be passed to another without re-keying. The 1997 paper frames the format as extensible: new blocks and commands can be added, which is why the paper includes guidelines for programs that extend it rather than only read it. Related formats named in the Wikipedia article include Newick (trees only), NeXML and phyloXML (both XML-based).

How to cite the format

When a methods section mentions the format, the defining reference for NEXUS is the 1997 paper (doi:10.1093/sysbio/46.4.590). For NeXus, the project site gives J. Appl. Cryst. (2015) 48, 301-305 (doi:10.1107/S1600576714027575). Citing the right one matters because a reader who follows the wrong citation lands in a different field entirely.

Common misunderstandings

  • “NEXUS and NeXus are the same format.” They are not. One is a text format for systematics; the other is an HDF5-based format for neutron, x-ray and muon data.
  • “A .nex file only holds trees.” It can hold taxa, character data, distances, sets and assumptions as well as trees.
  • “Every program reads every block.” Programs read the public blocks they support and ignore the rest.
  • “The Nexus Repository tool opens .nex files.” That product shares only the name.

Frequently asked questions

What is a nexus?

In general use it is a connection point. In research data it names two file formats: NEXUS, a text format for phylogenetic data (taxa, characters, trees), and NeXus, an HDF5-based format for neutron, x-ray and muon science data.

What is the use of Nexus Repository?

Nexus Repository is a software product unrelated to either file format, and this page does not describe it. For research data, the relevant meanings are the two formats above.

How do I set up Nexus?

To read a NEXUS phylogenetics file, no setup is needed: open the .nex file in a text editor and look for #NEXUS on the first line. To analyse it, use a program that supports the format, such as PAUP*, MrBayes, Mesquite, MacClade or SplitsTree.

What is a .nex file?

A .nex file is a plain-text NEXUS file: a #NEXUS header followed by blocks (Taxa, Characters, Trees and others), each opened with begin, closed with end;, and made of commands that end in semicolons.

Sources

Data: NEXUS (phylogenetics) and NeXus (neutron, x-ray, muon) data formats compared

Side-by-side comparison of the two file formats named Nexus, compiled from the 1997 NEXUS paper abstract, a university PAUP lecture handout, the Wikipedia article on Nexus files, and the NeXus website and manual.

NEXUS (phylogenetics) and NeXus (neutron, x-ray, muon) data formats compared
AttributeNEXUS (phylogenetics)NeXus (neutron, x-ray, muon science)
Research domainSystematic and phylogenetic data (taxa, characters, trees)Neutron, x-ray and muon science
Underlying file typePlain text (text/plain)HDF5
Basic structural unitBlocks opened with begin and closed with endClasses; NXentry is the only class required in a valid file
How it is recognisedFile begins with #NEXUS; extensions .nex or .nxsBuilt on HDF5; described by class and application definitions
Defining referenceMaddison, Swofford and Maddison 1997, Syst Biol 46(4):590-621J. Appl. Cryst. (2015) 48, 301-305
Maintained byNot stated in the sources readNeXus International Advisory Committee (NIAC)
Definition language for specificationsCommands ending in semicolonsApplication definitions written in NXDL (XML)

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about NEXUS File Format: Blocks, Syntax and the NeXus Look-Alike

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →