It is shown that the functional derivatives in density-functional theory (DFT) can be explicitly defined within the domain of electron densities restricted by the electron number, and a constructive definition of such restricted derivatives is suggested. With this definition, Kohn–Sham (KS) equations can be established for an N-electron system without extending the functional domain and introducing a Lagrange multiplier. This may clarify some of the fundamental questions raised by Nesbet (1998 Phys. Rev. A 58 R12). The definition naturally leads to the fact that the KS effective potential is determined only to within an additive constant, thus the KS levels can shift freely and the relation between the highest occupied molecular orbital (HOMO) energy and the ionization potential of the system depends on the choice of the constant. On the other hand, if the domain of functionals is indeed extended beyond the electron number restriction, conclusions depend on whether the extended functionals have unrestricted derivatives or not. It is shown that the ensemble extension of DFT to open systems of mixed states (Perdew et al 1982 Phys. Rev. Lett.49 1691) leads to an energy functional which has no unrestricted derivative at integer electron numbers. Hence after this extension, the relation between the HOMO energy and the ionization potential for an N-electron system is still uncertain. Besides, there are different extensions of the energy functional to a domain of densities unrestricted by the integer electron number, resulting in different unrestricted derivatives and electron systems with different chemical potentials. Even for the exact exchange-correlation potential, there is still an undetermined constant, whether it is a restricted or unrestricted derivative.