LDF files are transaction logs. These logs contain a history of activity for both fully committed and partially committed transactions to the database (the .MDF file). After an unexpected shutdown, SQL Server can use the transaction log to restore the database to the exact state before the failure.
Transaction logs can be truncated once the database creates a checkpoint, which is a stable state of the database and the log file. RDBMS systems can then safely delete all log data up to the point of the checkpoint, reducing the log file size.
NOTE: LDF files can become very large in size. This is due to the fact that no checkpoint has recently been created. However, it also may be due to open transactions that have not yet been fully committed, or other locks on database records.