The story is set partly in Salem, and partly in the wooded wilderness around the town. At first glance, the difference is pretty straightforward: the town is good, the woods are bad. Fortunately, there is a little more to it than that. Hawthorne’s story is about hypocrisy and sin. Goodman Brown has grown up in Salem; he has a natural respect for his elders, including his grandfather and his religious teacher, Goody Cloyse. In town, he sees them as good, upright people. But it is in the woods that he mysteriously meets his grandfather with the serpent staff, and overhears Goody Cloyse, the minister and Deacon Gookin proclaiming the devil and discussing a satanic ritual. And it is in the woods that Brown witnesses this black mass.
So perhaps another way of understanding the town/forest dichotomy has to do with truth. Paradoxically, the town, the place of light and civilization and clearly defined social relations, is shown to be deceptive, while the woods, which are dark and dangerous, are the place where the “true” nature of people is revealed. It’s not clear whether Brown really saw these things or hallucinated them, so the ending of the story is also ambiguous: Brown’s disenchantment with Salem after his revelation in the woods can be understood as a form of moral indignation and superiority, or a kind of madness. In either case, Hawthorne’s story calls into question the “real” nature of the people around us, and the inability of social convention (or our own experience) to reveal the true nature of things.