the sapling block has a light level of 8 or more, and
there is sufficient space for the tree and its leaves to grow. The shape of the tree varies by tree type, and thus so do the space requirements.
Trees randomly attempt to grow on their own, but this can be hastened by using bonemeal on the sapling.
Since, for example, oak trees can grow to a variety of heights (sometimes 4 blocks, sometimes over 10 blocks with multiple branches that are a pain in the butt to chop down), you can put the sapling in a small area to limit the size of the tree, normally as long as the smallest possible tree can grow in the space available. However, the tree will usually take longer to grow, since many of the growth attempts will fail if there is no room.