The wire and the baud rate
UART sends bytes over one wire, the sender's TX to the receiver's RX, plus ground. There is no clock wire, so both ends must agree on a speed: the baud rate. On an Uno the PC reaches RX pin 0 through a USB chip.
The UART divides the 16 MHz clock. In double-speed mode the datasheet's rule is 16,000,000 ÷ (8 × (UBRR0 + 1)). UBRR0 = 207 gives 9,615 baud, 0.2% fast of 9,600: inside the 1.5% the receiver tolerates.
You type 'h'. It travels as 0x68 in a frame of 10 bits: a 0 start bit, eight data bits lowest first, then a 1 stop bit. Each bit lasts 1/9,615 s, so a byte takes 1.04 ms. The UART shifts it into UDR0.
Interrupt and ring buffer
Once the stop bit is in, the UART sets a flag and the RX interrupt fires: loop() pauses and the ISR runs. It reads UDR0 straight away. The chip holds only 2 received bytes, so the ISR must move each one out fast.
The ISR works out n = (head + 1) % 8 = 1. That is not tail (0), so there is room: buf[0] = 'h' and head becomes 1. head is where the next byte goes; tail is the next one to read.
'i' and the newline arrive 1.04 ms apart, and each runs the same ISR: buf[1] = 'i', buf[2] = '\n', head = 3. Bytes waiting = (8 + head − tail) % 8 = 3, the sum Arduino's Serial.available() does.
In loop(), head != tail means a byte is waiting. c = buf[tail] gives 'h' and tail moves on. Two more reads give 'i' and '\n'; now head == tail: empty. Only the ISR writes head and only loop() writes tail, so they never clash.
Next comes 'hello\n' while loop() reads. After slot 7, (7 + 1) % 8 = 0: head wraps back to slot 0, then 1. loop() has read 'h', 'e', 'l', so tail is 6. Waiting: (8 + 1 − 6) % 8 = 3.
When the ring is full
Now loop() sits in delay(100); about 96 bytes can arrive meanwhile. A 20-byte line comes: 4 free slots fill, then (head + 1) % 8 == tail, so the ISR drops the other 16 and counts them in lost.
Read often, and size the ring for the longest gap between reads. A byte lands every 1.04 ms, so if loop() can be away 20 ms, about 20 arrive: use 32 slots. Arduino's Serial uses this same ring with 64 bytes on the Uno.
What happens
;; step 1/10 · link UART universal asynchronous receiver-transmitter wires TX -> RX, plus a shared ground clock none on the wire: both ends agree a baud rate Uno PC -> USB chip (ATmega16U2) -> RX pin 0 of the ATmega328P the Hardware lesson "Serial buses: UART, I2C and SPI" covers the wires
The card shows the core lines only. The full sketch also turns on double speed (U2X0), the receiver and the RX interrupt in UCSR0B, declares buf, head, tail and lost as volatile, and wraps the read in uart_read(), which returns -1 when the ring is empty. Do not use Serial in the same sketch: the Arduino core's Serial already defines this ISR. One slot always stays empty, so 8 slots hold at most 7 bytes: that way head == tail can only mean empty. The drawing blanks a slot once it is read; in real memory the old byte stays until it is overwritten. A power-of-two size lets the compiler do % 8 as a cheap bit mask.