We prove that the trace of the space to an arbitrary closed subset is characterized by the following ``finiteness'' property. A function belongs to the trace space if and only if the restriction to an arbitrary subset consisting of at most can be extended to a function such that

The constant is sharp.

The proof is based on a Lipschitz selection result which is interesting in its own right.