The Bitcoin P2P network
The Bitcoin P2P network is a randomly-wired gossip network. This means that all nodes make arbitrary connections to other peers (using various ways to discover new addresses) using a custom TCP protocol, usually using port 8333. Typical nodes create 8 outgoing connections, and if publicly reachable, accept up to a few 100 incoming connections.
It being a gossip network means that nodes send messages to each other of the form "do you have block with hash X" or "do you have transaction with hash X", after which the peer can respond by asking for the full transaction or block. Simplified, this means that eventually every node learns about every block. The protocol is bidirectional - it doesn't matter who connected to whom; both peers will announce if they have something they don't know the other side already has as well.
Not all network nodes are reachable. Some only make outgoing connections. Sometimes setups are used where someone runs a publicly reachable node, and then runs a second private node that only connects out to their own public node, thereby giving some extra privacy and reduced attack surface.
Not all network nodes validate the blocks and transactions they see and pass on. Nodes that do are called full nodes.
Miners (or at least mining pools) run nodes like this, picking up transactions their nodes learn about, assembling them into candidate blocks, hashing to find a nonce, and if they succeed, broadcast the resulting block out to their peers using the same P2P network. Miners in this way are not special - people don't directly submit things to miners.
Since recently, an extension to the protocol is used to relay blocks much more efficiently, called Compact Blocks. It makes use of the fact that most nodes will already have most of the transactions that are added to a new block.
Specialized relay networks
Additional networks exist of groups of nodes that use specialized protocols to very quickly interconnect nodes. One such protocol is FIBRE, which is in fact UDP based and makes heavy use of error correcting codes to avoid roundtrips.
Electrum
Ironically, Electrum in your question is a bad example. Electrum is not a P2P client (not even a light one). Instead, it uses a client-server architecture, and connects to specialized servers (which are themselves Bitcoin P2P nodes however).
Thanks for the detailed explanation! What about the online block explorers? Can it be done on client side? – Balázs Sáros – 2018-01-03T17:09:03.987
I don't understand the question. – Pieter Wuille – 2018-01-03T17:13:00.037
Oh, nevermind. Block explorers do everything on the server side. – Pieter Wuille – 2018-01-03T17:17:27.400
I see, thanks! Could you please include it in your answer because I addressed it in the question and someone may look for the info in your answer? – Balázs Sáros – 2018-01-03T17:19:58.080
1Perhaps it's better to move that to a different question; usually you shouldn't ask multiple questions in one thread (as it hurts searchability of answers). I think I could answer the other ones nicely together, but blockexplorers seem pretty unrelated. – Pieter Wuille – 2018-01-03T17:29:16.277
Ok, then I'll remove it from the question. I included it because I thought there was a way to communicate with the blockchain from a webpage directly (which turned out the be not the case) and so it fitted with other questions. – Balázs Sáros – 2018-01-03T17:32:09.523
So my full node makes the 8 outgoing connections but I've never seen more than ~20 incoming connections. Certainly not a few 100. Do I stink? Or maybe it's because I'm on an rather slow connection - 75 down/15 up - and the other nodes detect that? (The machine itself isn't slow or under load so I don't think the machine would be contributing to latency ... just the network connection itself?) – davidbak – 2018-01-03T23:52:34.727
(Or maybe it's a config setting I forgot about ...) – davidbak – 2018-01-03T23:59:29.547
@davidbak I said "allow up to". If every node makes 8 outgoing connections, on average each will only have 8 incoming connections too. Many nodes only make outgoing though, pushing the number of incoming connections somewhat higher on those that do support them. But in general, no, 20 incoming connections is very healthy. It's only nodes that are fast and reliable and up for very long periods of time (months or more) that gather 100s of connections. Note that more connections is not in any way better for you - once above a certain number, they just slow you down. – Pieter Wuille – 2018-01-04T06:41:38.423