
Encryption and hashing are both used in cybersecurity, but they solve different problems.
The easiest way to remember the difference is this:
Encryption hides data so it can be read again later. Hashing creates a fixed-size fingerprint of data so it can be checked or compared later.
Encryption is reversible when you have the required key. Cryptographic hashing is designed to be one-way. NIST describes approved cryptographic hash functions as producing fixed-length message digests from messages of arbitrary length, while AES is a symmetric encryption standard designed to encrypt and decrypt data.
So, encryption and hashing are not competing technologies. In a real application, you may use both.
Encryption vs Hashing at a Glance

Feature | Encryption | Hashing |
|---|---|---|
Main purpose | Protect confidentiality | Create a digest for verification and other security uses |
Reversible? | Yes, with the required key | Designed to be one-way |
Key required? | Yes | No for a normal cryptographic hash |
Original data recovered? | Yes | No |
Output | Ciphertext | Fixed-length digest |
Common examples | AES, ChaCha20 | SHA-256, SHA-3 |
Password storage | Generally not used | Use a dedicated password-hashing function |
Typical use | Files, messages, sensitive records | Integrity checks, password verification, digital-signature workflows |
The important part is why you are transforming the data. Choose encryption when the original data must come back. Choose hashing when you only need a value that can be checked or compared.
A Real-Life Example: Locked Box vs. Fingerprint

Imagine you have an important document.
Encryption is like a locked box
You put the document inside a box and lock it.
Document
↓
Lock with a key
↓
Locked box
↓
Unlock with the key
↓
Original documentThe person who has the correct key can open the box and read the document.
That is what encryption does. Plaintext is transformed into ciphertext, and the ciphertext can later be decrypted using the appropriate key. NIST's AES standard specifically defines encryption and decryption of electronic data using cryptographic keys.
Hashing is like a fingerprint
Now imagine creating a fingerprint of the document.
Document
↓
Hash function
↓
Fixed-size fingerprintLater, you can create the fingerprint again and compare the two.
You are not trying to rebuild the original document from the fingerprint. You are checking whether you have the same data.
That is the basic idea behind cryptographic hashing.
What Is Encryption?
Encryption converts readable data, called plaintext, into an unreadable form called ciphertext using a cryptographic algorithm and a key.
Plaintext
↓
Encryption + Key
↓
CiphertextTo get the original data back:
Ciphertext
↓
Decryption + Key
↓
PlaintextThe main goal of encryption is confidentiality: keeping information private from people who should not be able to read it.
For example, suppose an application needs to store a customer's address because the address has to be displayed later.
The application can encrypt the address:
"221 Baker Street"
↓
Encryption
↓
"Encrypted data..."When the authorized application needs the address, it decrypts the ciphertext and gets the original value back.
Where is encryption used?
Encryption is commonly used when information must remain secret but still needs to be recovered later.
Examples include:
Sensitive files and backups
Personal and financial records
Database data that must later be displayed
Messages and network communication
Data stored on laptops and mobile devices
AES is a widely used symmetric encryption standard. Modern authenticated-encryption modes such as AES-GCM can provide confidentiality together with authentication/integrity protection. NIST specifies GCM as an authenticated-encryption mode.
Symmetric vs. asymmetric encryption
There are two broad categories worth knowing.
Symmetric encryption uses the same secret key for the cryptographic operation and its inverse.
Same secret key
↓
Encrypt → Ciphertext → DecryptAES is a common example.
Asymmetric cryptography uses a public/private key pair and supports operations such as public-key encryption, digital signatures, and key agreement. It should not be reduced to simply “two keys that encrypt and decrypt everything.”
What Is Hashing?
Hashing takes input data and produces a fixed-length value called a hash, hash value, or digest.
Input data
↓
Hash function
↓
Fixed-length digestFor a given cryptographic hash algorithm, the output length is fixed even when the input length changes. For example, SHA-256 produces a 256-bit digest. NIST defines cryptographic hash functions as mappings from messages of arbitrary length to fixed-length message digests.
A hash is designed to be one-way. There is no normal “decrypt” operation that takes a SHA-256 digest and returns the original message.
However, that does not mean the original value is magically impossible to guess.
For example, if someone stores:
SHA-256("123456")an attacker can try common passwords, hash each guess, and compare the results.
That is one reason why ordinary fast hashes such as SHA-256 should not be used directly for storing passwords. Passwords need specialized password-hashing functions that make large numbers of guesses expensive.
What Makes a Good Cryptographic Hash?
A cryptographic hash function is expected to provide important security properties.
Same input, same hash
For the same input and the same algorithm, the digest is deterministic.
"Hello"
↓
SHA-256
↓
same digest every timeSmall change, different digest
Changing even a small part of the input should produce a substantially different digest.
"Hello"
"hello"These two inputs produce different SHA-256 values.
Fixed-length output
A short input and a very large input still produce a digest with the defined output size for the chosen hash algorithm.
Collision resistance
A collision happens when two different inputs produce the same hash value.
Collisions are mathematically possible because an unlimited set of possible inputs is mapped into a finite output space. A secure cryptographic hash is designed to make finding a practical collision computationally infeasible. NIST lists collision resistance, preimage resistance, and second-preimage resistance among the expected properties of approved cryptographic hash functions.
Encryption vs Hashing: The Core Difference
The simplest distinction is recoverability.
Encryption
Original data
↓
Encryption
↓
Ciphertext
↓
Decryption + Key
↓
Original dataHashing
Original data
↓
Hashing
↓
Hash digestThere is no equivalent decryption step.
This is why asking “Is hashing more secure than encryption?” is not really the right question.
They are designed for different jobs.
When Should You Use Encryption?
Use encryption when you need the original information later.
For example, imagine an application storing:
Customer Address:
221 Baker StreetThe application may need to show that address to the customer later.
Hashing it would be useless for that purpose:
Address
↓
Hash
↓
DigestThe application cannot use the digest as the customer's readable address.
Encryption makes sense:
Address
↓
Encryption
↓
Ciphertext
↓
Decryption
↓
AddressCommon encryption examples
A system may encrypt:
Personal information
Financial records
Documents
Backups
Files stored on devices
Sensitive application data
The deciding question is simple:
Will the application need the original value again?
If the answer is yes, encryption may be appropriate.
When Should You Use Hashing?
Hashing makes sense when you need to verify, compare, or represent data without needing to recover the original input.
1. File integrity
Suppose you download a large software file.
The publisher can provide a trusted SHA-256 digest.
You download the file and calculate its SHA-256 digest yourself.
Publisher's SHA-256
↓
Compare
↑
Your file's SHA-256If the values match, that indicates the files have the same hash value.
For a security-sensitive integrity check, however, the expected hash itself must come from a trusted source or be protected by an authentication mechanism. A plain hash does not by itself prove who supplied it.
2. Password storage
This is one of the most important real-world uses.
A website does not normally need to know your original password after you create your account. It only needs to verify whether the password you enter during login matches the stored password verifier.
Modern guidance recommends dedicated password-hashing algorithms such as Argon2id, with other options including scrypt, bcrypt, and PBKDF2 depending on the environment. OWASP specifically warns against using fast hashes such as SHA-256 directly for password storage.
A simplified flow looks like this:
Password
+
Unique Salt
+
Cost / Work Factor
↓
Argon2id
↓
Password verifier
↓
Stored in databaseDuring login, the system runs the password through the same password-hashing process and verifies the result.
3. Digital signatures
Hashing is also used as a building block in digital-signature systems. Instead of processing an entire large message directly in the signature operation, systems can hash the message and use the digest as part of the signature process.
NIST's Digital Signature Standard describes digital signatures as mechanisms used to detect unauthorized changes and authenticate the signatory.
What Is Salting?

You will often hear hashing and salting together when passwords are discussed.
A salt is a unique random value associated with a password before the password-hashing function processes it.
Without unique salts:
User A: MyPassword123
User B: MyPassword123
Same password
↓
Same stored hashWith unique salts:
User A:
Password + Salt A
↓
Password Hash A
User B:
Password + Salt B
↓
Password Hash BEven though the users chose the same password, their stored password values are different.
The salt does not make the hash function one-way. Its job is to make precomputed attacks such as rainbow-table attacks much less useful. OWASP recommends a unique salt for each password and recommends slow, purpose-built password-hashing functions.
Password
+
Random Salt
↓
Argon2id / scrypt / bcrypt / PBKDF2
↓
Stored Password VerifierEncryption and Hashing Are Often Used Together
A modern application may use both, but for different reasons.
For example:
User Login
│
┌────────────┴────────────┐
│ │
Communication Password
│ │
Encryption Password Hashing
│ │
Confidentiality Password VerificationThe communication channel can use encryption to protect sensitive information while it moves between systems. The stored password can use a dedicated password-hashing function because the application does not need to recover the original password.
This is layered security, not “hashing the encrypted data” or “encrypting the hash” as a general rule.
Encryption vs Hashing: Side-by-Side Comparison
Characteristic | Encryption | Hashing |
|---|---|---|
Main purpose | Protect data confidentiality | Create a digest for verification and security operations |
Direction | Reversible | Designed as one-way |
Key | Uses a cryptographic key | Normal cryptographic hashing does not require a secret key |
Can original data be recovered? | Yes, using the appropriate decryption key | No normal reverse/decryption operation |
Output size | Depends on the algorithm and mode | Fixed for a specific hash algorithm |
Typical examples | AES, ChaCha20 | SHA-256, SHA-3 |
Password storage | Generally inappropriate | Use Argon2id, scrypt, bcrypt, or PBKDF2 |
Typical use | Files, records, messages, backups | Integrity checks, fingerprints, password verification, signature workflows |
Encryption vs Hashing vs Encoding
Another common source of confusion is encoding.
Encoding is different from both encryption and hashing.
Encoding
Data
↓
Encoding
↓
Different representation
↓
Can be decoded without a secret keyFor example:
Hello
↓ Base64
SGVsbG8=Base64 does not make Hello secret. Anyone can decode it.
So remember:
Encoding → Change representation
Encryption → Hide data
Hashing → Create a one-way digestThis distinction is important because Base64 is sometimes mistaken for encryption. It is not.
Which Is More Secure: Encryption or Hashing?
Neither is “more secure” in general.
That comparison doesn't really make sense because they solve different security requirements.
Use encryption when:
“I need to keep this information secret, but I also need to read it later.”
Use hashing when:
“I need to create a value that I can verify or compare later without storing the original value.”
For passwords, use a dedicated password-hashing function, not a plain SHA-256 hash.
For sensitive data that must be recovered, encryption is the appropriate category of tool.
Common Mistakes Developers Should Avoid
Storing passwords with AES
Password
↓
AES
↓
DatabaseThis means the application has a way to recover the original password. That is generally not what a password-verification system needs.
Storing passwords with SHA-256
Password
↓
SHA-256
↓
DatabaseSHA-256 is a secure general-purpose cryptographic hash, but it is intentionally fast. That makes it unsuitable as a direct password-storage mechanism because attackers can try very large numbers of guesses quickly.
Using MD5 or SHA-1 for new security-sensitive applications
Modern systems should use current cryptographic algorithms rather than relying on older hashes with known weaknesses. NIST recommends moving away from SHA-1 for applications requiring collision resistance and points to SHA-2 or SHA-3 as alternatives.
Thinking encryption automatically provides integrity
Encryption and integrity are related but distinct security properties. Modern authenticated-encryption schemes such as AES-GCM are designed to provide confidentiality together with authentication of the protected data.
A Simple Way to Remember the Difference
Think about three things:
🔐 Encryption
"Keep it secret."
I need the original data later.
#️⃣ Hashing
"Give me a fingerprint."
I need to verify or compare the data.
🔤 Encoding
"Put it in another format."
I need compatibility or safe representation.Or remember this single sentence:
Encryption protects data that must be recovered; hashing creates a one-way fingerprint of data that you can verify or compare.
Conclusion
Encryption and hashing are both important parts of modern application security, but they are not interchangeable.
Encryption is reversible and protects confidentiality. It is the right choice when sensitive information needs to remain secret but must be readable later.
Hashing is designed to be one-way and produces a fixed-size digest. It is useful for verification, fingerprints, password storage when used with a proper password-hashing function, and as a component of other cryptographic mechanisms.
The easiest rule to remember is:
Need the original data later? Use encryption.
Only need to verify or compare it? Use hashing.
The security of an application doesn't come from choosing encryption or hashing as the “stronger” option. It comes from choosing the right cryptographic mechanism for the job and using modern algorithms correctly..

Join the conversation! Your thoughts help the community grow.