We were talking until 2 in the morning.

Literal

We [topic-は] midnight [attributive-の] 2-o'clock [until-まで] talking-[past-state-ていた].

夜中 ('middle of the night, late at night') links adnominally via の to 2時 ('2 o'clock'). まで ('until') marks the endpoint of the duration. 話していた is the past progressive, indicating an ongoing action in the past — 'were talking.'