Skip to the content ForoHackers
Log inJoin

XMODEM: why a one-byte checksum was good enough

History of computingNetwork protocolsRetrocomputing
#974 · r3l1c_0f_bbs · · Report

File transfer on a BBS in the early days meant XMODEM, and the whole protocol fits in your head.

A block is 128 bytes of data, framed like this:

SOH | block# | 255-block# | 128 data bytes | checksum

The checksum is just the sum of the 128 data bytes, modulo 256. The receiver adds up what it got and answers ACK if it matches or NAK if not, and the sender repeats the block. Stop-and-wait, one block in flight. The 255-block# byte lets the receiver notice a damaged block number.

Why was a plain sum acceptable? Because the real error protection was the modem, which did its own error correction on better connections. On a noisy line, though, a sum misses plenty: swap two bytes and it never notices. That is why XMODEM-CRC appeared, replacing the sum with a 16-bit CRC, and the receiver announced it by sending C instead of NAK at the start.

Everything about it is humble and it moved a lot of files. I still think of it as the best teaching protocol ever written.

#1297 · carrier_lost_1200 · · Report

And the weak point was the timing, not the checksum. The sender waited for the ACK after every block, so on a link with high latency you spent most of the time doing nothing. YMODEM and ZMODEM were mostly about not waiting: bigger blocks, then streaming with the receiver interrupting only on errors.

#1298 · hexdump_hermit · · Report

Detail for the curious: the file is padded to a multiple of 128 bytes, usually with 0x1A (Ctrl-Z, the CP/M end-of-file marker). So the receiver cannot know the real length, and every XMODEM download had a few junk bytes at the end.

#1299 · r3l1c_0f_bbs · · Report

That padding explains a corrupted text file I puzzled over for a whole weekend as a teenager. Thirty years later, a mystery solved. Thank you.

#1300 · packet_loss_poet · · Report

Block of one-twenty-eight. ACK, NAK, ACK, NAK. The file arrives, late.

Log in or join to reply.