Contrary to what we all thought, carnival has a religious origin. It was the last day people could eat meat or anything coming from animals like eggs and milk, before Lent. For that reason, this was a day of celebration and big parties. All of this is very well explained in the following video:

Nowadays, Carnival is a big party celebrated worldwide, but there are some places where Carnival is especially important such as Rio de Janeiro, Venice, Cadiz or Canary Islands.