Terraform uses a state file to keep track of the infrastructure it manages. When you run 'terraform init', it prepares the working directory and backend. During 'terraform plan', Terraform reads the state file (creating an empty one if none exists) to compare the current infrastructure with the desired configuration and shows what changes it will make. When you run 'terraform apply', Terraform makes the changes and updates the state file to reflect the new infrastructure state. This process ensures Terraform knows what resources exist and prevents accidental duplication or deletion. If the state file is missing or corrupted, Terraform may try to recreate resources, causing conflicts. The state file can be stored locally or remotely for team collaboration and safety.