TITLE: Why do units (from physics) behave like numbers?
QUESTION [141 upvotes]: What are units (like meters $m$, seconds $s$, kilogram $kg$, …) from a mathematical point of view?
I've made the observation that units "behave like numbers". For example, we can divide them (as in $m/s$, which is a unit of speed), and also square them (the unit of acceleration is $\frac{m}{s^2}$). In addition to that, we can cancel units:
$$s = v\cdot t$$
If for example $v=4\frac{m}{s}$ and $t=5s$, then
$$\require{cancel}s=4\frac{m}{\cancel s}\cdot 5\cancel s=20m.$$
Note that $\frac{m}{s}$ can also be written as $ms^{-1}$. This is another example where units "behave" like numbers.
So why can we cancel units, why do units behave like numbers?
I want to get an answer that can be understood by highschool students.

REPLY [7 votes]: Here's an attemps to describe a mathematical formalism that accounts for the physical units. I will try to distinguish the physical requirements from the mathematical features.
The most fundamental physical input is the following : 
we need a finite number of fundamental units to build a system of units covering all physical quantities.
Usually these are chosen as mass [M], length [L], time [T], temperature [$\Theta$], electric charge [Q], quantity [N], luminscence [I] but other choices are possible (for instance one can distinguish horizontal and vertical lengths).
Different units are used to quantify things that cannot be added. You can add a distance and a length and you will obtain another length so distance and length have the same physical nature. Thermodynamics states that you can add a physical work and a heat, so these two concepts are of the same physical nature, now called energy.
As is does not make sense to add different units, but only to multiply them, the complete unit system is a multiplicative structure, with identity element [1] (the dimension of dimensionless quantities) and the seven fundamental units as independent generators. We can denote this structure as 
$(\mathfrak U,\cdot)$, with 
$$\mathfrak U=\left\{[M]^m[L]^{\ell}[T]^t[\Theta]^\theta[Q]^q[N]^n[I]^j,(m,\ell,t,\theta,q,n,j)\in G^7\right\}$$
where $(G,+)$ is a group such that $G\supset\mathbb Z$. In elementary physics, it is usually enough to take $G=\mathbb Z$. Brownian motion requires to use $G=\frac12\mathbb Z$ and critical phenomena, in which critical exponents appear, or dynamical systems use real valued exponents, so it is best to chose $G=\mathbb R$ from the start. 
Furthermore, one needs a real number (sometimes a complex number can be used but that's probably far beyond the scope of the question) to represent the amplitude of the physical quantity. As a final construction we have the structure $$(\mathbb R\times\mathfrak U,\cdot)$$ equipped with the canonical product $(x,u)\cdot (y,v) = (xy,\,uv)$. 
The physical units are of great importance in physics, since this is used to determine dimensionless quantities thanks to the $\pi$ theorem.