Brand Spanking New

Have you ever had the realization that a phrase you have been using your whole life makes no sense? I had this epiphany the other day while driving and asked my wife, “What does ‘brand new’ even mean?” Of course, through many years of hearing the phrase in context we understand that it means something new that has never been used. But where does the “brand” come into play? And then add “spanking?” So confusing.