This is possible because the algorithm assumes that each of the n input elements is in the range [0, k], i.e. no element is smaller than 0 nor greater than k. The input is an array A indexed from 1 to n, the output is stored in the array B also indexed from 1 to n, and the array C is used as a temporary container, indexed from 0 to k.
Let C[0..k] be a new array.
For i = 0 to k:
C[i] = 0
For j = 1 to A.length:
C[A[j]] = C[A[j]] + 1
// C[i] now contains the number of elements equal to i.
For i = 1 to k:
C[i] = C[i] + C[i-1]
// C[i] now contains the number of elements less than or equal to i.
For j = A.length downto 1:
B[C[A[j]]] = A[j]
C[A[j]] = C[A[j]] - 1