FASTA and FASTQ Explained: Sequence Files and Phred Quality Scores
How FASTA stores sequences, how FASTQ adds a fourth line of per-base Phred quality, and why Q30 means 99.9% base-call accuracy.
Almost every bioinformatics pipeline starts with one of two plain-text file formats: FASTA or FASTQ. They look deceptively simple — just headers and letters — but understanding exactly what each line means, and how FASTQ smuggles a full quality score into a single printable character, will save you from a lot of confusing debugging later. This post walks through both formats line by line and works out the Phred math behind that mysterious fourth line.
What Is a FASTA File?
FASTA is the oldest and simplest sequence format still in everyday use. Each record has exactly two parts:
- A header line starting with
>, followed by an identifier and an optional free-text description. - One or more sequence lines containing the nucleotide or amino acid letters.
>NC_000913.3 Escherichia coli str. K-12 substr. MG1655, complete genome
AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGT
CTGATAGCAGCTTCTGAACTGGTTACCTGCCGTGAGTAAATTAAAATTTTATTGACTTAA few things worth internalizing about FASTA:
- The sequence can wrap across multiple lines (commonly 60 or 70 characters wide) or sit on a single long line — both are valid FASTA. Parsers must handle either.
- There is no quality information at all. FASTA tells you what the sequence is, never how confident the base calls are.
- A single file can hold many records back-to-back (a "multi-FASTA" file), which is exactly what a reference genome or a transcriptome file looks like.
- File extensions vary and are not part of the spec:
.fa,.fasta,.fna,.faa, and.ffnall describe FASTA-formatted content, sometimes distinguishing nucleotide from protein sequence by convention only.
FASTA is what you index a genome or transcriptome from, and it is the format salmon index consumes when you build a quantification index, as covered in the Salmon install guide.
What Is a FASTQ File?
FASTQ was designed for one job that FASTA cannot do: pairing every raw sequencing read with a per-base confidence score. It is the native output format of Illumina, Oxford Nanopore, and PacBio sequencers, and it is the starting point for essentially every alignment, quantification, or variant-calling pipeline.
The Four Lines of Every FASTQ Record
Every single read in a FASTQ file occupies exactly four lines, always in this order:
@SRR000001.1 071112_SLXA-EAS1_s_7:5:1:817:345 length=36
GGGTGATGGCCGCTGCCGATGAACTTCTCTCTCTAGAAG
+
IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII| Line | Symbol | Contents |
|---|---|---|
| 1 | @ | Read identifier plus optional description (instrument, flowcell, coordinates) |
| 2 | (none) | The raw sequence itself, one letter per base |
| 3 | + | A separator, optionally repeating the line-1 identifier |
| 4 | (none) | A quality string, exactly one character per base in line 2, in the same order |
That last constraint is the one that trips people up most: line 4 must be the same length as line 2, character for character. Each character in line 4 is not a letter grade — it is an ASCII-encoded number describing how confident the sequencer was about the base sitting directly above it in line 2. Unlike FASTA, a FASTQ sequence is never wrapped across multiple lines, because doing so would make it impossible to tell where the sequence ends and the quality string begins.
Phred Quality Scores: Turning Error Probability into a Number
The quality string in line 4 encodes a Phred quality score, a logarithmic scale that was originally developed for the Phred base-calling software used in Sanger sequencing and later adopted by every major sequencing platform. The formula is:
Q = -10 * log10(P_error)where P_error is the estimated probability that the base call is wrong. Rearranging it the other way, given a Phred score you can recover the error probability with:
P_error = 10^(-Q / 10)Because the scale is logarithmic, every 10-point increase in Q means the error probability drops by a factor of 10:
| Phred score (Q) | Error probability | Base-call accuracy |
|---|---|---|
| 10 | 1 in 10 | 90% |
| 20 | 1 in 100 | 99% |
| 30 | 1 in 1,000 | 99.9% |
| 40 | 1 in 10,000 | 99.99% |
This is where the widely quoted "Q30" benchmark comes from: a base with a Phred score of 30 has roughly a 1-in-1,000 chance of being an error, or 99.9% accuracy. Most Illumina QC reports and sequencing-core deliverables use "percent of bases above Q30" as their headline quality metric, and it is one of the first numbers a FastQC report will surface before you move on to alignment, as described in the RNA-seq differential expression guide. Q20 (99% accuracy) is generally treated as the bare minimum for usable data; anything much lower and you are looking at systematic sequencing or library-prep problems rather than normal background noise.
From Number to Letter: The Phred+33 ASCII Encoding
Writing a two-digit number after every single base would roughly triple the size of every FASTQ file, so instead each quality score is packed into one printable ASCII character. The scheme used by every modern platform (Illumina 1.8 and later, Nanopore, PacBio) is called Phred+33, sometimes referred to as the "Sanger" encoding:
ASCII character = chr(Q + 33)Adding 33 shifts the score past the first 33 ASCII codes, which include non-printable control characters and the space character, landing the encoded qualities in the range of printable, easy-to-read symbols. Decoding works the same way in reverse: take the character's ASCII decimal value and subtract 33.
| Character | ASCII decimal | Phred Q | Error probability |
|---|---|---|---|
! | 33 | 0 | 1.0 |
, | 44 | 11 | ~0.079 |
5 | 53 | 20 | 0.01 |
? | 63 | 30 | 0.001 |
I | 73 | 40 | 0.0001 |
So in the example record above, a quality character of I at every position means every base was called with Q40 — essentially maximum confidence, which is typical of a synthetic or lightly trimmed example. Real reads show a much more varied string, often trailing off into lower-quality characters toward the 3' end of the read as sequencing-by-synthesis chemistry degrades over the course of a run.
Two encoding pitfalls are worth flagging explicitly:
- Legacy Phred+64. Illumina pipeline versions 1.3 through 1.7 (roughly 2009–2011-era data) used an offset of 64 instead of 33. This data is extremely rare today, but if a modern tool throws nonsensical quality values or an "invalid quality" error on an old dataset, a mismatched offset is the first thing to check.
- Score ceiling. The printable ASCII range extends to
~(decimal 126), which allows Phred scores up to 93, but in practice most platforms cap reported quality around Q40–Q41, since claiming near-certain accuracy beyond that is not meaningfully supported by the underlying chemistry.
FASTA vs. FASTQ: When You'll See Each
| FASTA | FASTQ | |
|---|---|---|
| Lines per record | 2 (or more, if sequence wraps) | Always 4 |
| Quality scores | None | Yes, one Phred score per base |
| Typical source | Reference genomes, transcriptomes, protein databases | Raw reads straight off a sequencer |
| Typical use | Building an index, a BLAST database, a reference for alignment | Input to QC, trimming, alignment, or quantification |
| Common extensions | .fa, .fasta, .fna, .faa | .fq, .fastq (often gzipped as .fastq.gz) |
In short: if the file describes something you already trust to be correct — a published genome, a curated transcript set — it is almost always FASTA. If the file is what came directly out of a sequencing instrument, it is FASTQ, and that fourth line of quality scores is the whole reason the format exists. Downstream tools like SAMtools and BCFtools work with the aligned and compressed descendants of FASTQ data (BAM, CRAM, VCF), but the FASTQ file itself is almost always where a bioinformatics pipeline begins.
Key Takeaways
- FASTA is header-plus-sequence, with no quality information; FASTQ is always exactly 4 lines per read, adding a quality string the same length as the sequence.
- Phred quality follows
Q = -10 * log10(P_error): Q20 is 99% accuracy, Q30 is 99.9% accuracy, Q40 is 99.99% accuracy. - The quality string is ASCII-encoded with a
+33offset (Phred+33 / Sanger encoding) so each score fits in one printable character. - Watch for two gotchas: mismatched line-2/line-4 lengths, and rare legacy Phred+64 data from old Illumina pipelines.
- Before trusting any alignment or quantification result, check the percentage of bases at Q30 or above — it is the fastest sanity check on raw sequencing data quality.