Where it comes from
The Character of Physical Law is a set of lectures Feynman gave for a general audience, first published as a book by the BBC in 1965. Chapter 6 is about quantum mechanics, and near its start, on page 129 of the MIT Press paperback, comes the real line.
He sets it up with a joke about relativity: “There was a time when the newspapers said that only twelve men understood the theory of relativity. I do not believe there ever was such a time.” Plenty of people came to understand relativity, he says. Then: “On the other hand, I think I can safely say that nobody understands quantum mechanics.”
What he meant
The very next sentence tells you the mood: “So do not take the lecture too seriously, feeling that you really have to understand in terms of some model what I am going to describe, but just relax and enjoy it.”
A little later he adds: “Do not keep saying to yourself, if you can possibly avoid it, ‘But how can it be like that?’” If you do, he warns, you’ll end up in “a blind alley from which nobody has yet escaped. Nobody knows how it can be like that.”
So it wasn’t a put-down. It was a physicist telling a lecture hall that the theory works superbly, that nobody has a picture of why nature behaves this way, and that this is fine. You can still learn what nature does.
How the popular version differs
The version that circulates, “If you think you understand quantum mechanics, you don’t understand quantum mechanics”, adds a twist that isn’t in the original: that feeling you understand is itself proof you don’t. It’s catchy, and it sounds like Feynman, but we couldn’t find it in his work. On Wikiquote, editors asked for a source for exactly this wording in 2011, and the discussion still points back to the page 129 sentence instead.
Our take
Paraphrased, and the paraphrase shifts the meaning a little. Feynman’s line is about everyone, himself included, and it comes with an invitation to stop worrying and look at what nature actually does. The popular version is about catching you out. If you quote it, quote the real sentence and the book. It’s just as good, and it has a page number.