The definition of hit the nail on the head is:
(verb) to say the exact right thing
Teacher: So, what’s the correct answer?
Teacher: Good job, student. You hit the nail on the head.
Our boss loves you, because you have a way of always hitting the nail on the head. You know how to say the right things!
A: Did you hear about Wendy and John?
B: Let me guess, they are getting a divorce?
A: Wow, you hit the nail on the head. How did you know?