Many advanced applications of X-ray free-electron lasers require pulse durations and time resolutions of only a few femtoseconds. To generate these pulses and to apply them in time-resolved experiments, synchronization techniques that can simultaneously lock all independent components, including all accelerator modules and all external optical lasers, to better than the delivered free-electron laser pulse duration, are needed. Here we achieve all-optical synchronization at the soft X-ray free-electron laser FLASH and demonstrate facility-wide timing to better than 30 fs r.m.s. for 90 fs X-ray photon pulses. Crucially, our analysis indicates that the performance of this optical synchronization is limited primarily by the free-electron laser pulse duration, and should naturally scale to the sub-10 femtosecond level with shorter X-ray pulses.