In this paper, we propose an interference alignment and cancelation (IAC) scheme for the uplink of heterogeneous networks (HetNets). Due to the random deployment of small cells and the heterogeneous deployment of macrocells and small cells, complex interference occurs in HetNets. This makes the optimal interference cancelation order and the corresponding interference alignment (IA) scheme of IAC hard to determine. To address this problem, we first develop a set of constraints that should be satisfied by users, base stations, and interference cancelation when IAC is carried out in the HetNets. Meanwhile, by giving the design method of the precoding and decoding vectors, we prove that IAC is feasible if the developed constraints are satisfied. Then, to determine the optimal IAC scheme, based on the developed constraints, we construct an optimization problem with the aim of maximizing the number of data streams that can be transmitted in the network. By solving the optimization problem, the optimal interference cancelation order and the corresponding IA scheme can be obtained. The simulation results show that the proposed IAC scheme can significantly increase the number of data streams transmitted in the whole network.