How does the gradle know that the files of input or output has been changed or not?

Gradle Incremental Build will work if the input files and the output files of the task haven’t been changed. But I wonder how does the gradle know that? By the modification time of the file or other methods?

Details of how it works are described in the user guide.