How to Get the SHA-256 Hash of Text (Online, JS, Python, Terminal)
Generate a SHA-256 hash of any text online, in JavaScript, Python or a terminal, with verified reference values and fixes for hashes that do not match.
The short answer
To get the SHA-256 hash of some text, encode the text as UTF-8 bytes and run them through SHA-256; the result is 64 hexadecimal characters. The SHA-256 of hello (five lowercase letters, nothing else) is 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824. You can get it in the Hash Generator, in JavaScript, in Python or in a terminal, and all four give the same answer as long as the input bytes are identical.
Reference values to check your setup
Use these to confirm that your method is correct before hashing real data. Each was produced with Node.js, Python 3 and sha256sum, and all agreed.
| Input | SHA-256 |
|---|---|
hello | 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824 |
hello plus a newline | 5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03 |
Hello (capital H) | 185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969 |
héllo (UTF-8) | 3c48591d8d098a4538f5e013dfcf406e948eac4d3277b10bf614e295d6068179 |
One extra character, one capital letter or one accented letter produces a completely different hash. That is by design.
Method 1: online with the Hash Generator
The SHA hashes are calculated with your browser's built-in Web Crypto API after encoding the text as UTF-8, so the text is not sent anywhere. The output is lowercase hex. Watch out for one thing: if you press Enter at the end of the text, the newline becomes part of the input and you get the second hash in the table instead of the first.
Method 2: JavaScript
In the browser (and in Node.js 20 or later), use the Web Crypto API:
const bytes = new TextEncoder().encode("hello");
const digest = await crypto.subtle.digest("SHA-256", bytes);
const hex = Array.from(new Uint8Array(digest)).map(b => b.toString(16).padStart(2, "0")).join("");
crypto.subtle.digest returns raw bytes, which is why the last line converts each byte to two hex characters. padStart matters: without it, bytes below 16 would produce one character and the hash would be the wrong length. Note that crypto.subtle is only available on secure pages (HTTPS or localhost).
In Node.js you can also use the built-in crypto module:
require("crypto").createHash("sha256").update("hello", "utf8").digest("hex")
Method 3: Python
import hashlib
hashlib.sha256("hello".encode("utf-8")).hexdigest()
hashlib needs bytes, not a string, so .encode("utf-8") is required. Passing a plain string raises a TypeError.
Method 4: terminal (Linux and macOS)
The classic mistake here is the newline added by echo.
echo hello | sha256sumhasheshelloplus a newline and prints the5891b5...hash.printf 'hello' | sha256sumhashes exactly five bytes and prints the2cf24d...hash.echo -n hello | sha256sumalso omits the newline in bash on Linux, butprintfbehaves the same across shells, so it is the safer habit.
sha256sum is standard on Linux. On macOS, use shasum -a 256 in its place, or OpenSSL, which is available on both: printf 'hello' | openssl dgst -sha256. These commands were checked on Linux and all printed the same 2cf24d... value.
For files instead of text, pass the file name, for example sha256sum setup.iso. Checking a downloaded file against a published checksum is covered in how to verify a file checksum.
Why two tools give different hashes for the "same" text
If your hashes do not match, the inputs are different bytes. The usual causes:
- Trailing newline. From
echo, from pressing Enter, or from a text file saved with a final line break. - Windows line endings. A line break saved as CRLF (two bytes) hashes differently from LF (one byte).
- Leading or trailing spaces. Copying from a web page or spreadsheet often adds them.
- Different text encoding.
hélloin UTF-8 is 6 bytes; in Latin-1 it is 5 bytes. We checked: the Latin-1 bytes hash toc63c19ed..., not the UTF-8 value in the table. Modern tools default to UTF-8, but older systems may not. - Uppercase vs lowercase hex.
2CF24D...and2cf24d...are the same hash written differently. Compare them case-insensitively. - Hashing the hex of something else. Hashing an already-hashed value, or Base64 output, gives a different result from hashing the original.
The same causes apply to MD5; there is a longer list in why the same text gives a different MD5 hash.
Hex or Base64 output?
A SHA-256 hash is always 32 bytes. How it is written depends on the tool:
- Hex (the usual form) writes each byte as two characters, giving 64 characters. This is what the Hash Generator,
sha256sumand Python'shexdigest()show. - Base64 packs the same 32 bytes into 44 characters. For
helloit isLPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=, which you get withdigest("base64")in Node.js orbase64.b64encode(hashlib.sha256(b"hello").digest())in Python.
Some APIs, such as content-integrity headers and subresource integrity attributes, expect Base64, so a correct hex hash can still be "wrong" for them. Convert the format, not the hash.
A useful sanity check: the SHA-256 of an empty input is e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855. If you see that value, your program hashed nothing, which usually means a variable was empty or a file path was wrong.
What SHA-256 is (and is not) for
SHA-256 is a one-way function: you cannot turn the hash back into the text. Typical uses:
- Integrity checks. Confirm a file or message has not changed.
- Fingerprints and cache keys. A short, fixed-length ID for any amount of data.
- Signatures and HMACs. SHA-256 is the hash inside many signing schemes, used with a secret key rather than on its own.
It is not a good way to store passwords by itself. SHA-256 is fast, which makes guessing attacks fast too. Password storage needs a slow, salted algorithm such as Argon2id, scrypt, bcrypt or PBKDF2. For choosing between SHA variants, see SHA-1 vs SHA-256 vs SHA-512.
Quick checklist
hello. You should get 2cf24dba...b9824.Frequently asked questions
What is the SHA-256 hash of hello?
For the five lowercase letters hello with no newline, SHA-256 is 2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824. With a trailing newline it is 5891b5b522d5df086d0ff0b110fbd9d21bb4fc7163af34d08286a2e846f6be03.
Why does echo give a different SHA-256 than online tools?
echo adds a newline, so echo hello | sha256sum hashes six bytes. Use printf 'hello' | sha256sum to hash exactly the text.
Can you reverse a SHA-256 hash?
No. SHA-256 is a one-way function. Short or common inputs can be guessed by trying candidates, which is why fast hashes alone are not suitable for storing passwords.
Is SHA-256 output uppercase or lowercase?
Either. Hex is not case-sensitive, so 2CF24D... and 2cf24d... are the same hash. Most tools, including the Lazyblink Hash Generator, show lowercase.
Put this guide into practice with our free online tool — no signup required.
Open tool