How a transistor works?
These days, more than 99% of transistors in active use are operated by another transistor.
Simplified one could say that just about any integrated circuit is made up of transistors doing various things.
A transistor isn't really a switch, the one you refer to, a Bipolar Junction Transistor, is a current amplifier. But, put that aside for now, just know they don't really switch, but that in many my-first-schematic designs they can be seen as a switch because you are allowed to ignore the tiny bit of behaviour that makes it not exactly that.
So in the following we are going to assume the transistor actually is a switch, which switches the current path between its collector and emitter on when a current flows in the right direction through the base. Because I'm going to take some care in my images to make sure that assumption will work.
A transistor:



simulate this circuit &ndash; Schematic created using CircuitLab
It's a single NPN type transistor. There's two types: NPN and PNP, they work almost entirely the same, just the PNP has the currents flowing the other way around. Again, for now, ignore PNPs exist, no running before walking, we only know NPN.
Let's make it do something: Let's let it control a LED. (feel free to go along with this, if you happen to have a bread-board handy, by the way).



simulate this circuit
The LED is pink, because pink LEDs are cool.
Now, if the transistor turns on, the LED will turn on: In an NPN transistor no current is &quot;allowed&quot; to flow from the collector to the emitter if the base is not activated. If the base is activated, the current will be allowed to flow and the transistor would really like it if you designed it so the current goes from collector to emitter in an NPN type.
How do we activate the base? By forcing a little current into it. So, step one, let a human control the base:



simulate this circuit
When you push the switch, the current goes from the +5V through R2 into the base of transistor Q1. Then the collector will allow current to flow to the emitter, because the LED will also want to conduct current in that direction, the LED will now turn on.
Now, this is about where you get stuck: What if &quot;I&quot; don't want to push a button?
Well.... we could have another transistor in there:



simulate this circuit
But... same difference! Now we just have another base to control!
Yes.
But;
It's already become more interesting! Imagine our switch back into that circuit, but now connected with another 10k resistor to the base of Q2. If you push the switch, Q2 will turn on, right? Right! Now, the base of the Q1 will be pulled to ground, because the Q2 will happily conduct enough current to have nearly all of the 5V fall across the R2. So Q1 will actually turn off. So when you push the button the LED goes off. If you release the button, Q2 will turn off. Which will let the current from R2 flow into the base of Q1 in stead of into the collector of Q2. Now Q1 will turn on and the LED will turn on.
This behaviour we summarise with the name &quot;Inverter&quot;.
What's more than 2 transistors? 3!



simulate this circuit
Can you see that when you push switch SW1, Q2 will turn on and everything will be as we said just now? Can you also see that the same will happen when you press SW2? SW2 turns on Q3, then Q3 pulls the current into its collector and it will not go into Q1, so Q1 will be off. If you push no switches, the current through R2 will be able to go into Q1 and turn it on. If you push both switches, Q2 and Q3 will find a way between them to share the current through R2 and again Q1 will go off.
so if you press SW1 OR you press SW2 OR you press both, the LED will go off, else it will go on.
If you consider the LED's light as the output we call this an OR-gate with an inverting output.
Can you see where this is going? If transistors can control each other when they are used as a switching element, we can start to build logic gates.
In the same way:



simulate this circuit
Is another type of logic gate.
If you press neither button, the LED will be on. If you press only SW1 the base of Q2 will want to take the current and Q2 will then want to conduct, but it cannot, because Q3 isn't conducting, so nothing happens.
If you press only SW2, the base of Q3 will be able to take some current, it will then allow current to go from its collector to the emitter, but Q2 is now turned off, so again, no current can flow and the resistor R2 keeps turning on Q1, so the LED stays on.
If you now press SW1 and SW2, both Q2 and Q3 will want to conduct, because there is no more obstruction, the current from R2 can flow through both Q2 and Q3 to ground and will not go into Q1's base, so Q1 will turn off.
This is called an AND-Gate with inverting output.
Now we can start using the gates we just &quot;invented&quot; and several other ones to build other bigger blocks. We know how gates can work, so we can take it one step further. Imagine the switches are inputs and the LED is an actual electrical output and you pretty much have a working gate. In &quot;the real world&quot; they are designed much more efficiently for lower power, higher speed and such, but the idea in broad lines is the same.

From here some technical details may go over your head. I will try to explain as best I can in the limited space I have here, but if you don't understand the specifics of how everything works, it's okay to just assume that what I say/conclude is as-is. The general idea of how to build up complex things stays unchanged by your understanding;

Let's make something with gates:



simulate this circuit
This looks very scary, doesn't it? But I want to start wrapping it up a little, so I made a little jump, but I will explain.
The ones labeled &quot;XOR1&quot; and &quot;XOR2&quot; are called Exclusive OR. They work a bit like an OR, but with one difference: Their output is only 1 if their inputs are different, i.e. 0 and 1. If they're both 1, the output is 0. If both inputs are 0, the output is 0 as well. This port is also made of transistors.
The AND3 and 4 are AND gates. But these have no inverting output. When both inputs are 1, the output is 1, in all other cases the output is 0.
OR1 is a normal OR port, if either input is 1 the output is also 1. If both are 1, the output is 1 as well.
Let's see what happens. The labels in the schematic already give it away a little, but we are going to walk through it anyway.
If the Carry in is 1, and the others are 0:
Both inputs of XOR1 are 0, so its output is 0 as well. Both inputs of AND3 are 0, so its output will be 0. One input of AND4 (the output of XOR1) is 0, so the output of AND4 is also 0. Both AND3 and 4 are zero, so the output of OR1 will be zero too: Carry Out is zero.
One input of XOR2, the output of XOR1 is 0, the other input to XOR2, the Carry In, is 1. So its output is 1, so the Sum output is 1.
If only one of A or B is 1 and Carry In is 0:
The inputs of XOR1 are different, so its output is 1. The Carry In is 0, so the inputs of XOR2 are different as well, so its output is 1. The Sum Out is 1.
The Carry In is 0, so one input of AND4 is 0, so its output is 0 as well. Either A or B is zero (doesn't matter which), so AND3 has its output 0 as well. Both inputs of OR1 are 0, so its output is 0 as well. Thus the Carry Out is 0.
If Both A and B are 1 and Carry in is 0:
If both A and B are 1, the inputs to XOR1 are the same, so its output is 0. The Carry In is 0 too, so Both the AND4's output and XOR2's output have to be 0. Sum is 0.
Since both inputs are 1, AND3's output is 1. So now one of the inputs to OR1 is 1, so its output must be 1 as well: Carry Out is 1.
If Both A and B are 1 and Carry in is 1:
Both inputs to XOR1 are 1, so its output must be 0. Carry In is 1, so XOR2 has one input 1 and another 0, so its output must be 1. Sum is 1.
Since both inputs are 1, again AND3 has its output 1. Even though the output of AND4 is 0, because one of its inputs is 0, the 1 at the output of the AND3 goes into OR1 and the output of OR1 is 1 as well. The Carry Out is 1.
If every input is 0:
If all inputs are 0, the output of XOR1 must be 0, because both its inputs are. The Carry In is 0, so XOR2 has two 0's in as well, making it have a 0 on its output: Sum is 0.
Because all inputs are 0, each AND gate has at least a 0 on the inputs, so both have 0 on their outputs as well. If both outputs of the AND gates are 0, the OR1 gate has two 0's on its inputs, so it will have a 0 on the output. Carry Out is 0.

What does that mean? Let's look at the results:

A = 0; B = 0; C-in = 0 --&gt; S = 0; C-out = 0;
A = 1; B = 0; C-in = 0 --&gt; S = 1; C-out = 0;
A = 0; B = 1; C-in = 0 --&gt; S = 1; C-out = 0;
A = 1; B = 1; C-in = 0 --&gt; S = 0; C-out = 1;
A = 0; B = 0; C-in = 1 --&gt; S = 1; C-out = 0;
A = 1; B = 0; C-in = 1 --&gt; S = 0; C-out = 1;
A = 0; B = 1; C-in = 1 --&gt; S = 0; C-out = 1;
A = 1; B = 1; C-in = 1 --&gt; S = 1; C-out = 1;

This is what we call a 1-bit full-adder. If both numbers are 1, it will &quot;overflow&quot; into the Carry output. If you imagine the Carry Out to be 1 bit more significant the output then becomes 2. If the carry input is high, it means another block below it had an overflow, so that signal gets added. If both inputs are 1 and the carry is 1 as well, all outputs become 1, so it says &quot;my value is 1, and the next one is 1 higher as well&quot;. This is how adding binary numbers of any length is done: You couple carries together. So with our 1 bit full-adder, by stacking it, we can make a much bigger many-bit adder, like this:



simulate this circuit
This adds 4bit number 1 to 4bit number 2 to create a Sum output. The first carry is tied to ground for a 0, because the lowest bit needs no carry input. Of course this block has a carry output as well.
That means that you can repeat this block again, for example 8 times and get a 32 bit adder.
Now you have made a super useful block for a computer by connecting transistors to other transistors and then connecting the blocks they make together to get a larger block and then you tie those together to get the 4bit Adder and then you use those blocks to create a 32bit Adder that a 32bit processor could use to add numbers for you.
If you then do the same trick for a block that can multiply and can divide and can shift all bits one up or down, then it won't take long to see that you can make all the mathematical and logical functions a modern 32bit processor would need, or even a 64bit one.
And then you are full circle: We have thousands to millions to billions of transistors connected to each other, all in small groups performing relatively simple tasks, all put inside a tiny little block and what do they do? Wait for you to press keys on a keyboard, and when you do they do maths for you. Of course there's a little programming in between to control which numbers get used how and when and for what purpose, but that's just an intermediate layer.
So then you have a computer, thrown in some software that controls the numbers that go left and right. Then you can take it further: You can group a bunch of computers and you get a (redundant) server park. If you then connect them to other groups of servers you get the internet that can connect to home computers.
Throw in 70 years of weird nerds making groups of commands that make up software in various different layers and pah-dam: Stackoverflow --&gt; StackExchange --&gt; EE.SE --&gt; This Answer.
All made possible in the beginning by one single transistor.

TL;DR Concluding:

By grouping transistors that control each other, we can make logic functions like OR, XOR and AND.
With those logic gates you can then make an Adder.
That adder can then go into a group with a multiplier, divider, shifter and other such functions to make an macro-unit that does maths and logic.
If you then add a way to move the numbers around and some memory, which can be of many types, some are made mostly of transistors, some, like a hard-disk use magnetic fields to store bits in stead, you can run programs on it.
Some smaller controllers you can then program to make their outputs go high or low, which in turn can control another transistor that can actually drive some power, and this transistor can then turn on that LED, just like in out first example.