"On the first day of Christmas, my true love gave to me," etc.
So, where does that idea come from? What do they mean, "12 days of Christmas"? Aren't there actually at least four weeks of Christmas? From Thanksgiving to Christmas day? And expanding every year?
Sometime in the middle ages, the Roman Catholic Church (i.e., the main type of Christian church in those days; see also Coptic Church, Eastern Orthodox Church) adopted what we now call the Christian Calendar or the Liturgical Calendar. That calendar has seasons in it and Christmas is one of those seasons. And guess what? It lasts 12 days.
Now, I'm going to simplify the Christian Calendar here just to keep this article short, but you can find a detailed discussion of it on Wikipedia. I grew up in the United Methodist Church and am most familiar with the calendar we used and it provides a nice, basic structure:
Season 1: Advent. The name comes from the Latin adventus, meaning "coming." The focus of the season is the coming of the Christ child. It contains four Sundays and ends on Christmas Eve.
Season 2: Christmas. The name comes from the Old English Christes maesse, Christ Mass. It runs from Christmas day up to, but not including, January 6. Wow! That's 12 days. How about that? And Christmas BEGINS on Christmas day. That's different!
Season 3: Epiphany. This season begins on January 6 and varies in length depending on when Easter is.
Season 4: Lent. This season contains the 46 days (excluding Sundays) prior to Easter.
Season 5: Easter. It runs for 50 days.
Season 6: Pentecost. It runs until Advent begins.
So, when the song counts the 12 days of Christmas, it is not referring to the days before Christmas, as we might think since for us Christmas ENDS, for all practical purposes, on Christmas day. The song is counting the days in the Christmas season of the Christian calendar which BEGINS on Christmas day.