Trailing Newline Changes Hash – echo vs printf SHA-256

Local only

Troubleshoot a digest mismatch caused by a final newline character.

6 chars · 2 lines

Waiting for input

Loading hash algorithms…

Newlines and hashes

Why does a trailing newline change the hash?

A final line-feed character is part of the input. This is a common reason command-line hash results differ when one command appends a newline and another does not. This tool is free to use. No account or payment is required.

Last updated

What you can do here

  • MD5 text digests
  • SHA-1 text digests
  • SHA-256 text digests
  • SHA-512 text digests
  • Exact text byte sensitivity
  • Browser-local hashing

Steps

  1. Check whether the source ends in LF or CRLF.
  2. Hash the exact bytes including the final line ending.
  3. Use a no-newline command option when the protocol expects bare text.

Command output often includes a newline

Shell commands such as echo commonly append a line ending. That extra character changes a digest even though the terminal display still looks like the same word.

Final newline SHA-256 comparison

The first input contains hello followed by LF.

Input comparison

hello\n
hello

SHA-256 digests

with LF: 5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03
without LF: 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824

Common questions

Frequently asked questions

Does a newline count when hashing text?

Yes. LF and CRLF characters are part of the hashed byte sequence.

Why can echo and printf produce different hashes?

A typical echo command appends a newline, while printf can emit the text without one.

Debugging a specific Hash issue? Browse Hash troubleshooting.