Database encryption works by using cryptographic keys to encode and decode data. When data is stored, it is encrypted using a specific algorithm, and when it is retrieved, it is decrypted back into its original form. Common encryption methods include AES (Advanced Encryption Standard) and RSA (Rivest-Shamir-Adleman).