Narrative:

I had reached my cruising altitude of 7500 ft; 500 ft below the class B shelf that I was flying under. I was visually scanning for traffic when I looked down to scan the instrument panel. When I looked up again; I noticed another plane approaching very quickly from my 2 o'clock position; and from what I could tell; was starting to descend. It looked apparent that they had not seen me; so I put in full power and pitched up so that I would climb above their flight path. The other aircraft continued on their original track underneath me; and when I looked at the altimeter; I was at 8050 ft; in the class B. I immediately pitched down to regain my original cruising altitude of 7500 ft. My mind was preoccupied to the resolution of the issue when it arose; and while I was taking action; I was not thinking about how close I was approaching to the bravo airspace.

Google
 

Original NASA ASRS Text

Title: A C172 Pilot reported inadvertently flying into Class B Airspace after a NMAC.

Narrative: I had reached my cruising altitude of 7500 ft; 500 ft below the class B shelf that I was flying under. I was visually scanning for traffic when I looked down to scan the instrument panel. When I looked up again; I noticed another plane approaching very quickly from my 2 o'clock position; and from what I could tell; was starting to descend. It looked apparent that they had not seen me; so I put in full power and pitched up so that I would climb above their flight path. The other aircraft continued on their original track underneath me; and when I looked at the altimeter; I was at 8050 ft; in the class B. I immediately pitched down to regain my original cruising altitude of 7500 ft. My mind was preoccupied to the resolution of the issue when it arose; and while I was taking action; I was not thinking about how close I was approaching to the bravo airspace.

Data retrieved from NASA's ASRS site and automatically converted to unabbreviated mixed upper/lowercase text. This report is for informational purposes with no guarantee of accuracy. See NASA's ASRS site for official report.