Skip to content

Reading CIGAR Strings

CIGAR (Compact Idiosyncratic Gapped Alignment Report) is an alignment-state string stored in each record of a SAM/BAM alignment file. Column 6 of a line compactly records how a read aligns to the reference sequence. If POS says “where,” CIGAR says “in what shape”: which portions align, where insertions and deletions occur, and which ends are clipped.

Question for this reference: How does a string such as 40M1523N36M describe one read’s alignment?

CIGAR is one column of a SAM/BAM record. For all 11 columns, FLAG, and tags, see the SAM/BAM reference.

A CIGAR string concatenates length + operator pairs from left to right. For example, 40M1523N36M is read as three pieces: 40M, 1523N, and 36M. Read them in order from the left, which is the read’s 5’ end.

  • 40M: 40 bp align to the reference
  • 1523N: skip 1,523 bp of the reference, an intron
  • 36M: another 36 bp align to the reference

This read is therefore 76 bp long, while its alignment spans 1,599 bp of the reference. The intervening 1,523 bp are absent from the read because they are an intron. This pattern is very common in RNA-seq.

The key distinction is whether an operator consumes bases from the read (query), the reference, or both. Once you know these two columns, you can calculate any CIGAR string.

OperatorMeaningConsumes queryConsumes ref
MAligned, either match or mismatch
=Aligned and bases match
XAligned but bases mismatch
IInsertion present in the read but absent from the reference
DDeletion: present in the reference but absent from the read
NSkipped reference region, usually an intron
SSoft clip: an unaligned end retained in SEQ
HHard clip: removed and absent from SEQ
PPadding for multiple alignment, rare

Remember two rules.

  • The sum of operators that consume the query (M, I, S, =, X) equals the SEQ length.
  • The sum of operators that consume the reference (M, D, N, =, X) equals the reference span covered by the read.

🧩 M does not mean “match”: M only means that positions in the read and reference were aligned. It does not guarantee that their bases are identical. Most aligners, including STAR and BWA, write both matches and mismatches as M. The = and X operators distinguish true matches from mismatches, but few tools emit them. In practice, check the NM tag rather than CIGAR for the mismatch count.

Both N and D denote a reference region absent from the read, but they mean different things.

  • D (deletion): a few reference bases are missing from this read. It is usually short, on the scale of an indel.
  • N (skipped): the alignment intentionally skips part of the reference. In RNA-seq, an N appears when a read aligns across an exon-intron-exon boundary. It is commonly hundreds to tens of thousands of base pairs long.

Thus, 50M3D26M is a read with a 3 bp deletion, while 40M1523N36M is a splice read crossing a 1,523 bp intron. This N is what makes results from splice-aware aligners such as STAR and HISAT2 the “intron-spanning alignments” described in Alignment concepts. The intron itself corresponds to exon boundaries recorded in the GTF.

If an end of a read does not align to the reference, that portion is clipped. POS refers to the first aligned base, excluding any clip.

  • S (soft clip): clipped bases remain in the SEQ column, so they count toward the SEQ length.
  • H (hard clip): clipped bases are removed from SEQ too. Hard clips occur mainly in supplementary alignments, where a read is split across multiple locations.

For example, 5S71M clips the first 5 bp and aligns the remaining 71 bp. Its SEQ is still 76 bp long, 5 + 71. Adapter remnants or low-quality ends can appear as soft clips here. For adapters and trimming, see the trimming reference.

A CIGAR of 76M for the first line of a paired-end read is simple. Here are several practical examples:

CIGARInterpretationSEQ lengthref span
76M76 bp aligned as-is; mismatches may still exist7676
5S71MFirst 5 bp soft-clipped, 71 bp aligned7671
50M2I24M2 bp insertion in the middle7674
50M3D26M3 bp deletion in the middle7679
40M1523N36MSplice read crossing a 1,523 bp intron761599
30M500N20M2I24MSplice followed by a 2 bp insertion76574

Use the last row to verify the reference span. The reference-consuming operators are M, D, N, =, and X, so 30M (30) + 500N (500) + 20M (20) + 24M (24) = 574. The 2I does not consume the reference and is excluded. The SEQ length is the sum of query-consuming operators: 30M + 20M + 2I + 24M = 76.

💡 To inspect CIGAR directly: open alignments from a particular region with samtools view file.bam chr21:33426891-33427000. Column 6 is CIGAR. For a gene where you suspect splicing, check whether N matches the expected intron length and whether I or D clusters at a particular position. Together with counting through FLAG filters in samtools view -c, this is a basic alignment-debugging technique.

CIGAR compresses the shape of one read’s alignment from left to right as length+operator pairs. Instead of memorizing all nine operators at first, remember three points.

  1. M means aligned, not matched. Use the NM tag for the actual mismatch count.
  2. N skips an intron in a splice alignment; D is a short deletion. RNA-seq splice reads contain N.
  3. The sum of query-consuming operators is the SEQ length, and the sum of reference-consuming operators is the reference span.

Continue with Reading one SAM/BAM line for the context of a complete SAM record and Finding read positions for the concept of splice alignment.