The band lineup, or alignment, of semiconductors is investigated via first-principles calculations based on density functional theory (DFT) and many-body perturbation theory (MBPT). Twenty-one semiconductors including C, Si, and Ge in the diamond structure, BN, AlP, AlAs, AlSb, GaP, GaAs, GaSb, InP, InAs, InSb, ZnS, ZnSe, ZnTe, CdS, CdSe, and CdTe in the zinc-blende structure, and GaN and ZnO in the wurtzite structure are considered in view of their fundamental and technological importance. Band alignments are determined using the valence and conduction band offsets from heterointerface calculations, the ionization potential (IP) and electron affinity (EA) from surface calculations, and the valence band maximum and conduction band minimum relative to the branch point energy, or charge neutrality level, from bulk calculations. The performance of various approximations to DFT and MBPT, namely the Perdew-Burke-Ernzerhof (PBE) semilocal functional, the Heyd-Scuseria-Ernzerhof (HSE) hybrid functional, and the $GW$ approximation with and without vertex corrections in the screened Coulomb interaction, is assessed using the $GW{\ensuremath{\Gamma}}^{1}$ approximation as a reference, where first-order vertex corrections are included in the self-energy. The experimental IPs, EAs, and band offsets are well reproduced by $GW{\ensuremath{\Gamma}}^{1}$ for most of the semiconductor surfaces and heterointerfaces considered in this study. The PBE and HSE functionals show sizable errors in the IPs and EAs, in particular for group II-VI semiconductors with wide band gaps, but are much better in the prediction of relative band positions or band offsets due to error cancellation. The performance of the $GW$ approximation is almost on par with $GW{\ensuremath{\Gamma}}^{1}$ as far as relative band positions are concerned. The band alignments based on average interfacial band offsets for all pairs of 17 semiconductors and branch point energies agree with explicitly calculated interfacial band offsets with small mean absolute errors of both $\ensuremath{\sim}0.1\text{eV}$, indicating a good overall transitivity of the band offsets. The alignment based on IPs from selected nonpolar surfaces performs comparably well in the prediction of band offsets at most of the considered interfaces. The maximum errors are, however, as large as 0.3, 0.4, and 0.7 eV for the alignments based on the average band offsets, branch point energies, and IPs, respectively. This margin of error should be taken into account when performing materials screening using these alignments.