Format Atlas

Compare

SAM vs BAM

SAM and BAM represent the same alignment information. SAM is TAB-delimited text; BAM is binary encoded in BGZF blocks.

Which format should you choose?

Consider SAM for inspection and debugging, and BAM for storage and region queries in compatible analysis tools.

Good fit for SAM

Exchanging sequencing reads and reference-alignment information as text · Inspecting headers and records while handing analysis results between tools

  • Reviewing reference names, lengths, flags, CIGAR, MAPQ, sequence, quality, and tags
  • Keeping readable records for debugging or small data checks

Good fit for BAM

Storing and exchanging large read-alignment datasets in binary form · Querying coordinate-sorted data by region with an index

  • Compressing SAM-compatible headers, records, and tags
  • Using BGZF and BAI/CSI indexes with compatible tools

Basic information

FieldSAMBAM
Extension.sam.bam
MIME typetext/plainapplication/octet-stream
Common usesExchanging sequencing reads and reference-alignment information as text · Inspecting headers and records while handing analysis results between toolsStoring and exchanging large read-alignment datasets in binary form · Querying coordinate-sorted data by region with an index
How to openUse SAM-aware software or a text editor. Check headers such as `@HD`, `@SQ`, `@RG`, and `@PG`, the eleven required columns, FLAG bits, reference coordinates, CIGAR, MAPQ, SEQ/QUAL, and optional tags. Avoid spreadsheet operations that reorder rows or alter tabs.Use SAM/BAM-aware software. Check header reference names, lengths and identifiers, sort order, read and unmapped counts, FLAG/CIGAR, qualities, and tags. For regional access, use a BAI/CSI index made for that exact BAM and its sorting state.
Export or convertWhen converting SAM to BAM, verify headers, flags, CIGAR, qualities, tags, and ordering. Coordinate-sorted BAM may be indexed according to the tool's requirements. Producing SAM from FASTQ requires a reference and an alignment workflow; it is not a simple format conversion.Converting BAM to SAM makes records readable but may greatly increase size. When converting SAM back to BAM, validate fields, tags, and order. CRAM conversion can depend on reference sequences and quality-preservation settings; retain the needed references.

Choose by use case

Reviewing reference names, lengths, flags, CIGAR, MAPQ, sequence, quality, and tags

Exchanging sequencing reads and reference-alignment information as text · Inspecting headers and records while handing analysis results between tools

SAM

Keeping readable records for debugging or small data checks

Exchanging sequencing reads and reference-alignment information as text · Inspecting headers and records while handing analysis results between tools

SAM

Compressing SAM-compatible headers, records, and tags

Storing and exchanging large read-alignment datasets in binary form · Querying coordinate-sorted data by region with an index

BAM

Using BGZF and BAI/CSI indexes with compatible tools

Storing and exchanging large read-alignment datasets in binary form · Querying coordinate-sorted data by region with an index

BAM

Key point 1

SAM can be inspected with text tools.

More on the differences

Key point 2

BAM requires a compatible decoder.

More on the differences

More on the differences

Conversion alone does not sort or index a file. Coordinate-sort and create the required BAI/CSI index for the receiving workflow.

  • FLAG, CIGAR, MAPQ and optional tags carry defined meanings. Editing SAM as an ordinary table can break consistency with records and reference dictionaries.
  • BAM's BGZF should not be treated as ordinary gzip. Region queries need the appropriate index and coordinate-sorted data.

Frequently asked questions

Does BAM improve mapping accuracy?

No. Changing representation does not realign reads. Compare record counts, reference dictionaries, tags and quality values, and check conversion filters.

Learn more

Related uses and checks

Choosing Sequencing Files by Workflow

References and specifications