A Sequence Alignment Map (SAM) file is a tab-delimited text format for storing nucleotide sequences aligned against a reference genome. Each alignment line contains 11 mandatory fields recording the read name, bitwise flag, reference position, mapping quality, and a CIGAR string that compactly encodes the alignment's match, insertion, and deletion operations.
Glossary
Sequence Alignment Map (SAM)

What is Sequence Alignment Map (SAM)?
The Sequence Alignment Map (SAM) format is a tab-delimited text format for storing biological sequences aligned to a reference genome.
The format also stores the aligned read sequence and per-base quality scores, enabling variant detection and visualization. While human-readable, SAM files are voluminous; the compressed binary equivalent, BAM, provides efficient storage and random access. SAM serves as the universal interchange format between short-read aligners like BWA and downstream analysis tools.
Frequently Asked Questions
Clear, technical answers to common questions about the SAM format, its structure, and its role in genomic variant discovery pipelines.
A Sequence Alignment Map (SAM) file is a tab-delimited text format for storing biological sequences aligned to a reference genome. It consists of a header section containing metadata and a reference sequence dictionary, followed by an alignment section where each line represents a single sequencing read's alignment. Each alignment record contains 11 mandatory fields including the read name (QNAME), a bitwise flag (FLAG), the reference sequence name (RNAME), the 1-based leftmost mapping position (POS), a mapping quality score (MAPQ), a compact CIGAR string describing the alignment, and the read sequence and quality scores. The format was defined by the SAM/BAM specification maintained by the SAMtools community and serves as the universal interchange format between alignment algorithms and downstream analysis tools like variant callers.
SAM vs BAM vs CRAM: Format Comparison
A technical comparison of the three primary formats for storing biological sequence alignment data, from uncompressed text to reference-based compression.
| Feature | SAM | BAM | CRAM |
|---|---|---|---|
Full Name | Sequence Alignment Map | Binary Alignment Map | Compressed Reference-oriented Alignment Map |
File Type | Tab-delimited text | Binary (BGZF compressed) | Binary (custom block compression) |
Human Readable | |||
Indexed Random Access | |||
Compression Ratio vs SAM | 1:1 (baseline) | 3-5:1 | 10-30:1 |
Reference Genome Required for Decompression | |||
Lossless Read Sequence Storage | |||
Primary Use Case | Pipeline debugging, manual inspection | Production storage, variant calling input | Long-term archival, large cohort storage |
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.
Key Features of the SAM Format
The SAM format is the universal currency of aligned sequencing data. Its design balances human readability with a compact, machine-parseable structure for storing nucleotide sequences aligned to a reference genome.
11 Mandatory Alignment Fields
Each alignment line consists of 11 tab-delimited fields, providing a complete description of a read's placement. Key fields include:
- QNAME: The query template name, linking paired reads.
- FLAG: A bitwise flag encoding properties like read paired, mapped in proper pair, and strand.
- RNAME and POS: The reference sequence name and 1-based leftmost mapping position.
- MAPQ: The Mapping Quality score, a Phred-scaled probability that the alignment is incorrect.
- CIGAR: A compact idiosyncratic gapped alignment report string summarizing matches, insertions, deletions, and clipping operations.
- SEQ and QUAL: The original read sequence and its per-base quality scores.
Bitwise FLAG Decoding
The second field in a SAM record is a single integer that encodes up to 12 binary properties of the read alignment. This bitwise FLAG is the sum of individual flags, each a power of 2. For example, a read that is paired (0x1), mapped in a proper pair (0x2), and is the first mate (0x40) has a FLAG of 99. Common flags include:
- 0x4: Segment unmapped
- 0x8: Next segment unmapped
- 0x10: Read reverse strand
- 0x400: Read is a PCR or optical duplicate Decoding the FLAG is essential for filtering reads by strand, mapping status, or duplicate designation.
CIGAR String Operations
The CIGAR string is a compact representation of the alignment's fine-grained structure. It alternates between integer lengths and single-letter operation codes. Core operations include:
- M: Alignment match (can be a sequence match or mismatch)
- I: Insertion in the read relative to the reference
- D: Deletion from the reference
- N: Skipped region on the reference (intron)
- S: Soft clipping (bases at read ends not aligned but present in SEQ)
- H: Hard clipping (bases removed from SEQ)
A CIGAR of
150Mindicates a perfect 150bp match, while50M1I99Mdescribes a single-base insertion at position 51.
Optional Tags for Rich Metadata
Beyond the 11 mandatory fields, SAM records carry optional key-value tags in the format TAG:TYPE:VALUE. These tags store platform-specific and analysis-derived metadata. Critical tags include:
- NM:i: Edit distance to the reference, counting mismatches and indels.
- MD:Z: A string detailing mismatching positions and deleted reference bases, used for variant discovery.
- AS:i: Alignment score from the aligner.
- RG:Z: The read group identifier, linking back to the header's @RG record.
- X? and Y?: Reserved prefixes for end-user or tool-specific annotations.
Paired-End Mate Coordination
SAM natively handles paired-end sequencing by storing each mate on a separate line, linked by a shared QNAME. The FLAG field distinguishes the first mate (0x40) from the second (0x80). Fields RNEXT, PNEXT, and TLEN describe the mate's alignment. RNEXT is the mate's reference name (= if same chromosome), PNEXT is its 1-based position, and TLEN is the observed template length—the signed distance between the outermost mapped bases. A negative TLEN indicates the second mate maps to the reverse strand, enabling structural variant detection through insert size discordance.

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