The Append Only File (AOF) in Redis works by saving every command executed by Redis to a file after the command runs successfully. This means when a client sends a command, Redis executes it, then appends that command to the AOF file. If Redis restarts, it reads the AOF file and replays all commands in order to restore the data exactly as it was. For example, if Redis runs SET key1 value1, then INCR counter, then DEL key1, each command is saved in the AOF file. After restart, replaying these commands rebuilds the data state. This method ensures data durability by logging changes step-by-step. However, if Redis crashes before a command is appended, that command is lost and not restored on restart. The AOF file can grow large, so Redis can rewrite it to keep it compact.