Why Base64 output differs between echo and a web encoder
Trace the difference to the final byte. Compare OK with no newline, a Unix LF and a Windows CRLF, then reproduce the exact input in a shell.
Decode both results before changing settings
A typical echo OK command writes a newline after OK. Typing OK into a web text box usually supplies only the two letters. Decode both outputs and compare the byte counts to distinguish a different input from a different encoding setting.
Read the last byte of each sample
The first visible line of all three decoded examples says OK. Their lengths are two, three and four bytes. LF is 0A and CRLF is 0D 0A. Looking at the padding alone cannot tell you which line ending the original file contained.
| Input | Bytes in hexadecimal | Base64 |
|---|---|---|
OK | 4F 4B | T0s= |
OK + LF | 4F 4B 0A | T0sK |
OK + CRLF | 4F 4B 0D 0A | T0sNCg== |
Repeat with controlled input
Run printf %s OK | base64 for a two-byte input and an output of T0s=. For a whole file, read it directly rather than moving its contents through an editor that normalizes newlines. Line wrapping added to the encoded output is a separate operation from a newline inside the original text.