System Design · Concept Library · Free article
Bits and Bytes: Inside One Machine
Start with no computing background. Build a byte, represent a message, and find out why a buffer can run out of room.
A bit is a 0 or a 1. One byte contains eight bits, giving 256 possible patterns. A computer stores and moves patterns of bits. A representation gives those patterns meaning: a number, some text, or an instruction. Before a message can fit in memory, you need to know how many bytes its representation needs. Counting visible letters is not enough.
What happens inside one machine?
Imagine typing a short greeting into a program and asking it to show the greeting again. A program is a set of instructions for a computer to follow. The greeting is data, the information those instructions work on. Neither arrives inside the machine as tiny printed letters. Both need a physical representation the machine can store and use.
The CPU, or central processing unit, carries out instructions, such as adding two numbers or copying a value. Memory holds information the running program needs. RAM, random-access memory, is the machine’s working memory: locations can be accessed by address, without reading every earlier location first. Ordinary main RAM needs power to retain its contents. Storage, such as an SSD, is used to retain data across power loss. A safe saved write also requires the system to finish the work needed to retain that data.
An address identifies a memory location. Think of numbered compartments: the number tells you where to look, and the contents tell you what is there. This is an introduction to the roles, not a claim that every compartment is a physical box. A register is a small storage location within a processor, used directly during instruction execution. A core is an execution unit within a CPU. These parts operate on represented data, so we begin with the data itself.
One bit, then eight
A bit, short for binary digit, has two possible values: 0 and 1. Hardware represents those values using distinguishable physical states. We can reason about the values without first studying the electronics.
One bit distinguishes two possibilities. Two bits distinguish four: 00, 01, 10, 11. Adding a bit doubles the number of possible patterns. Eight bits give 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 256 possible patterns. Those eight bits make one byte, not eight bytes. The number 256 tells us how many different values that single byte can represent; it does not count how many bits it contains.
The abbreviation B means byte; lowercase b means bit. An 8 B buffer has room for eight bytes. Each byte contains eight bits, so its capacity is 8 bytes × 8 bits per byte = 64 bits. To compare the two calculations: 2⁸ counts the possible patterns in one byte; 8 × 8 counts the bits in eight bytes.
In the decimal numbers you already use, moving one place left multiplies a digit’s weight by ten. In binary, it multiplies the weight by two. For an eight-bit unsigned number, the weights from left to right are 128, 64, 32, 16, 8, 4, 2 and 1. Add the weights of positions holding a 1. For 01000111, that is 64 + 4 + 2 + 1 = 71.
0 1 0 0 0 1 1 1
Try making 72 before looking at the answer. It needs 64 + 8, so its bits are 01001000. The decimal value changed by one, but several bits changed. The computer is manipulating a pattern; our notation helps us understand it.
Hexadecimal, usually shortened to hex, is a more compact way to write those patterns. It uses sixteen digits: 0 through 9, then A through F for ten through fifteen. Four bits have sixteen possibilities, so each group of four bits maps to one hex digit. Split 01000111 into 0100 and 0111: that is hex 47. The prefix in 0x47 says “read this as hexadecimal,” not decimal forty-seven. Two hex digits describe one byte. Hex does not compress the stored data; it shortens the way we write it.
The same bits can mean different things
The pattern 01000111 can mean the unsigned number 71. Under the ASCII text convention, it represents the letter G. The bits alone do not declare which interpretation you intended. A program must use an agreed representation, the rule for turning a value into bits and interpreting those bits again.
An unsigned integer is a whole number that cannot be negative. With eight bits, its 256 patterns represent 0 through 255. Notice the final value is 255, not 256: zero already uses a pattern. With sixteen bits, the unsigned range is 0 through 65,535. In general, n unsigned bits represent 0 through 2ⁿ − 1.
A signed integer includes negative values. This workshop uses two’s complement, a common signed representation. Its leftmost bit has a negative weight. For eight bits the weights are −128, 64, 32, 16, 8, 4, 2 and 1. Now 11111111 means −128 + 127 = −1, while 10000000 means −128. The range is −128 through 127. The same 256 patterns have been divided between negative and nonnegative values. Choosing signedness changes their interpretation, not the number of bits.
| Width | Unsigned | Signed, two’s complement |
|---|---|---|
| 8 bits / 1 B | 0 to 255 | −128 to 127 |
| 16 bits / 2 B | 0 to 65,535 | −32,768 to 32,767 |
| 32 bits / 4 B | 0 to 4,294,967,295 | −2,147,483,648 to 2,147,483,647 |
What happens if you ask an eight-bit unsigned representation to hold 256? The value is outside its range. This is an overflow. The workshop offers three explicit policies: reject refuses the conversion, wrap keeps the value modulo 256 so 256 becomes 0, and saturate clamps it to the nearest boundary so 256 becomes 255. Wrapping and saturation produce bytes, but neither preserves 256. Actual language and hardware behavior depends on the operation and type; these are selectable model policies.
For a counter that must retain 256, choose more bits. In the workshop’s sixteen-bit, most-significant-byte-first format, 256 is 01 00 in hex: one group of 256, plus zero. That byte order is called big-endian. Little-endian would put the lower-valued byte first, 00 01. A receiver must know the agreed order. This lesson’s model uses big-endian integers throughout.
How a greeting becomes bytes
Encoding converts a value into its chosen representation. Decoding interprets the representation to recover a value. ASCII, the American Standard Code for Information Interchange, assigns values 0 through 127 to a limited set of letters, digits, punctuation and control characters. Its seven-bit codes fit in one eight-bit byte. It includes G, but it does not include 🐐.
Unicode provides code points, numbered entries used to represent text from many writing systems and symbols. A code point is written with U+ followed by a hexadecimal number. G is U+0047; 🐐 is U+1F410. Unicode is not a promise that every character occupies one byte.
UTF-8, a Unicode Transformation Format, encodes a Unicode scalar value in one to four bytes. A scalar value is a code point excluding the surrogate range reserved for UTF-16 encoding. ASCII characters keep their one-byte values. The goat symbol takes four bytes: F0 9F 90 90. A code unit is the basic unit an encoding uses. The “8” names UTF-8’s eight-bit code unit; it does not mean every symbol takes eight bits. Unicode’s encoding FAQ explains the distinction.
A code point and a symbol you see on screen are not always the same unit. Some displayed symbols combine multiple code points, such as a letter and a combining accent. For this particular greeting, G, O, A, T, the space and 🐐 are six code points. The encoded size is nine bytes.
| Text | Hex bytes | Bytes needed |
|---|---|---|
| G | 47 | 1 |
| O | 4F | 1 |
| A | 41 | 1 |
| T | 54 | 1 |
| Space | 20 | 1 |
| 🐐 | F0 9F 90 90 | 4 |
| Total | 47 4F 41 54 20 F0 9F 90 90 | 9 |
Give the bytes somewhere to wait
A buffer is an area reserved to hold data temporarily while work moves between stages. Its capacity is how much it can hold. Its occupancy is how much space is currently in use. A capacity of twelve bytes does not mean twelve bytes are always occupied.
A record here is one complete value being transferred, such as the whole greeting. The workshop’s buffer must hold the entire encoded record before forwarding it. This is a deliberate model rule. Other systems can process a stream in smaller pieces; that requires different rules about partial input and when space is released.
Our nine-byte greeting cannot fit in the starter’s eight-byte buffer. The first eight bytes can be staged, but byte nine has no space. This model rejects the entire record and releases its staged space. It does not forward a shortened greeting. A twelve-byte buffer can stage all nine bytes, forward them, then make that space available again. Nothing about increasing the buffer changes the encoding.
Predict, run, repair
- Before running, predict what will happen with the starter’s 8 B buffer.
- Run the machine. Open Evidence and select the rejection event. In Inspect, examine the staged bytes and the missing ninth byte.
- In Compare, pin the completed run. Change the buffer to 12 B in Inspect, then run again. Compare the output and delivered byte count.
- Try 16 B. The record fits, but the challenge limits total memory to 12 B. Explain why completing a run and meeting every requirement are different.
Open the record workshop to build, run and inspect the byte-flow machine. The interactive controls need JavaScript.
Build a different design
Switch to “Free experiment” to edit the source freely. Try the ASCII message Hi! and a three-byte buffer. Run it, then replace the buffer with your own buffer component. Connect Representation to the new buffer and the new buffer to Output by dragging between their canvas ports. Delete the old buffer. The new topology should deliver the same record.
Now place two three-byte buffers in sequence. Each has room for the whole record, and the record should arrive once, after passing through both. However, the machine now reserves six bytes of total buffer capacity. Switch to “Three bytes, no spare room” if you want the explicit three-byte challenge. It checks the outcome and budget rather than requiring a particular component identifier.
Two buffers holding smaller pieces do not automatically act as one larger buffer. In this model, each buffer stages the complete record. Splitting the greeting across parallel paths requires rules for dividing the record and reassembling it at the destination. Connecting two buffers does not supply those rules.
Finally, try “One count too many.” Keep 256 unchanged within a four-byte memory budget. Compare reject, wrap and saturate at eight bits, then choose sixteen bits. Use the output value as your evidence; “some bytes arrived” is too weak a requirement.
Count every part of a record
A field is one part of a record, such as a count or a message. To budget a record with several fields, add their encoded sizes. Consider this worked example, with no padding or headers:
| Field | Representation | Size |
|---|---|---|
| Count: 256 | Unsigned 16-bit integer | 2 bytes |
| Message: GOAT 🐐 | UTF-8 | 9 bytes |
| Complete record | Count followed by message | 11 bytes |
A ten-byte buffer is one byte short. If a system keeps only the first ten bytes, it cuts off the emoji’s final byte. This is truncation, and strict UTF-8 decoding refuses the incomplete character. The workshop’s buffer instead rejects a record that cannot fit. Real record formats may also need headers or padding; count those bytes too.
Use the existing Inspect controls to explore the two constraints separately: change Buffer capacity for the greeting, then choose “One count too many” and change Field width in Representation. More buffer space cannot make 256 fit in eight unsigned bits. The representation must preserve the value before the buffer can preserve its bytes.
Scale up without mixing units
An application may work with millions of bytes instead of nine. kB is 1,000 B and MB is 1,000,000 B. KiB, kibibyte, is 1,024 B, and MiB, mebibyte, is 1,048,576 B. The binary prefixes name powers of two explicitly. NIST lists the definitions.
A 1 KiB buffer can hold at most 113 separate nine-byte records if every byte is available for record data: 113 × 9 = 1,017, leaving seven bytes. A 1 kB buffer holds at most 111 under the same assumptions. Real buffers can also need metadata or alignment space. State those assumptions before turning a byte count into a capacity promise. This workshop counts record bytes and configured buffer capacity only.
Keep size separate from speed. Bytes describe how much information is represented. Bytes per second describe a rate. This workshop’s ticks expose ordering; they do not tell you how fast a real CPU, RAM module or network will be.
Explain it without the controls
Try answering before reading the explanations
- A friend says “six characters need six bytes.” How would you test that claim?
- Ask which encoding and which text. For GOAT 🐐, count five one-byte UTF-8 entries including the space, then four bytes for the goat: nine. In general, visible symbols, code points and bytes are different counts.
- Why does changing 8 B to 12 B fix the greeting, but not an unsigned 8-bit counter holding 256?
- The greeting’s representation is valid but lacks staging space. The counter cannot be represented unchanged in eight unsigned bits. More downstream memory does not add patterns to that integer representation; increase its bit width.
- Would two 6 B buffers in sequence deliver the nine-byte greeting?
- No. The first buffer cannot stage the whole record. Total capacity is twelve bytes, but each buffer needs nine. This model has no mechanism to combine their partial capacity for one record.
- A run delivered the right value once, then hit the event limit. Can its final outcome be established?
- No. The unfinished work may still duplicate or reject records. The visible checks require complete execution before evaluating the final outcome.
Sources and model boundaries
- Unicode encoding FAQ: code points, encoding forms and UTF-8.
- ASCII specification, RFC 20: the seven-bit character code.
- NIST binary prefixes: decimal and binary units.
- The workshop’s whole-record staging, overflow policies, logical tick schedule and memory budget are declared teaching-model rules. They are not measurements of a physical machine.
By GOAT Engineer. Back to Concept Library. Privacy Policy · Contact.