What is the origin of the idiom "with all the bells and whistles"?

Solution 1:

The Collins dictionary has this to say about the etymology of this phrase:

Bells and whistles

Word origin: from the bells and whistles which used to decorate fairground organs

http://www.collinsdictionary.com/dictionary/english/bells-and-whistles

Fairground organs could be very colorful, so it's easy to see how they would serve as a basis for the idiom:

enter image description here

Solution 2:

Not sure about the cattle, but you could be on the right lines with country fairs. The Oxford Dictionary of Word Origins (by Julia Cresswell), under the entry on 'Bell', states (p.44):

Bells and whistles for attractive but unnecessary extras (...) is an allusion to the bells and whistles of old fairground organs.

which makes more sense to me than putting a whistle on a cow. The Wikipedia entry for such a calliope mentions

The whistles of a calliope are tuned to a chromatic scale, although this process is difficult and must be repeated often to maintain quality sound. Since the pitch of each note is largely affected by the temperature of the steam, accurate tuning is nearly impossible; however, the off-pitch notes (particularly in the upper register) have become somewhat of a trademark of the steam calliope. A calliope may have anywhere from 25 to 67 whistles, but 32 is traditional for a steam calliope.

And the entry for fairground organ says:

The ornate case façades frequently had different instruments such as a Glockenspiel or Drums that provide visual entertainment as they played. There were often ornate human figures such as a conductor whose arm moved in time to the music or women whose arms would strike bells. The mechanics to accomplish this motion were quite intricate and provided a pleasant visual experience in addition to the music.

So while I'm reluctant to claim this as the source, these early steam-powered entertainments were certainly fitted with lots of Bs and Ws, for delightful if arguably non-essential reasons.

Edit -- crossposted with @A.P.

Solution 3:

Here is an attestation from 1858 of the phrase "bells and whistles" in connection with the idea of fancy conveniences that mansions can be fitted out with.