I am a Turkish citizen with a Blue Card living in Berlin and travel from Athens back to Berlin. Flight has a stop in Sofia and I would like to know if I need a transit visa for Bulgaria and I am able to go out of the airport in Sofia during the waiting time.
I assume that you have a multiple-entry Schengen visa, additionally to the Blue Card. According to this EU Blue Card FAQ, you are allowed to visit other EU countries up to three months in any 6-month period. As I assume your stay will be likely measured in hours, you are OK with this Blue Card condition.
Next, the freedom of movement for non-EU nationals applies, as described here.
The borderless Schengen area includes 22 EU countries, excluding Bulgaria, Cyprus, Ireland, Romania and the UK. If you wish to travel to one of these five countries for a short stay (less than three months), you must get a separate national visa.
Which redirects you to Bulgarian national visas, as you will be leaving Schengen on arrival in Sofia. As you can check on the Ministry of Foreign Affairs site here: Visa-free regime for holders of Schengen visas for a stay of up to 90 days
On 25 January 2012 the Council of Ministers of the Republic of Bulgaria adopted a decision according to which by the date of Bulgaria’s accession to the Schengen area, our country will unilaterally apply a visa-free system for holders of valid Schengen visas. They will have the right to enter and reside in the Republic of Bulgaria for a period of no more than three months in any six-month period from the date of the first entry, without needing to have a Bulgarian short-stay visa. The decision entered into force on 31.01.2012.
Which clearly states that your Schengen visa will be honored while entering Bulgaria.
Assuming you have a Schengen multiple-entry visa (edit: or a residence permit like Blue Card), you should be allowed to leave the airport in Sofia using your visa.
If you have only a national (German, I presume) visa,
then you would have to apply for a Bulgarian visa in order to enter their country.
According to this, for the purpose of transit:
No transit visa is required for passage of citizens of third states when they produce any of the following documents:
Schengen (single) visa, long-stay visa, permit for stay issued by any of the Schengen area states;
national short-stay visas, long-stay visas and permits for stay issued by Romania and Cyprus;
permits for stay issued by Lichtenstein. The right of passage without a visa under the transit decisions is applied only and exclusively for the purposes of transit passage.
Assuming you stay in Germany legally
and have a long-stay visa, condition 1 may apply here, allowing you to transit without a separate visa.
edit: As discussed in the comments, Blue Card is a permit for stay, so it also fulfills condition 1 for travelling without a separate visa.
Your blue card entitles you to enter Bulgaria.
User pnuts has asked for a souce. Offical Bulgarian sources I've found only mention Schengen visas, not residence permits, but the likely conclusion is that by visa they actually mean visa or residence permit. Timatic supports this conclusion:
National India (IN) /Residence Germany (DE) Destination Bulgaria (BG)
Visa required, except for Passengers with a residence permit issued by Germany for a maximum stay of 90 days. (SEE NOTE 56110) NOTE 56110: The max. stay is granted within 180 days. Visa required, except for Passengers with a D visa issued by Germany for a maximum stay of 90 days. (SEE NOTE 56110) NOTE 56110: The max. stay is granted within 180 days.
The next question is whether a blue card is in fact a residence permit. As I mentioned in the comments, an image search for eu blue card returned several images showing a German Aufenthaltstitel bearing the annotation BLAUE KARTE EU.
The only question that remains is whether an Aufenthaltstitel is a residence permit, and online translation services indicate that it is. In addition, the appearance of the card conforms to the EU standards for residence permits. Finally, the PRADO database entry for the card indicates that it serves as both a residence permit and a blue card:
AUFENTHALTSTITEL _ NIEDERLASSUNGSERLAUBNIS // NIEDERLASSUNGSERLAUBNIS (Familienangehöriger) // AUFENTHALTSERLAUBNIS // AUFENTHALTSERLAUBNIS (Familienangehöriger) // DAUERAUFENTHALT EG // BLAUE KARTE EU