We introduce and study model-theoretic connected components of rings as an analogue of model-theoretic connected components of definable groups. We develop their basic theory and use them to describe both the definable and classical Bohr compactifications of rings. We then use model-theoretic connected components to explicitly calculate Bohr compactifications of some classical matrix groups, such as the discrete Heisenberg group ${\mathrm {UT}}_3({\mathbb {Z}})$, the continuous Heisenberg group ${\mathrm {UT}}_3({\mathbb {R}})$, and, more generally, groups of upper unitriangular and invertible upper triangular matrices over unital rings.