Cloud and Zack were captured by Hojo after the Sephiroth's incident.
Hojo conducted inhuman experiment on them.
Zack managed to break free and also saved Cloud.
Zack managed to withstand the effect of the experiment because he was once a SOLDIER and his mind is also pretty strong. Where else Cloud seem to be in a vegetable state.
Zack told Cloud about his life and everything in a truck when they escaped.
Cloud in a dazed state thought those were his memories and got mixed up.
When they are near Midgar, Shrina Soldiers appeared and killed Zack. The commander thought that Cloud is just a wastrel and there's nothing to worry from him so they spared Cloud.
Cloud later picked up Zack's sword and thought it was his and headed to Midgar where he met Tifa at a train station.

The flashback in Nibelheim five years ago is Cloud playing the role of Zack but actually he is one the two regular Shrina Solidier that went along with the mission.