Before we tell you what to do, first question: Can you see your ball?
If you play golf on a course with a lot of trees, what we're about to describe might sound a little too familar: It's not uncommon to hit a golf ball toward the tree line only to see it disappear into the branches, needles or leaves and never come down.
Palm trees are especially stingy when it comes to returning golf balls to their proper owners. Just ask Sergio Garcia (below).

Sergio Garcia looks for his ball up a palm tree on the 12th hole during the second round of the Omega Dubai Desert Classic in 2013.
Warren Little
When you hit a ball into a tree, and it doesn't drop to the ground, how you proceed depends on one important question: Can you see it? You can do whatever you have to do to identify your ball—including using a rangefinder or scaling the branches (good luck with that)—but the clock is ticking. You've got three minutes, otherwise it’s deemed lost.
If you find your ball in the tree
If you can ID your ball in the allotted search time, you can proceed under Rule 19.2 and declare it unplayable. When you do so, you have three options from there—and they all come with a one-stroke penalty.
The first is to go back and replay from where you just hit. The second is lateral relief. You have to find the spot on the ground directly under the ball in the tree. You then get a two-clublengths drop zone that has to be no closer to the hole and can be in any area of the course, but must come to rest in the same area of the course where it first touched when dropped. (In other words, if you drop it and it lands in the general area but then rolls into a penalty area, you have to drop again—even if it's within two clublengths of the drop spot.)
Keep in mind that the drop zone might not get you clear of a tree or group of trees. It's a tough break, but that's when you might go with option one or the final option under 19.2—back-on-the-line relief. Here's how to do it:
Identify the spot on the ground directly below where the ball came to rest in the tree. Then imagine a line that runs from that spot to the hole. You can then drop the original ball or a replacement anywhere on an extension of that line farther away from the hole with no limit as to how far back you go.
Keep in mind that the spot on the line where the ball first touches the ground when dropped creates an area that is one clublength in any direction from that point, as long as it's not nearer the hole and stays in the same area of the course from where it first touched when dropped.

The options when taking an unplayable lie include (1) returning to the spot you hit your last shot; (2) taking back-on-the-line relief; (3) creating a drop zone two clublengths from where your ball was and taking relief there. (Image courtesy of the USGA)
If you DON'T find your ball in the tree
You borrowed binoculars, shook the tree, even attempted to climb it, and after three minutes have elapsed, the ball is gonzo. So what now? Simple. You treat the ball as lost and proceed under Rule 18.2 (ball lost or out of bounds). You must take stroke-and-distance relief, which means replaying from where you last played (with a new ball) and adding a penalty stroke.
There is a third option for what to do if your ball gets stuck in a tree. Rather than explain it, we'll let Sergio Garcia demonstrate below.