The HISTFILE environment variable specifies the file where the command history is saved when a Bash session ends. By default, this is ~/.bash_history. When Bash exits, it writes the history list to the file named by HISTFILE. If HISTFILE is unset, no history is saved.