In this paper, a routing algorithm to optimize the selection of the best path for the transmitted data within the Internet of Things (IoT) system is proposed. The algorithm controls the use of ant colony ideas in the IoT system to obtain the best routing benefit. It divides the IoT environment into categorized areas depending on network types. Then, it applies the most suitable ant colony algorithm to the concerned network within each area. Furthermore, the algorithm considers routing problem in intersected areas that may arise in case of IoT system. Finally, Network Simulator 2 is used to evaluate the proposed algorithm performance. Simulation results demonstrate the effectiveness of the proposed routing algorithm in terms of end-to-end delay, packet loss ratio, bandwidth consumption, throughput, overhead of control bits, and energy consumption ratio. that the real IoT system consists of four different networks: WSN, HAP, Mobile Ad Hoc, and RFID. These networks are communicated with each other using the Internet. Each network has its own ACO algorithm. The equations describing different ACO algorithms, which are used in the simulation process, are stated as follows. Equations (1)-(4) represent the general form of the ACO algorithm, while the ACO algorithm for WSN is expressed by Equations (5)-(9). Equations (10)-(17) represent the ACO algorithm for the HAP network. The ACO algorithm equations for mobile ad hoc network are described in Equations (18)-(22). The ACO algorithm equations for RFID network are stated in [37][38][39], and the ACO algorithm equations for the Figure 2. The proposed IoT routing algorithm.