Template Hierarchy System
WordPress uses the query string to decide which template/set of templates should be used to display a certain page. The query string is information contained within the link for that page. To determine which template to use, WordPress will review to see if a very specific template exists, and then broaden the template from there. Naming conventions are used for the template files to 'assign' when they will be used.
Template Hierarchy System - Order
WordPress will work from a very specific theme file based on the query string, and then become more broad if that specificity is not met. For example, when navigating to a single page, WordPress will start with a custom template file for that page. If that is not available, it will move to a file with page-slug.php. If that is not available it will review page-id.php. It will then move on to a general page.php, then singlular.php then the broadest index.php.
Template Hierarchy System - File Naming Conventions
Determining which template will be used, as noted above, is based on naming conventions. Starting with the most specific, is a custom template. A custom template file is created using specific comments in the .php file, and can then be selected within the WordPress environment. After that, page-'slug'.php is used, and that template will be called if a page with that specific slug exists. After that, is page-'id'.php, where a template will be called if the ID (off the database) is used. Then the generic page.php file is referenced, followed by single.php, and lastly if that does not exists, the index.php template is used.
Summary
WordPress has a specific hierarchy that must be followed to determined which template a portion of your site will use. Once you understand the naming conventions, the hierarchy is easy to follow, and can even aid you in organizing your site.