UART Baud Rate Calculator (Error, Divisor and Transfer Time)
The divisor to load for a baud rate, the error it leaves with your clock (in normal and double-speed mode), the bits that make up a frame, the real data rate and the time to send a message.
Results
The dashed line marks the value you entered.
What this tool does
A UART derives its baud rate by dividing the microcontroller clock, which is why not every speed is exact: on an AVR, UBRR = f_osc ÷ (16 × baud) − 1 must be a whole number, so 9600 baud from a 16 MHz clock is really 9615 baud, 0.16 % too fast. Two ends can talk if their combined error stays within a few percent, and a rule of thumb is to keep each under about 2 %. Each byte also costs more than 8 bit times: start and stop bits and an optional parity bit make 10 bits for the common 8N1 format, so 9600 baud carries 960 bytes per second, not 1200.
Formula
UBRR = f_osc ÷ (16 × baud) − 1 (best of the two nearest integers) · error = actual ÷ wanted − 1 · frame = 1 + data + parity + stop bits · time = bytes × frame ÷ baud
Variables
| Symbol | Meaning | Unit |
|---|---|---|
ba | Baud rate wanted | baud |
db | Data bits | bit |
pa | Parity | — |
sb | Stop bits | — |
nby | Message length | B |
fo | Microcontroller clock | MHz |
ER | Baud-rate error with the best divisor | % |
UB | Divisor to load (UBRR on AVR) | — |
AB | Baud rate you will really get | baud |
E2 | Error in double-speed mode (U2X) | % |
FR | Bits on the wire per byte | bit |
EF | Share of the line carrying data | % |
DR | Data rate | B/s |
TM | Time to send the message | ms |
Worked example
- Baud rate wanted9600 baud
- Data bits8 bit
- Parity0
- Stop bits1
- Message length100 B
- Microcontroller clock16 MHz
- Baud-rate error with the best divisor0.16 %
- Divisor to load (UBRR on AVR)103
- Baud rate you will really get9615.4 baud
- Error in double-speed mode (U2X)0.16 %
- Bits on the wire per byte10 bit
- Share of the line carrying data80.0 %
- Data rate960.0 B/s
- Time to send the message104.17 ms
Limitations
- Coverage and consumption figures vary between products. Take the values from the manufacturer's datasheet for the product you are actually using.
- The result is an estimate based only on the values you type. Real situations often include factors this calculator does not know about.