It varies by locale. In some regions where I have lived, it can only include the part of the house with heating and/or air conditioning. In other regions, the unfinished, unheated attached garage can be included. Your realtor will know how it is done in your area.
Sometimes sellers include a disclaimer in their ads, saying that the buyer should verify square footages. There are two doors on the outside of my house that lead to small toolshed closets that do not connect actually with the interior. Although it was advertised as 1598 square feet when I bought it, the appraisor for the mortgage company subtracted out the toolshed closets so officially it is 1558 square feet.
The square footage computations are one reason why so many people convert attached garages to rec rooms (in my area, where they aren't included unless they are heated and cooled). I don't know about basements, but have noticed square footages computed both ways in houses with basements in Missouri that I have been looking at.