The first documented use of the phrase in the sense of “revealing a secret” comes from a book review in a 1760 issue of The London Magazine, wherein the reviewer laments that, “We could have wished that the author had not let the cat out of the bag.”
That, unfortunately, is about all we know for sure. There are two popularly cited origins for the phrase, but neither is very clearly recorded as leading to it.
The first origin story claims the phrase refers to the cat o’ nine tails, infamously used by the Royal Navy as an instrument of punishment aboard its ships. The whip’s nine knotted cords could scratch an undisciplined sailor’s back badly, hence its feline nickname. The bag comes into play because the “cat,” being made of leather, had to be kept in a sack to protect it from drying out in the salty sea air and keep it flexible. Removing a whip from a sack doesn’t immediately seem to have anything to do with revealing a secret (that the lash was on board the ship and would be readily used shouldn’t have been a secret to any sailor), but if you think of “letting the cat out of the bag” as a revelation that results in a punishment, it makes a little more sense.
Urban legend clearinghouse Snopes.com rejects this origin based on the idea that “let the cat out of the bag” is recorded before “cat o’ nine tails,” but the whip’s nickname shows up in print earlier than they claim: In a 1695 play called Love for Love by William Congreve, it is used in a very clear reference to a lashing at sea. The same thing can’t be said about “let the cat out of the bag,” though, and there aren’t any recorded uses of it in a nautical context.
OR MAYBE IT RELATES TO LIVESTOCK FRAUD
The other explanation for the phrase is that it was born from a ridiculous bit of livestock fraud. Supposedly, merchants would sell customers live piglets and, after putting a pig in a sack for easier transport, would sometimes swap the pig for a cat when the customer looked away. The buyer wouldn’t discover they’d been cheated until they got home and literally let the cat out of the bag. There don’t seem to be any recorded links between the phrase and livestock markets, or even much evidence that this sort of con was commomplace. (Pigs were bagged for sale, though, and Richard Hill’s Common-place Book from 1530 offers some advice to merchants that led to another idiom: “When ye proffer the pigge open the poke.”)
There’s a certain implausibility to the trick, too. Piglets big enough to be taken to market differ in size and build from domestic cats. Consider also that cats meow, and don’t oink. We can’t imagine enough people would have picked up their purchase and thought, “this sack seems a little light, and isn’t making the right noise, but I guess everything is normal,” to make this ruse work often enough that an idiom came from it. The Spanish equivalent of the phrase—dar gato por liebre, or “giving a cat instead of a hare”—at least implies an origin with an animal that makes more sense. Rabbits meant to be eaten are usually sold already slaughtered and skinned, and are similar enough in size and appearance to cats in the same circumstances.