In this paper we solve the problem of extending continuous functions with nonempty subdifferential at every point of a closed subset A of R n to functions with the same property defined in the whole R n , keeping the property of outer semicontinuity of the subdifferential, which is a set-valued function. The proof is constructive, and gives us a wide range of possible extensions.