Traditionally temporal phase unwrapping for phase measuring profilometry needs to employ the phase computed from unit-frequency patterned images; however, it has recently been reported that two phases with co-prime frequencies can be absolutely unwrapped each other. However, a manually man-made look-up table for two known frequencies has to be used for correctly unwrapping phases. If two co-prime frequencies are changed, the look-up table has to be manually rebuilt. In this paper, a universal phase unwrapping algorithm is proposed to unwrap phase flexibly and automatically. The basis of the proposed algorithm is converting a signal-processing problem into a geometric analysis one. First, we normalize two wrapped phases such that they are of the same needed slope. Second, by using the modular operation, we unify the integer-valued difference of the two normalized phases over each wrapping interval. Third, by analyzing the properties of the uniform difference mathematically, we can automatically build a look-up table to record the corresponding correct orders for all wrapping intervals. Even if the frequencies are changed, the look-up table will be automatically updated for the latest involved frequencies. Finally, with the order information stored in the look-up table, the wrapped phases can be correctly unwrapped. Both simulations and experimental results verify the correctness of the proposed algorithm.