Quantum computational algorithms exploit quantum mechanics to solve problems exponentially faster than the best classical algorithms. Shor's quantum algorithm for fast number factoring is a key example and the prime motivator in the international effort to realize a quantum computer. However, due to the substantial resource requirement, to date there have been only four small-scale demonstrations. Here, we address this resource demand and demonstrate a scalable version of Shor's algorithm in which the n-qubit control register is replaced by a single qubit that is recycled n times: the total number of qubits is one-third of that required in the standard protocol. Encoding the work register in higher-dimensional states, we implement a two-photon compiled algorithm to factor N = 21. The algorithmic output is distinguishable from noise, in contrast to previous demonstrations. These results point to larger-scale implementations of Shor's algorithm by harnessing scalable resource reductions applicable to all physical architectures.