Birkat Hagomel: The Blessing of Thanksgiving

The blessing
Baruch ata Hashem, Elokenu Melech HaOlam, Hagomel lachayavim tovot,
shegemalani kol tov.  He who has bestowed upon the undeserving good
things, who has given me all good things.

Response from listeners
Mi shegmalach (for a man, Gemalcha), kol tov, hu yigmalech (yigmolcha) kol tov selah. He Who Has bestowed upon you good things should always bestow upon you good things.

Talmud Berachot 54b: Rabbi Judah said in the name of Rav: 4 must give
thanksgiving; those who go down into the sea, walk through the deserts,
one who was sick and was healed, and one who was captured in the jail
and got out. (HAYIM: Holeh, Yam, Yisurin, Midbar) Based on Psalm 107.
Hayey Adam: it is like a sacrifice of Thanksgiving

With a minyan, with a bracha
If not in a minyan, without a bracha

Within three days, if possible. Otherwise, best within 30 days, or whenever.

What about women?
Mishna Berurah (Chafetz Chaim):
1) ten women plus one man is a possibility,
2) the custom is for women not to make the blessing,
3) and a husband can make it for his wife "who has given to you, asher
gemalach" and she should answer amen
4) or let him say, "who has given to my wife, asher gamal le-ishti"
Aruch Hashulchan: the third party must care about the person a lot. The
minhag is not to use third parties.
Hayey Adam: Women should also do so in front of ten.
Aruch Hashulchan: women don't say it and there is no reason for this,
maybe because it is during torah is right that they should.
Rabbi Hayim David Halevy: the custom is not for women to do it, and so
it is fitting, even though they are obligated.
Rav Ovadya Yoseph: let her do it at a party or at Torah reading

For what occasion?
The four cases mentioned above.
Shulchan Aruch: These four are not the only ones but someone to whom a miracle happened that a wall collapsed on him or was saved from the attack of an ox, or was saved from robbers should also say it. Some say only these cases, and it is good to do so without G-d's name. 
Mishna Berurah: we follow the first approach.
Sepharadim do not say Hashem's name for other dangers.  Sepharadim do not allow one to bless for another
Rav: Danger is subjective. One could say it over air travel. He didn't.  After a serious accident, of course one would.
Rav Feinstein: boats and air is always dangerous, it is not the human element.
Rav Yoseph: the flight must be at least 1:15 minutes. If in one day the trip back and forth is 1:15 he also may say it.
Rav Aharon Soloveitchik: for car travel, even across the USA, no blessing.
Sick means that you were in bed for at least three days. 
Aruch Hashulchan; out of jail only if he comes out clean.
Mishnah berurah: if the jail was dangerous or if he was saved from the death penalty. Some say any exit from jail is included due to the lack of freedom.