Where does the expression “a bad egg” come from and What does it mean?

A bad egg figuratively is like a bad egg literally, a person, or an egg, that externally appears to be wholesome and sound but, upon closer acquaintance, is found to be thoroughly rotten.

By some strange chance this slang usage did not develop until about the middle of the past century, though even Shakespeare called a young person an “egg,” as when, in Macbeth, the murderers, seeking Macduff, encounter and slay his young son, with the words, “What you egg! Young fry of treachery!”

A good egg, the converse of a bad egg, did not come into popular use until the early part of the present century, and it seems to have first been British university slang, probably first used at Oxford.