DNA base encoder
Write a word and see it as DNA letters: Hi becomes CAGACGGC, four bases per byte, because every pair of bits maps to A, C, G or T. Paste a sequence to turn it back into text. Free in your browser.
- Free
- Runs in your browser
- No sign-up
- Your data stays on your device
Run — free
Worked example
- Text
- Hi
- Calculation mode
- Encode
- Result
- CAGACGGC
- Input
- Hi
- Dna
- CAGACGGC
- Groups
- CAGA, CGGC
A DNA base encoder turns ordinary text into a string of the four biological bases adenine, cytosine, guanine, and thymine by treating each pair of bits as one letter of that alphabet, and a DNA decoder reverses the same table so you recover the original UTF-8 string. Enter plain text and choose encode to receive a continuous A/C/G/T sequence—four bases per byte—or paste a DNA string and choose decode to rebuild the characters.
How bit pairs become DNA bases and why length must be a multiple of four
Digital text is a sequence of bytes, and each byte is eight bits. This encoder groups those bits into pairs and maps every pair to exactly one DNA base using a fixed table: zero-zero becomes A, zero-one becomes C, one-zero becomes G, and one-one becomes T. Walking a byte from the most significant bit pair down to the least significant pair therefore always produces four letters.
The capital letter H has decimal value seventy-two, binary zero-one-zero-zero-one-zero-zero-zero, which becomes C, A, G, A; the letter i becomes C, G, G, C; together the word Hi encodes as CAGACGGC. Decoding reads the sequence four bases at a time, expands each base back to its two-bit code, rebuilds each byte, and interprets the byte array as UTF-8. Because one full byte always needs four bases, a sequence whose length is not a multiple of four cannot represent an integer number of bytes and is rejected.
Likewise, any character that is not A, C, G, or T—including U, N, digits, and punctuation—is invalid. Whitespace, commas, hyphens, and similar separators are stripped before validation so pasted FASTA-style fragments still work when they only contain legal bases. Multi-byte UTF-8 characters such as accented letters or emoji expand to more than one byte and therefore more than four bases; that is expected, not an error.
This landing targets people searching for a DNA base encoder, text to DNA converter, or A/C/G/T binary packing tool; it is not a biological sequence aligner, codon table, or reverse-complement calculator.
What you can do with it
Homework checks for information-theory DNA codes
Students encode short phrases, compare hand-written A/C/G/T strings to the deterministic result, and decode teacher-provided sequences without a spreadsheet.
Classroom demos of four-letter digital packing
Workshops show how printable labels become DNA bases two bits at a time, then force invalid letters or odd lengths to illustrate strict validation.
FAQ
What mapping does the DNA base encoder use?
Each pair of bits maps to one base: 00→A, 01→C, 10→G, 11→T. Bits are taken most-significant-first within each UTF-8 byte, so every byte becomes exactly four bases.
Are lowercase bases and spaces allowed?
Yes on decode. Bases are uppercased and whitespace or common separators (commas, hyphens, pipes) are stripped before validation. Encode always returns continuous uppercase DNA.
Does it support UTF-8 and emoji?
Yes. Encoding uses UTF-8, so multi-byte characters become multiple four-base groups. Decoding rejects byte sequences that are not valid UTF-8.
Is the DNA base encoder free?
The browser tool is free and runs locally.
Why must a DNA sequence have a multiple of four bases to decode?
Because one byte of text always takes exactly four bases, two bits each. A sequence of, say, seven bases cannot form whole bytes, so it is rejected instead of being padded or guessed.
Related tools
For developers — API access
Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.
API endpoint
Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/enc/dna-encode \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"text":"Hi"}'const res = await fetch("https://api.kit.forhosting.com/enc/dna-encode", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"text": "Hi"
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/enc/dna-encode",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"text": "Hi"
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/enc/dna-encode", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"text":"Hi"}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"text":"Hi"}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/enc/dna-encode", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"text": "Hi"
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "enc.dna_encode",
"status": "queued",
"_links": {
"result": "/tasks/tsk_…/result"
}
}The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Limits
max_chars | 100000 |
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |
Technical notes
Sequences that contain letters outside A, C, G, and T, or whose length is not a multiple of four, return a clear invalid_input error instead of inventing padding or silent substitutions.
How to call the API and what the response contains
The default mode is encode: the UTF-8 bytes of text become a continuous uppercase DNA string. Mode decode treats text as a DNA sequence—optionally with whitespace or common separators—and returns the recovered UTF-8 string after stripping separators, uppercasing bases, and validating the alphabet and length. On success for decode, the response includes mode, input, result and text with the decoded UTF-8 string, dna normalized to a continuous uppercase sequence, the same groups and bytes arrays, counts, mapping, and a matching message. Send a JSON body with a required string field text (aliases input, value, data, and sequence) and an optional mode that is either encode or decode. Input length is capped at one hundred thousand characters so a single request cannot exhaust Worker memory on huge strings. On success for encode, the response includes mode, input, result and dna with the same base string, groups as an array of four-base chunks (one per byte), bytes as the integer byte values, byte_count, base_count, bit_count, the mapping legend, and a short English message. Failed validation—missing text, non-string text, oversize input, an unknown mode, a non-base character, a length that is not a multiple of four, or decoded bytes that are not valid UTF-8—returns invalid_input and is never charged. Pricing is a flat $0.002 per successful request with unit item.
Practical tips, limits, and related tools
Round-trip checks are the fastest smoke test: encode a short word such as Hi, confirm the eight bases match the known four-base groups for H and i, then decode those bases and confirm you recover the original string. Prefer this capability when the search intent is text or binary versus DNA bases with a two-bit packing table; use a binary or hex text converter when you need zero-one or hexadecimal forms instead of A/C/G/T. When teaching, show the same emoji or accented letter next to a plain ASCII letter so students see multi-byte UTF-8 octets appear as extra four-base groups rather than a single mystery codon. Prefer decode when you already hold an A/C/G/T string from a textbook or a generated payload and want the characters back. Deliberately submit a three-base fragment or a string containing X or U to assert that your client handles invalid_input and the error message that names the alphabet or the multiple-of-four rule. Keep payloads under the published character limit; multi-megabyte dumps belong offline. This tool is not a biological reverse-complement utility, not a codon translator, and not a general base-4 number converter for arbitrary integers—those problems deserve dedicated pages. Failed tasks that return invalid_input do not consume prepaid balance, which keeps exploratory scripts cheap when learners paste incomplete sequences.
Integration use cases
Unit-test fixtures for synthetic data formats
Generate known DNA-style strings from fixture text and assert decode recovers the same UTF-8 bytes in CI without ad-hoc bit packing helpers.
Technical questions
Why must the DNA sequence length be a multiple of four?
Four bases hold eight bits—one full byte. A length that is not a multiple of four cannot represent complete bytes, so decode returns invalid_input instead of padding.