How to uuencode and uudecode
To encode:
- Type or paste text into Input · Text. The uuencoded block appears in Output · uuencode.
- Set the File name under the output; it goes into the
beginline. The default isdata.bin. - Untick begin/end lines if you need only the encoded lines, for example to embed them in another format.
To decode:
- Click uuencode → Text in the direction toggle.
- Paste the uuencoded data. It can include the mail or news text around it; everything before the
beginline is skipped. - Read the text in the output, or click Save bytes to download the decoded file under the name from the
beginline. For binary content, set To to Hex to inspect it first.
Anatomy of a uuencoded file
Encoding the text Cat with the file name hello.txt gives:
begin 644 hello.txt
#0V%T
`
end
begin 644 hello.txtgives the Unix permissions and the file name.- Each data line starts with a length character: the number of bytes on the line plus 32.
#is 35, so this line holds 3 bytes. A full line holds 45 bytes and starts withM, followed by 60 characters. - The data characters work much like Base64: every 3 bytes become four 6-bit values, and each value v is written as the character with code v + 32. A value of 0 is written as a backtick instead of a space.
- The line with a single backtick is an empty line of length 0, and
endcloses the block.
A longer input shows the full-line structure:
begin 644 fox.txt
M5&AE('%U:6-K(&)R;W=N(&9O>"!J=6UP<R!O=F5R('1H92!L87IY(&1O9RX@
*,#$R,S0U-C<X.0``
`
end
That is The quick brown fox jumps over the lazy dog. 0123456789: 45 bytes on the M line and 10 on the * line (42 − 32 = 10). Every line carries its own length plus a newline, so uuencoded data is about 38% larger than the input, a bit more than Base64.
Where uuencode still turns up
uuencode comes from Unix-to-Unix Copy (UUCP) and was the standard way to send binary files through email and Usenet before MIME. Today you meet it in old mail archives, Usenet posts, some embedded and mainframe file transfers, and scripts that pipe files into mail.
The backtick convention dates from that era. Some gateways stripped trailing spaces from lines, which destroyed data encoded with space for zero; the backtick survives. This encoder writes backticks, and the decoder accepts both.
Uuencode on the command line and in Python
With GNU sharutils installed:
uuencode hello.txt hello.txt > hello.uu
uudecode hello.uu
The first argument is the input file and the second is the name written into the begin line. uudecode creates the file with that name in the current directory. Add -m to uuencode for Base64 output instead.
In Python, binascii encodes one line of up to 45 bytes at a time:
import binascii
binascii.b2a_uu(b"Cat", backtick=True) # b'#0V%T\n'
binascii.a2b_uu(b"#0V%T") # b'Cat'
Add the begin 644 name line, the closing backtick line and end yourself. More encoding examples are on the Python page.
Common problems
- An error at position 1. There is no
beginline and the text is not bare uuencoded lines either. Check that you copied the whole block. - Garbage output from a
begin-base64block. That block was written byuuencode -mand is Base64. Copy the lines betweenbegin-base64and====into the Base64 decoder. - The file is truncated or has wrong bytes near line ends. A mail client re-wrapped the lines or stripped trailing spaces. Every data line must be intact; try to get the original attachment or message source.
- A multi-part post decodes only partly. Large files were often split across several messages. Join the parts in order, keeping one
beginand oneend, before decoding.
FAQ
How do I fix uuencode: command not found?
The command is not installed by default on most Linux systems. On Debian and Ubuntu, sudo apt install sharutils adds uuencode and uudecode; Fedora has a sharutils package as well.
What does begin 644 mean?
644 is the Unix file mode the decoded file should get (owner read/write, everyone else read), and the word after it is the file name. uudecode creates that file; this page uses the name for Save bytes.
Is uuencode the same as Base64?
Both turn 3 bytes into 4 characters, but uuencode uses the ASCII range from space to underscore and adds a length character per line. Base64 has a different alphabet and is what MIME email uses. uuencode -m writes Base64 inside a begin-base64 block.
Can Python still decode uuencoded files?
Yes, with binascii.a2b_uu, one line at a time. The higher-level uu module was deprecated in Python 3.11 and removed in 3.13.