Bien is an adverb (meaning well) and buen is an adjective (meaning good)
- Lo hiciste bien. (You did it well)
Buen is used in from of a masculine noun, while bueno/a is used after the noun:
- Fue un buen viaje. (It was a good trip)
- El viaje fue bueno. (The trip was good)
As a general rule, adjectives generally go after the noun, and the sentence will have a more literal meaning. When coming before a noun, an adjective generally takes on a more figurative, poetic, or literary sense.