Question 1.0.0.1. Let $X$ be a topological space. Can one devise a “categorytheoretic” invariant of $X$, in the spirit of the fundamental groupoid $\pi _{\leq 1}(X)$, which contains information about all the homotopy groups of $X$?
1 The Language of $\infty $Categories
A principal goal of algebraic topology is to understand topological spaces by means of algebraic and combinatorial invariants. Let us consider some elementary examples.
To any topological space $X$, one can associate the set $\pi _0(X)$ of path components of $X$. This is the quotient of $X$ by an equivalence relation $\simeq $, where $x \simeq y$ if there exists a continuous path $p: [0,1] \rightarrow X$ satisfying $p(0) = x$ and $p(1) = y$.
To any topological space $X$ equipped with a base point $x \in X$, one can associate the fundamental group $\pi _{1}(X,x)$. This is a group whose elements are homotopy classes of continuous paths $p: [0,1] \rightarrow X$ satisfying $p(0) = x = p(1)$.
For many purposes, it is useful to combine the set $\pi _0(X)$ and the fundamental groups $\{ \pi _1(X,x) \} _{x \in X}$ into a single mathematical object. To any topological space $X$, one can associate an invariant $\pi _{\leq 1}(X)$ called the fundamental groupoid of $X$. The fundamental groupoid $\pi _{\leq 1}(X)$ is a category whose objects are the points of $X$, where a morphism from a point $x \in X$ to a point $y \in X$ is given by a homotopy class of continuous paths $p: [0,1] \rightarrow X$ satisfying $p(0) = x$ and $p(1) = y$. The set of path components $\pi _0(X)$ can then be recovered as the set of isomorphism classes of objects of the category $\pi _{\leq 1}(X)$, and each fundamental group $\pi _{1}(X,x)$ can be identified with the automorphism group of the point $x$ as an object of the category $\pi _{\leq 1}(X)$. The formalism of category theory allows us to assemble information about path components and fundamental groups into a single convenient package.
The fundamental groupoid $\pi _{\leq 1}(X)$ is a very important invariant of a topological space $X$, but is far from being a complete invariant. In particular, it does not contain any information about the higher homotopy groups $\{ \pi _{n}(X,x) \} _{n \geq 2}$. We therefore ask the following:
We begin to address Question 1.0.0.1 in §1.1 by introducing the theory of simplicial sets. A simplicial set $S_{\bullet }$ is a collection of sets $\{ S_ n \} _{n \geq 0}$, which are related by face maps $\{ d_ i: S_ n \rightarrow S_{n1} \} _{0 \leq i \leq n}$ and degeneracy maps $\{ s_ i: S_ n \rightarrow S_{n+1} \} _{0 \leq i \leq n}$ satisfying suitable identities (see Definition 1.1.1.12 and Exercise 1.1.1.11). Every topological space $X$ determines a simplicial set $\operatorname{Sing}_{\bullet }(X)$, called the singular simplicial set of $X$, with the property that each $\operatorname{Sing}_{n}(X)$ is the collection of continuous maps from the topological $n$simplex into $X$ (Construction 1.1.7.1). Moreover, the homotopy groups of $X$ can be reconstructed from the simplicial set $\operatorname{Sing}_{\bullet }(X)$ by a simple combinatorial procedure (see §3.2). Kan observed that this procedure can be applied more generally to any simplicial set $S_{\bullet }$ satisfying the following Kan extension condition:
 $(\ast )$
For $0 \leq i \leq n$, every map $\sigma _0: \Lambda ^{n}_{i} \rightarrow S_{\bullet }$ admits an extension $\sigma : \Delta ^{n} \rightarrow S_{\bullet }$.
Here $\Delta ^ n$ denotes a certain simplicial set called the standard $n$simplex (Construction 1.1.2.1), and $\Lambda ^{n}_{i}$ denotes a certain simplicial subset of $\Delta ^ n$ called the $i$th horn (Construction 1.1.2.9). Simplicial sets satisfying condition $(\ast )$ are called Kan complexes. Every simplicial set of the form $\operatorname{Sing}_{\bullet }(X)$ is a Kan complex (Proposition 1.1.9.8), and the converse is true up to homotopy. More precisely, Milnor proved in [MR0084138] that the construction $X \mapsto \operatorname{Sing}_{\bullet }(X)$ induces an equivalence from the (geometrically defined) homotopy theory of CW complexes to the (combinatorially defined) homotopy theory of Kan complexes; we will discuss this point in Chapter 3 (see Theorem 3.5.0.1).
The singular simplicial set $\operatorname{Sing}_{\bullet }(X)$ is a natural candidate for the sort of invariant requested in Question 1.0.0.1: it is a mathematical object of a purely combinatorial nature which contains complete information about the homotopy groups of $X$ and their interrelationship (from which we can even reconstruct $X$ up to homotopy equivalence, provided that $X$ has the homotopy type of a CW complex). But in order to see that it qualifies as a complete answer, we must address the following:
Question 1.0.0.2. Let $X$ be a topological space. To what extent does the simplicial set $\operatorname{Sing}_{\bullet }(X)$ behave like a category? What is the relationship between $\operatorname{Sing}_{\bullet }(X)$ with the fundamental groupoid of $X$?
Our answer to Question 1.0.0.2 begins with the observation that the theory of simplicial sets is closely related to category theory. To every category $\operatorname{\mathcal{C}}$, one can associate a simplicial set $\operatorname{N}_{\bullet }(\operatorname{\mathcal{C}})$, called the nerve of $\operatorname{\mathcal{C}}$ (we will review the construction of $\operatorname{N}_{\bullet }(\operatorname{\mathcal{C}})$ in §1.2; see Construction 1.2.1.1). The construction $\operatorname{\mathcal{C}}\mapsto \operatorname{N}_{\bullet }(\operatorname{\mathcal{C}})$ is fully faithful (Proposition 1.2.2.1): in particular, a category $\operatorname{\mathcal{C}}$ is determined (up to canonical isomorphism) by the simplicial set $\operatorname{N}_{\bullet }(\operatorname{\mathcal{C}})$. Throughout much of this book, we will abuse notation by not distinguishing between a category $\operatorname{\mathcal{C}}$ and its nerve $\operatorname{N}_{\bullet }(\operatorname{\mathcal{C}})$: that is, we will view a category as a special kind of simplicial set. These simplicial sets have a simple characterization: according to Proposition 1.2.3.1, a simplicial set $S_{\bullet }$ has the form $\operatorname{N}_{\bullet }(\operatorname{\mathcal{C}})$ (for some category $\operatorname{\mathcal{C}}$) if and only if it satisfies the following variant of the Kan extension condition (Proposition 1.2.3.1):
 $(\ast ')$
For $0 < i < n$, every map $\sigma _0: \Lambda ^{n}_{i} \rightarrow S_{\bullet }$ admits a unique extension $\sigma : \Delta ^{n} \rightarrow S_{\bullet }$.
The extension conditions $(\ast )$ and $(\ast ')$ are closely related, but differ in two important respects. The Kan extension condition requires that every map of simplicial sets $\sigma _0: \Lambda ^{n}_{i} \rightarrow S_{\bullet }$ admits an extension $\sigma : \Delta ^ n \rightarrow S_{\bullet }$. Condition $(\ast ')$ requires the existence of an extension only in the case $0 < i < n$, but demands that the extension is unique. Neither of these conditions implies the other: a simplicial set of the form $\operatorname{N}_{\bullet }(\operatorname{\mathcal{C}})$ satisfies condition $(\ast )$ if and only if the category $\operatorname{\mathcal{C}}$ is a groupoid (Proposition 1.2.4.2), and a simplicial set of the form $\operatorname{Sing}_{\bullet }(X)$ satisfies condition $(\ast ')$ if and only if every continuous path $[0,1] \rightarrow X$ is constant. However, conditions $(\ast )$ and $(\ast ')$ admit a common generalization. We will say that a simplicial set $S_{\bullet }$ is an $\infty $category if it satisfies the following variant of $(\ast )$ and $(\ast ')$, known as the weak Kan extension condition:
 $(\ast '')$
For $0 < i < n$, every map $\sigma _0: \Lambda ^{n}_{i} \rightarrow S_{\bullet }$ admits an extension $\sigma : \Delta ^ n \rightarrow S_{\bullet }$.
The theory of $\infty $categories can be viewed as a simultaneous generalization of homotopy theory and category theory. Every Kan complex is an $\infty $category, and every category $\operatorname{\mathcal{C}}$ determines an $\infty $category (given by the nerve $\operatorname{N}_{\bullet }(\operatorname{\mathcal{C}})$). In particular, the notion of $\infty $category answers the first part of Question 1.0.0.2: simplicial sets of the form $\operatorname{Sing}_{\bullet }(X)$ are almost never (the nerves of) categories, but are always $\infty $categories. At this point, the reader might reasonably object that this is terminological legerdemain: to address the spirit of Question 1.0.0.2, we must demonstrate that simplicial sets of the form $\operatorname{Sing}_{\bullet }(X)$ (or, more generally, all simplicial sets satisfying condition $(\ast '')$) really behave like categories. We begin in §1.3 by explaining how to extend various elementary categorytheoretic ideas to the setting of $\infty $categories. In particular, we can associate to each $\infty $category $S_{\bullet }$ a collection of objects (these are the elements of $S_0$), a collection of morphisms (these are the elements of $S_1$), and a composition law on morphisms. In particular, we show that any $\infty $category $S_{\bullet }$ determines an ordinary category $\mathrm{h} \mathit{S}_{\bullet }$, called the homotopy category of $S_{\bullet }$ (Proposition 1.3.5.2). The construction of the homotopy category allows us to answer the second part of Question 1.0.0.2: for every topological space $X$, the singular simplicial set $\operatorname{Sing}_{\bullet }(X)$ is an $\infty $category, whose homotopy category $\mathrm{h} \mathit{\operatorname{Sing}}_{\bullet }(X)$ is the fundamental groupoid $\pi _{\leq 1}(X)$ (see Example 1.3.5.5).
Roughly speaking, the difference between an $\infty $category $S_{\bullet }$ and its homotopy category $\mathrm{h} \mathit{S}_{\bullet }$ is that the former can contain nontrivial homotopytheoretic information (encoded by simplices of dimension $n \geq 2$, which can be loosely understood as “$n$morphisms”) which is lost upon passage to the homotopy category $\mathrm{h} \mathit{S}_{\bullet }$. We can summarize the situation informally with the heuristic equation
or more precisely with the diagram
Structure

Section 1.1: Simplicial Sets
 Subsection 1.1.1: Simplicial and Cosimplicial Objects
 Subsection 1.1.2: Simplices and Horns
 Subsection 1.1.3: The Skeletal Filtration
 Subsection 1.1.4: Discrete Simplicial Sets
 Subsection 1.1.5: Directed Graphs as Simplicial Sets
 Subsection 1.1.6: Connected Components of Simplicial Sets
 Subsection 1.1.7: The Singular Simplicial Set of a Topological Space
 Subsection 1.1.8: The Geometric Realization of a Simplicial Set
 Subsection 1.1.9: Kan Complexes

Section 1.2: The Nerve of a Category
 Subsection 1.2.1: Construction of the Nerve
 Subsection 1.2.2: Recovering a Category from its Nerve
 Subsection 1.2.3: Characterization of Nerves
 Subsection 1.2.4: The Nerve of a Groupoid
 Subsection 1.2.5: The Homotopy Category of a Simplicial Set
 Subsection 1.2.6: Example: The Path Category of a Directed Graph
 Section 1.3: $\infty $Categories

Section 1.4: Functors of $\infty $Categories
 Subsection 1.4.1: Examples of Functors
 Subsection 1.4.2: Commutative Diagrams
 Subsection 1.4.3: The $\infty $Category of Functors
 Subsection 1.4.4: Digression: Lifting Properties
 Subsection 1.4.5: Trivial Kan Fibrations
 Subsection 1.4.6: Uniqueness of Composition
 Subsection 1.4.7: Universality of Path Categories