A gateway is a device that is used to connect totally dissimilar networks. Gateways handle messages, addresses and protocol conversions necessary to deliver a message from one network to another. They offer the greatest flexibility in internetworking communications. Gateways potentially operate in all seven layers of the OSI model. A gateway is a protocol converter. A router by itself transfers accepts and relays packets only across networks using similar protocols. A gateway, on the other hand, can accept a packet formatted for one protocol and convert it to a packet formatted for another protocol before forwarding it.
A gateway is generally software installed within a router. The gateway understands the protocols used by each network linked into the router and is, therefore, able to translate from one to another. In some cases, the gateway modifies only the header and trailer of the packet while in other cases, the gateway must adjust the data rate, size and format as well.
Transport gateway makes a connection between two networks at the transport layer. Application gateway connects two parts of an application in the application layer. When a gateway is between two WANs run by different organizations, possibly in different countries, the joint operation of one workstation-class machine can lead to a lot of finger-pointing. The gateway is effectively ripped apart in the middle and two parts are connected with a wire.
Each of the halves is called a half-gateway and each one is owned and operated by one of the network operators. The whole problem of gatewaying then reduces to agreeing to a common protocol to use on the wire, one that is neutral and does not favour either party.