how-to · 5 min read
How to calculate GC content from a sequence
GC content is the percentage of a nucleotide sequence made up of guanine and cytosine. It is one of the simplest sequence statistics to calculate and one of the easiest to get subtly wrong, because the clean percentage depends on which bases are counted in the denominator and how the input was formatted.
This guide gives the formula, explains how DNA and RNA change it, shows a worked example with an ambiguity code, and covers the normalization and cleaning steps that a GC content calculator should do for you.
The GC content formula
For a DNA sequence, GC content is (G + C) divided by (A + T + G + C), multiplied by 100. The denominator is every unambiguous base in the sequence, not the number of characters in the pasted text and not the sequence length including ambiguity codes. Stated as a formula, GC% = (G + C) / (A + T + G + C) × 100.
The result is a proportion expressed as a percentage, so a sequence with equal numbers of G and C bases and no other bases would give 100%, while a sequence of only A and T would give 0%. Most real sequences fall somewhere in between, and the number is only meaningful alongside the count of bases that produced it.
DNA and RNA: T and U change the denominator
RNA uses uracil in place of thymine, so the RNA version of the formula is (G + C) / (A + U + G + C) × 100. The numerator is unchanged, because guanine and cytosine are the same in both molecules. What changes is which fourth base contributes to the denominator.
If a sequence contains both T and U, it is not a normal single strand, so treat that as a warning rather than choosing one denominator silently. A calculator should report the molecule it detected and state the exact denominator it used, which is the only way to compare two GC values honestly.
Worked example: ATGCGCNN
Take the short sequence ATGCGCNN. It has eight letters, but two of them are N, an ambiguity code that does not identify a base. Removing the Ns leaves six unambiguous bases: one A, one T, two Gs and two Cs. The GC numerator is 2 + 2 = 4, and the denominator is 6, so GC content is 4/6 × 100 = 66.7%.
Compare that with counting all eight letters and treating the Ns as non-GC: 4/8 would give 50%. The difference is not a rounding detail, it is a different question. The first answer describes the known bases, the second treats unknown positions as if they were known not to be G or C. Reporting the denominator resolves the ambiguity.
Why ambiguity codes are handled separately
Ambiguity codes such as N, R, Y, S, W, K, M, B, D, H and V describe sets of possible bases. N means any base, R means a purine (A or G), Y means a pyrimidine (C or T), and the others encode partial information. A code like R might hide a G, which would raise the GC content, so counting it as GC would overstate the result and counting it as non-GC would understate it.
The most defensible approach is to exclude ambiguity codes from both the numerator and the denominator, then report how many there were and list the codes found. A sequence with many Ns can then be recognized as having a GC percentage based on very few known bases, which is a different level of confidence from a percentage over thousands of unambiguous bases.
Cleaning a FASTA record before counting
Sequence data rarely arrives as a bare string. A FASTA record has a header line beginning with >, the sequence may be wrapped across many lines, and pasted output often contains spaces or position numbers. None of those characters is a base, so counting the raw text would produce a wrong denominator.
A proper calculation strips header and comment lines, removes whitespace, digits and punctuation, uppercases the remaining letters, and then counts. If several records are pasted together, their sequences are usually concatenated by this kind of cleaning, so per-record GC content requires analyzing one record at a time or using software that keeps records separate.
What GC content tells you and what it does not
GC content is a compact summary of base composition. It is used to compare sequences and regions, to check that a primer or amplicon has the expected composition, and as one input when thinking about duplex stability, because G-C pairs have three hydrogen bonds and A-T or A-U pairs have two. That gives a qualitative trend, not a melting temperature: the actual stability also depends on length, salt, mismatches and sequence context.
GC content does not identify an organism, a gene or a function, and it does not tell you whether the molecule is DNA or RNA; the presence of T or U does that. Short sequences give noisy percentages, sequences with many ambiguity codes give low-confidence ones, and values from different samples are only comparable when they were counted the same way. Reporting the percentage, the denominator and the ambiguity count together keeps the number honest.