The Sequence Alignment/Map (SAM) format and its compressed binary counterpart, BAM, are the standard way to store sequencing reads aligned to a reference genome. Each alignment record is a single tab-separated line with eleven mandatory fields followed by optional tags. Two of those fields, FLAG and CIGAR, carry a lot of information in very compact form. They are also a common source of confusion and filtering mistakes, so it is worth understanding them in detail.

Where FLAG and CIGAR sit in a record

The mandatory SAM fields, in order, are: QNAME (read name), FLAG, RNAME (reference sequence name), POS (1-based leftmost mapping position), MAPQ (mapping quality), CIGAR, RNEXT, PNEXT and TLEN (mate information and observed template length), SEQ (the read bases) and QUAL (base qualities). FLAG is the second field and CIGAR is the sixth. For a general introduction to SAM, BAM and related formats, see our formats overview.

The FLAG field is a set of bits

FLAG is a single integer, but it is really a collection of yes-or-no properties. Each property is assigned a power of two, and the FLAG value is the sum of all properties that are true. The defined bits are:

  • 1: the read is paired (template has multiple segments).
  • 2: each segment is properly aligned according to the aligner.
  • 4: this read is unmapped.
  • 8: the mate is unmapped.
  • 16: this read is aligned to the reverse strand.
  • 32: the mate is aligned to the reverse strand.
  • 64: this is the first read in the pair.
  • 128: this is the second read in the pair.
  • 256: secondary alignment.
  • 512: the read failed quality or vendor checks.
  • 1024: PCR or optical duplicate.
  • 2048: supplementary alignment.

For example, a FLAG of 99 is 64 + 32 + 2 + 1: a paired read, properly paired, mate on the reverse strand, first in pair. A FLAG of 147 is 128 + 16 + 2 + 1: its partner, second in pair, on the reverse strand. Seeing 99 and 147 together is typical of a well-behaved read pair.

Filtering with flags

Tools such as samtools let you include reads that have certain bits set or exclude reads with others. Common uses include:

  • Excluding unmapped reads (bit 4).
  • Excluding secondary (256) and supplementary (2048) alignments so each read is counted once.
  • Excluding duplicates (1024) after duplicate marking.
  • Selecting only properly paired reads (bit 2).

A frequent mistake is testing whether FLAG equals a specific number rather than whether a bit is set. A read marked as a duplicate may have FLAG 1123 rather than 1024, because other bits are also set. Always test bits, not whole values.

Secondary and supplementary alignments are different. A secondary alignment is an alternative placement of a read that maps to multiple locations. A supplementary alignment is part of a chimeric alignment, where different portions of one read map to different places, as can happen across structural variant breakpoints.

CIGAR: how the read lines up

The CIGAR string describes how the bases of the read align to the reference, as a series of lengths followed by operation codes. The operations are:

  • M: alignment match (can be a sequence match or mismatch).
  • I: insertion relative to the reference.
  • D: deletion from the reference.
  • N: skipped region of the reference, used for introns in spliced RNA-seq alignments.
  • S: soft clip; bases present in SEQ but not aligned.
  • H: hard clip; bases removed from SEQ entirely.
  • P: padding, used rarely in multiple alignments.
  • = and X: explicit sequence match and mismatch.

For example, 5S90M2I3M means five soft-clipped bases, ninety aligned bases, a two-base insertion, then three more aligned bases. An asterisk in the CIGAR field means no alignment information is available.

Which operations consume what

Some operations advance along the read, some along the reference, and some both. M, = and X consume both. I and S consume the read only. D and N consume the reference only. H and P consume neither.

This matters when computing alignment end positions or checking consistency. The length of SEQ should equal the sum of M, I, S, = and X lengths. The reference span equals the sum of M, D, N, = and X. Note that POS gives the position of the first aligned base, not the first soft-clipped base.

Practical tips

  • Use a flag-explaining utility to decode unfamiliar values rather than doing the arithmetic by hand.
  • Remember that M does not mean "matches the reference"; check the NM or MD tags, or use = and X, for mismatches.
  • Large N operations are expected in RNA-seq alignments but unusual in DNA alignments.
  • Extensive soft clipping at the same position across many reads can hint at an adapter problem or a structural variant.

Key takeaways

  • FLAG is a sum of bit values; filter by bits, never by exact totals.
  • Secondary and supplementary alignments mean different things.
  • CIGAR operations differ in whether they consume read bases, reference bases or both.
  • Understanding both fields makes alignment QC and filtering far more reliable.

Educational and research information only, not medical advice. Genetic results used for health decisions should be interpreted by a qualified healthcare professional; in an emergency call your local emergency number.

About Geneconvert

Independent educational articles on genomic file formats, bioinformatics and gene conversion. Learn more.

Newsletter