Looks at the source underneath (https://api.drupal.org/api/drupal/includes!file.inc/function/file_create_filename/7)... It's pretty simple: If it exists, it puts an integer before the extension (before the period, that is), check if that exists, incrementing the integer each time if finds it existing.