Data encryption works by using algorithms to encode data, making it accessible only to those who possess the decryption key. There are two main types of encryption: symmetric encryption and asymmetric encryption. Symmetric encryption uses the same key for both encryption and decryption, while asymmetric encryption uses a pair of keys – a public key and a private key.