I’ve heard this all my life, hummed it myself, and consider it the original ear worm. And now I know the name of it (via Hacker News):
“Shave and a Haircut” and the associated response “two bits” is a seven-note musical call-and-response couplet, riff or fanfare popularly used at the end of a musical performance, usually for comedic effect. It is used melodically or rhythmically, for example as a door knocker.
Give it a listen on the Wikipedia Page.You’ve definitely heard this before!