The CIGAR string encodes the alignment trace by pairing integer lengths with single-letter operation codes (e.g., M for match/mismatch, I for insertion, D for deletion). This compact representation allows downstream variant calling tools to rapidly reconstruct the read-to-reference mapping without storing the full pairwise alignment, enabling efficient storage and high-speed parsing of massive genomic datasets.
Glossary
CIGAR String Encoding

What is CIGAR String Encoding?
A CIGAR (Compact Idiosyncratic Gapped Alignment Report) string is a concise, standardized notation within SAM and BAM files that summarizes the sequence of match, insertion, deletion, and clipping operations required to align a sequencing read to a reference genome.
Precise CIGAR interpretation is critical for accurate variant allele fraction calculation and indel discovery. Operations like S (soft clipping) and H (hard clipping) distinguish unaligned read segments from true deletions, preventing false positive variant calls at read edges and ensuring the correct calculation of coverage depth at candidate loci.
Core Operations and Properties
The CIGAR string is a compact, operational summary of how a sequencing read aligns to a reference genome. It encodes the precise sequence of matches, insertions, deletions, and clipping events, serving as the fundamental data structure for variant calling and alignment visualization.
Core CIGAR Operations
The CIGAR string uses a defined set of single-character operations to describe an alignment. Each operation is preceded by a length integer, forming a compact run-length encoding.
- M (Match/Mismatch): An alignment match, which can represent a sequence match or a mismatch. The read base is aligned to the reference.
- I (Insertion): Bases present in the read but absent from the reference genome.
- D (Deletion): Bases present in the reference but absent from the read. This operation consumes reference bases but no read bases.
- N (Skipped Region): Represents an intron or other large gap in the read's alignment to the reference, typically used in spliced alignments.
- S (Soft Clipping): Read bases at the start or end that are not aligned but are retained in the Sequence Alignment Map (SAM) record's sequence field.
- H (Hard Clipping): Read bases that are not aligned and are also removed from the SAM record's sequence field.
Parsing the String: `100M1I50M1D25M`
A CIGAR string is parsed by iterating through pairs of numbers and operation characters. The example 100M1I50M1D25M describes a 176-base read with a complex alignment.
- 100M: The first 100 bases of the read align to the reference with matches or mismatches.
- 1I: The next base in the read is an insertion relative to the reference. It consumes 1 read base and 0 reference bases.
- 50M: The subsequent 50 read bases align to the reference.
- 1D: A single base is deleted from the reference. It consumes 1 reference base and 0 read bases.
- 25M: The final 25 read bases align to the reference.
This compact representation allows tools to rapidly reconstruct the exact gapped alignment without storing the full pairwise alignment matrix.
Consumption Rules and Length Calculation
A critical property of the CIGAR string is the distinction between read-consuming and reference-consuming operations. This distinction is essential for calculating alignment length and mapping coordinates.
- Read-Consuming Operations: M, I, S, and =/X (sequence match/mismatch) advance the position in the read sequence.
- Reference-Consuming Operations: M, D, N, and =/X advance the position on the reference genome.
- Non-Consuming Operations: H and P (padding) consume neither read nor reference.
The sum of lengths for read-consuming operations must equal the length of the SEQ field in the SAM record. The sum of reference-consuming operations defines the total span of the reference covered by the alignment, which is used to calculate the mapping quality and identify structural variants.
Extended CIGAR for Long Reads
The original CIGAR specification has been extended to support the complex alignment features of long-read sequencing technologies like PacBio and Oxford Nanopore.
- = (Sequence Match): An exact base-for-base match, providing finer resolution than the generic M operator.
- X (Sequence Mismatch): An explicit base substitution, allowing variant callers to immediately identify single nucleotide polymorphisms from the CIGAR string alone.
- P (Padding): A silent deletion from a padded reference, used in multiple sequence alignments where the reference has been artificially extended.
Using = and X instead of M transforms the CIGAR string from a coarse alignment summary into a precise edit transcript, enabling rapid variant identification without re-examining the base-level alignments.
CIGAR in Variant Calling Pipelines
Variant callers like DeepVariant and GATK HaplotypeCaller rely heavily on the CIGAR string to construct pileup images and perform local reassembly.
- Pileup Generation: The CIGAR string dictates which read bases are stacked at each reference position. Insertions (I) cause extra bases to be placed between reference columns, while deletions (D) create gaps.
- Indel Realignment: Regions with clusters of I and D operations indicate potential misalignments around true indels. Tools perform local reassembly to resolve these regions.
- Strand Bias Detection: Comparing the CIGAR operations from forward-strand reads versus reverse-strand reads at a locus can reveal systematic sequencing artifacts.
A malformed CIGAR string that violates consumption rules will cause pipeline failures, making strict validation a critical preprocessing step.
CIGAR vs. MD Tag
The CIGAR string is often paired with the optional MD tag in SAM/BAM files to provide a complete picture of the alignment.
- CIGAR String: Encodes the operations (match, insert, delete) but does not, by default, specify the reference bases that were mismatched.
- MD Tag: A string that encodes the reference bases for mismatches and deletions. For example,
MD:Z:10A5^C3indicates 10 matches, a mismatch to 'A', 5 matches, a deletion of 'C', and 3 matches.
Together, the CIGAR string and MD tag allow a tool to perfectly reconstruct the reference sequence at the aligned locus without accessing the full reference genome file, which is critical for the high-speed operation of variant callers and alignment viewers.
Frequently Asked Questions
Clear, technically precise answers to the most common questions about the CIGAR string, its syntax, and its critical role in genomic sequence alignment.
A CIGAR string (Compact Idiosyncratic Gapped Alignment Report) is a compact, standardized representation within Sequence Alignment/Map (SAM) and Binary Alignment/Map (BAM) files that summarizes the sequence of operations required to align a sequencing read to a reference genome. It encodes the exact pattern of matches (M), insertions (I), deletions (D), skipped regions (N), soft-clipping (S), and hard-clipping (H) as a series of paired length-and-operator values. For example, the string 150M indicates a perfect 150-base-pair match, while 20M2I128M describes a read where 20 bases match, 2 bases are inserted relative to the reference, and then 128 more bases match. The CIGAR string is essential for variant calling because it precisely defines the alignment's edit distance and allows tools like DeepVariant to reconstruct the read's sequence at each genomic position.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
The CIGAR string is the operational core of read alignment. Master these adjacent concepts to fully understand how alignment information is stored, manipulated, and utilized in variant calling pipelines.
Mapping Quality Filtering
The process of discarding reads with a low probability of correct alignment before variant calling. The MAPQ field in SAM/BAM files is a Phred-scaled probability that the read is misaligned. A MAPQ of 30 corresponds to a 1/1000 chance of error. Filtering on MAPQ removes reads with ambiguous CIGAR strings that would otherwise introduce false positive variant calls due to mismapping in repetitive regions.
Neural Pileup Representation
A method of encoding the vertical stack of aligned reads at a candidate locus into a multi-channel tensor for direct input into a convolutional neural network. Unlike traditional variant callers that parse CIGAR strings to count alleles, neural pileup representations preserve the spatial arrangement of reads, base qualities, strand information, and CIGAR-derived alignment features as distinct image channels, enabling the model to learn complex error patterns.
Local Reassembly
A targeted computational method that performs de novo assembly of reads mapping to a specific region to resolve complex variants. When CIGAR strings indicate multiple overlapping indels or soft-clipped reads that suggest a structural rearrangement, local reassembly constructs a consensus sequence from the reads themselves rather than forcing alignment to the reference. This resolves haplotypes that cannot be represented by a simple CIGAR string.
Homopolymer Indel Error
A systematic sequencing error where the true number of consecutive identical bases is miscounted, leading to false insertion or deletion calls. In CIGAR strings, this manifests as incorrect indel operation lengths in homopolymer runs (e.g., AAAAAA). The error arises from signal phasing issues in sequencing-by-synthesis platforms and is a major source of false positive indels that variant callers must model and correct.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us