Let $S subset mathbb{R}^{n}$ be a~closed set such that for some $d in [0,n]$ and $varepsilon > 0$ the~$d$-Hausdorff content $mathcal{H}^{d}_{infty}(S cap Q(x,r)) geq varepsilon r^{d}$ for all cubes~$Q(x,r)$ centered in~$x in S$ with side length $2r in (0,2]$. For every $p in (1,infty)$, denote by $W_{p}^{1}(mathbb{R}^{n})$ the classical Sobolev space on $mathbb{R}^{n}$. We give an~intrinsic characterization of the restriction $W_{p}^{1}(mathbb{R}^{n})|_{S}$ of the space $W_{p}^{1}(mathbb{R}^{n})$ to~the set $S$ provided that $p > max{1,n-d}$. Furthermore, we prove the existence of a bounded linear operator $operatorname{Ext}:W_{p}^{1}(mathbb{R}^{n})|_{S} to W_{p}^{1}(mathbb{R}^{n})$ such that $operatorname{Ext}$ is right inverse for the usual trace operator. In particular, for $p > n-1$ we characterize the trace space of the Sobolev space $W_{p}^{1}(mathbb{R}^{n})$ to the closure $overline{Omega}$ of an arbitrary open path-connected set~$Omega$. Our results extend those available for $p in (1,n]$ with much more stringent restrictions on~$S$.