The set $M_n(\mathbb{R})$ of all $n \times n$ matrices over the real numbers is an example of an algebraic structure called a $C^*$-algebra. The subalgebra $D$ of diagonal matrices has special properties and is called a \emph{Cartan subalgebra} of $M_n(\mathbb{R})$. Given an arbitrary $C^*$-algebra, it can be very hard (but also very rewarding) to find a Cartan subalgebra, if one exists at all. However, if the $C^*$-algebra is generated by a cocycle $c$ and a group (or groupoid) $G$, then it is natural to look within $G$ for a subgroup (or subgroupoid) $S$ that may give rise to a Cartan subalgebra. In this talk, we identify sufficient conditions on $S$ and $c$ so that the subalgebra generated by $(S,c)$ is indeed a Cartan subalgebra of the $C^*$-algebra generated by $(G,c)$. We then apply our theorem to $C^*$-algebras generated by $k$-graphs, which are directed graphs in higher dimensions. This is joint work with J. Briones Torres, A. Duwenig, L. Gallagher, E. Gillaspy, S. Reznikoff, H. Vu, and S. Wright.