WhatsApp is one of the most popular messaging apps in the world, with over 2 billion active users. When you use WhatsApp, all your messages, media, and other data are stored locally on your device in a database. This allows you to access your WhatsApp data even when you are offline.
What is a database?
A database is an organized collection of data that is stored electronically. Databases allow for easy access, management, and updating of data.
WhatsApp uses a SQLite database to store your data on your device. SQLite is a lightweight, open-source database that is used in many applications, especially on mobile devices. The main benefits of using SQLite are:
- Lightweight – SQLite databases are stored as single files on the device, rather than requiring a full database server. This makes them good for mobile apps.
- Fast access – SQLite is very fast at reading and writing data.
- Reliable – SQLite has robust reliability mechanisms to prevent data corruption.
- Compact – SQLite databases require very little memory and storage space.
Where is the WhatsApp database stored?
On Android devices, the WhatsApp database is stored in the following location:
/data/data/com.whatsapp/databases/msgstore.db
On iOS devices, it is stored here:
/var/mobile/Containers/Shared/AppGroup/YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY/ChatStorage.sqlite
The exact path may vary across devices and OS versions, but it is generally in a protected application data directory that normal users do not have access to. This helps keep the WhatsApp data private and secure.
What data is stored in the WhatsApp database?
The WhatsApp database contains all your account information, settings, messages, media files, and other data related to your use of WhatsApp. This includes:
- Your account information and settings
- Your contacts list
- All chat messages you have sent and received
- Media files like photos and videos you have shared or received
- Any files or documents you have sent or received
- Chat histories and timestamps
- Any starred or favorite messages
- Group names and participants
- Deleted messages and media (until they are automatically removed)
- Cached data to improve performance
Essentially, any data created and used within WhatsApp is stored in the database on your device. The data is organized into different tables and records in the database structure.
WhatsApp database structure
The WhatsApp database uses multiple tables to store different types of data efficiently. Some of the key tables include:
Table Name | Data Stored |
---|---|
messages | Details about each message like sender, receiver, timestamp, status |
chat_list | List of chats and their last updated time |
contacts | Your contacts list and details |
groups | Details about your WhatsApp groups |
media | Media files like photos, videos, audio files |
blobs | Binary data for media files |
settings | Your WhatsApp settings and preferences |
There are over 30 tables in the WhatsApp database schema. By storing different data types in separate interlinked tables, WhatsApp can efficiently perform queries, updates, and migrations.
How is the database encrypted?
WhatsApp implements end-to-end encryption for messages stored in its database. This means the messages are encrypted on the sender’s device before transit and only decrypted on the receiver’s device. No one in between, not even WhatsApp itself, can read the messages.
Specifically, WhatsApp uses the Signal Protocol which utilizes asymmetric cryptography to secure the messages. Each user has a public and private encryption key pair. The public key is shared while the private key is known only to the user. Here is how it works:
- When you install WhatsApp, it generates a public/private key pair for your account.
- Your public key is shared with WhatsApp servers and your contacts.
- When sending a message, WhatsApp uses your contact’s public key to encrypt the message.
- On the receiving end, your private key is used to decrypt the message.
- This encrypted data is then stored in the database.
The keys change periodically for more security. As long as users don’t share their private keys, the encryption ensures only the sender and recipient can access the messages.
How are media files like photos stored?
Media files like photos and videos are also encrypted using a random 128-bit AES encryption key before they are stored in the database. This ensures they cannot be accessed by anyone except the sender and recipient.
Here are the steps for how media files are stored in the database:
- When a user sends a photo, WhatsApp compresses it to save space.
- A 128-bit AES encryption key is generated to encrypt the photo.
- The encrypted photo is stored in the ‘media’ table in the database.
- The AES encryption key for the photo is individually encrypted using the recipient’s public key.
- This encrypted AES key is stored along with the photo in the database.
- On the receiving end, the user’s private key decrypts the AES key.
- The decrypted AES key finally decrypts the photo.
This ensures end-to-end encryption for photos as well. The actual media files are stored efficiently while their decryption keys are securely shared across users.
How is the database backed up?
WhatsApp provides options for users to backup their local database to external services like Google Drive or iCloud. This allows you to restore your chat history if you lose your device or switch to a new one.
Backups contain the encrypted copies of your messages, media files, and other WhatsApp data from the device database. They do not contain your private encryption keys however. So your data remains end-to-end encrypted even in the backups.
WhatsApp follows a few best practices for secure backups:
- Backups are encrypted using a user-specific key, which is protected by a password set by the user.
- They do not store user chat keys, further protecting messages.
- Users have full control over managing backups, including password protection.
- No third-party, including WhatsApp, can read the user’s backup.
- WhatsApp cannot restore backups without the user’s encryption password.
How to clear the WhatsApp database
If needed, users can clear the WhatsApp database on their device to erase all their local data. This is recommended before changing devices or giving your phone away to someone else. Here are the steps to clear the database:
- Open WhatsApp Settings.
- Go to Chats > Clear All Chats.
- Confirm clearing all chats to erase the database.
- Also clear any media files saved to your phone storage.
- Go to Settings and tap Logout to clear account info.
- Uninstall and reinstall the app to complete the process.
This will wipe the WhatsApp database, media files, and account from the device. Your encryption keys are removed so the data cannot be recovered. You will have to set up WhatsApp again after this.
Size of the WhatsApp database
The size of the WhatsApp database depends on how heavily you use the app. It grows as you send more messages, exchange more media, and store more data in the app over time.
On average, the size of the WhatsApp database is:
- 100-200 MB for light users with limited messages and media
- 500 MB to 1 GB for moderate usage with frequent messaging
- 1-2 GB for very frequent users who exchange media regularly
Photos and videos take up the most space compared to plain text. Voice messages, documents, and databases backups also increase the database size.
WhatsApp uses compression and caching techniques to optimize storage requirements. The app can safely handle databases of up to 2-4 GB based on your device storage and memory.
Is the WhatsApp database related to Telegram or Signal?
WhatsApp, Telegram, and Signal are independent messaging apps with their own databases to store user data. There is no relationship between their databases. Each app manages its database separately.
However, WhatsApp and Signal both use the end-to-end Signal Protocol for encryption. So they have similar encryption methods even if the database works differently.
Telegram uses its own MTProto encryption protocol. Its database structure and encryption differ from WhatsApp’s.
In summary:
- WhatsApp uses SQLite database with Signal Protocol encryption
- Telegram has its own database structure and MTProto encryption
- Signal also uses Signal Protocol but has a different database implementation than WhatsApp
Can you transfer the WhatsApp database between Android and iPhone?
Unfortunately, the WhatsApp database cannot be directly transferred between Android and iPhone due to differences in operating systems. The database file formats differ.
When switching devices between Android and iOS, your chat history can still be transferred using the WhatsApp backup and restore feature. This transfers your encrypted backup from one device to another via iCloud or Google Drive.
The steps are:
- On old device, backup WhatsApp chats to Google Drive or iCloud.
- On new device, install WhatsApp and log in with same number.
- Restore chat history from backup when prompted.
This will bring your chats to the new device. Media files may need to be re-downloaded if not stored on cloud backup. As long as you use the same phone number, your chat history will restore.
Can you view, edit, or decrypt the WhatsApp database?
Viewing, editing, or decrypting the raw WhatsApp database file is very difficult and not recommended. Since it is encrypted end-to-end, the data can only be decrypted on the user’s own device with their private key.
Trying to manually access and edit the database can lead to corruption and loss of data. At best, you may be able to view encrypted data as unreadable text.
There are no ethical ways to decrypt or view someone else’s WhatsApp database without their device and encryption key. WhatsApp does not provide official tools for database access either.
Modifying the database incorrectly can also break WhatsApp functionality. So the only safe options are to use WhatsApp’s built-in tools like backup and restore when needed.
Does WhatsApp store deleted messages?
When you delete a WhatsApp message, it is removed from your chat screens. However, it continues to be stored in the database until it is automatically deleted after a certain duration.
On Android devices, deleted WhatsApp messages are stored for up to 60 days before removal. On iOS, this duration is up to 30 days.
This allows you to recover recently deleted messages using WhatsApp’s built-in backup and restore tools. Once the duration passes, the messages are permanently deleted from the database.
Note that if you clear all chats or logout from WhatsApp, it also immediately deletes all messages marked for deletion. They do not remain for those 60 or 30 days.
Conclusion
The WhatsApp database is a structured SQLite database that securely stores your account information, settings, chats, media files, and other data used in the app. It implements end-to-end encryption using the Signal Protocol to protect user privacy.
Media files also utilize an additional layer of AES-256 encryption for security. Backups provide encrypted copies of the database for restore purposes. The database is obfuscated and cannot be accessed or decrypted without the user’s encryption key.
With over 2 billion users, understanding how WhatsApp handles and protects user data is important. The underlying database structure and encryption techniques aim to provide the best balance between usability, performance, and security.