This is a commonly asked question among beginners and students. In this post, we are going to clarify the main differences between the two terms by providing basic definitions as well as indicating why (when) they are used. Let us begin with encoding...
What is encoding?
Encoding is the process of transforming data (ex. text file) into another format so that it can be properly stored, transmitted and consumed by another device or system. Encoding and decoding algorithms are publicly available (i.e. there is no secrecy involved). If the encoding scheme is known (or detected) then the encoded data can be easily decoded back to its original form.
Why do we need to change data format in the first place? Why do not we just keep it as is? Consider the following scenarios...
- Imagine we want to transfer a binary file (ex. an image) using a system that only accepts text format (ex. xml or json). One way to do that is to encode the image pixel data using base64 to ensure that the transformed data is compatible with text format
- Another example is URL encoding. If we include unprintable or special characters in the URL, problems may arise. URL encoding solves this problem by transforming special characters (or control characters) into a representation that is acceptable by web browsers and servers
- A third example is text compression where input text is converted into a new format for the purpose of size reduction. On the other hand, extraction is nothing but the decoding process
An encoding scheme refers to the method or algorithm by which the input data is transformed into a new format. Recall that decoding algorithm is the opposite process. As we mentioned earlier, encoding schemes are not a secret. They can be used by the receiving end to reconstruct the original data. Here are some popular encoding schemes...
- ASCII used to encode characters into numbers (i.e. a byte stream)
- UNICODE same as ASCII but it supports all writing systems of the world. It is more advanced and widely used
- BASE64 used to encode binary data into text compatible format
That is all about encoding for now, let us move to encryption...
What is encryption?
Similar to encoding, encryption transforms data into a new format (scrambled data), however the key difference is that the output data cannot be read (i.e. decrypted) except by the intended recipient. Asking the same question again, why do we need to scramble data? As opposed to encoding, the answer in this case is obvious. When sending confidential over untrusted medium such as the Internet, the data needs to be scrambled so that only intended recipients can decipher it.
How encryption works?
This is beyond the scope of this short post, however -generally speaking- there are two main encryption methods:
- Symmetric key encryption (ex. AES): the same cryptographic keys are used for both encryption of plain text and decryption of cipher text
- Asymmetric key encryption (ex. RSA): also known as public key encryption. Two (public and private) different but related keys are used. The private key is used to encrypt the message while the public key is used to decrypt the message
For more information about encryption, you may check the following post.
Here is a summary of differences in a tabular form:
|Transforms input data into a new format||Similar, transforms input data into a new format
|The goal is proper use of data in different systems or size reduction||The goal is to hide data from third parties over untrusted mediums
|Encoding and decoding algorithms are public and known||The algorithm is known but the keys are kept secret
The following links shed more light on some of the concepts discussed earlier...
Thanks for visiting. For questions and feedback, please use the comments section below.