Let $X $ be a convex and compact subset of $R^n$. There is a function $f :X \to R$ which is smooth & convex. It is known that $f$ can be extended to a convex $f_{ext}:R^n \to R$ as follows:
$f_{ext}(x)=f(x) $ if $x \in X$
$f_{ext}(x)=\infty $ if $x \notin X$
What is the subgradient of $f_{ext}$? Can it be proved that subdifferential of$ f_{ext}$, $\partial f_{ext}(x)= \nabla f(x)+\partial I(x)$ (where $I(x)$ is the indicator function of set $X$ defined as: $I(x)=0 $ if $x \in X$ else $I(x)= \infty$.)?
Note that for the function $f:X \to \Bbb R$ $$\partial f(\bar{x}) = \{ y \in \Bbb R^n ~|~~ \langle y , x -\bar{x} \rangle \leq f(x) - f(\bar{x}) ~~ \forall x \in X \} $$ $$= \{ y \in \Bbb R^n ~|~~\langle y , x -\bar{x} \rangle \leq f(x) - f(\bar{x}) ~~ \forall x \in \text{dom } f = \text{dom } f_{ext} \} $$ $$= \partial f_{ext}( \bar{x})$$
What convex analysis tells you for subdifferential at boundary of $X$ is that $$ \partial f(x) := \partial f_{ext}(x) $$
Thus writing subdifferential of $f_{ext}$ in terms of subdifferential of $f$ is trivial since they coincide.
Note that $$\partial f_{ext}(x)= \nabla f(x)+\partial I(x)$$ is not true when $x \in$ boundary of $X$. Since $f$ is smooth on only $\text{int}X $
By the way $\partial I (\bar{x}) = N (\bar{x} ; X).$
As an example think about the function $f[-1,+1] \to R$ with $f(x) = - \sqrt{1-x^2}. $ what would be the $\partial f (1)$
HOWEVER if $\nabla f : \text{int} X \to R^n$ be bounded function then we have $$ \partial f_{ext}(\bar{x})= \text{Lim Sup}_ {x \to \bar{x}} \nabla f(x)+\partial I(\bar{x}) $$