Then the wanderer Vacchagotta went to the Blessed One and, on arrival, exchanged courteous greetings with him. After an exchange of friendly greetings & courtesies, he sat to one side. As he was sitting there he asked the Blessed One: "Now then, Venerable Gotama, is there a self?"
When this was said, the Blessed One was silent.
"Then is there no self?"
A second time, the Blessed One was silent.
Then Vacchagotta the wanderer got up from his seat and left.
Then, not long after Vacchagotta the wanderer had left, Ven. Ananda said to the Blessed One, "Why, lord, did the Blessed One not answer when asked a question by Vacchagotta the wanderer?"
"Ananda, if I — being asked by Vacchagotta the wanderer if there is a self — were to answer that there is a self, that would be conforming with those brahmans & contemplatives who are exponents of eternalism [the view that there is an eternal, unchanging soul]. If I — being asked by Vacchagotta the wanderer if there is no self — were to answer that there is no self, that would be conforming with those brahmans & contemplatives who are exponents of annihilationism [the view that death is the annihilation of consciousness]. If I — being asked by Vacchagotta the wanderer if there is a self — were to answer that there is a self, would that be in keeping with the arising of knowledge that all phenomena are not-self?"
"No, lord."
"And if I — being asked by Vacchagotta the wanderer if there is no self — were to answer that there is no self, the bewildered Vacchagotta would become even more bewildered: 'Does the self I used to have now not exist?'"
See also: other suttas in the Avyakata Samyutta (and the translator's Introduction); AN 4.42.