The function is injective (i.e. one-to-one), that is the principle of an encoding. So no two formula can have the same number. This is guaranteeing by the fundamental theorem of arithmetic: there is only one decomposition of a number in product of primes, and that is what is used by Gödel to do this encoding.
More precisely, each sign of a formula is encoded by a number, so a formula becomes a sequence $(a_1,\dots, a_k)$, and then we map to it the unique number $2^{a_1}3^{a_2}\dots p_k^{a_k}$ where $p_k$ is the $k^{th}$ prime number.