  Topological crystalline insulators define a new class of topological insulator phases with gapless surface states protected by crystalline symmetries. In this work, we present a general theory to classify topological crystalline insulator phases based on the representation theory of space groups. Our approach is to directly identify possible nontrivial surface states in a semi-infinite system with a specific surface, of which the symmetry property can be described by 17 two-dimensional space groups. We reproduce the existing results of topological crystalline insulators, such as mirror Chern insulators in the $pm$ or $pmm$ groups, $C_{nv}$ topological insulators in the $p4m$, $p31m$ and $p6m$ groups, and topological nonsymmorphic crystalline insulators in the $pg$ and $pmg$ groups. Aside from these existing results, we also obtain the following new results: (1) there are two integer mirror Chern numbers ($\mathbb{Z}^2$) in the $pm$ group but only one ($\mathbb{Z}$) in the $cm$ or $p3m1$ group for both the spinless and spinful cases; (2) for the $pmm$ ($cmm$) groups, there is no topological classification in the spinless case but $\mathbb{Z}^4$ ($\mathbb{Z}^2$) classifications in the spinful case; (3) we show how topological crystalline insulator phase in the $pg$ group is related to that in the $pm$ group; (4) we identify topological classification of the $p4m$, $p31m$, and $p6m$ for the spinful case; (5) we find topological non-symmorphic crystalline insulators also existing in $pgg$ and $p4g$ groups, which exhibit new features compared to those in $pg$ and $pmg$ groups. We emphasize the importance of the irreducible representations for the states at some specific high-symmetry momenta in the classification of topological crystalline phases. Our theory can serve as a guide for the search of topological crystalline insulator phases in realistic materials. 
Classification of topological crystalline insulators based on   representation theory