character encoding (ASCII and Unicode)
/ ASCII = ASS-kee /
Computers only store numbers, so to store text every character must be assigned a number — a code. A character encoding is the agreed-upon dictionary that maps each letter, digit, and symbol to a specific number (and back). It is exactly like a codebook where 'A' means 65, 'B' means 66, and so on; as long as the writer and the reader use the same codebook, text survives the trip through the all-numbers machine intact.
The original widely-used codebook is ASCII, which assigns the numbers 0 to 127 to the English letters, digits, punctuation, and a few control codes, fitting each character in 7 bits (one byte with a spare). So 'A' is 65 (0x41) and 'a' is 97 (0x61). ASCII works beautifully for English but has no room for accented letters, Chinese, Arabic, emoji, or the thousands of other characters the world uses. Unicode solves that by giving every character in essentially every writing system its own unique number, called a code point — over a million possible, with U+0041 for 'A' and U+4E2D for the Chinese character 中. Unicode is the giant catalogue of which character gets which number; it does not, by itself, say how to store those numbers as bytes.
That storage job belongs to an encoding form, and the dominant one is UTF-8. UTF-8 is clever: it uses a single byte for the original ASCII characters (so any plain-English text is automatically valid UTF-8), and two, three, or four bytes for everything else. This backward compatibility is why UTF-8 took over the web. The honest pitfalls are real and common: a character is no longer always one byte, so counting bytes is not counting characters; and if text is written with one encoding but read with another, you get mojibake — garbled symbols where readable text should be. Always knowing and matching the encoding of your text is a genuine, recurring source of bugs.
In ASCII, 'A' is 65 (0x41) and 'a' is 97 (0x61). In Unicode the Chinese character 中 is code point U+4E2D, which UTF-8 stores as the three bytes 0xE4 0xB8 0xAD — so that one character is one code point but three bytes.
ASCII covers English in one byte; Unicode names every character; UTF-8 stores them in 1 to 4 bytes.
In UTF-8 one character is not always one byte, so byte count is not character count. Reading text with the wrong encoding produces mojibake — garbled output — a frequent, real source of bugs.