The Enigma machine is an electro-mechanical device. It consists of a keyboard (German QWERTZ layout), a lamp panel, representing the alphabet, and three or four rotors. One or more rotors move on each key stroke. The rotors and plugboard translate the depressed key into a burning lamp, representing the encoded letter. The machine has a compartment for a 4 volt battery. Some versions have a switch to select between internal battery and external power supply. Other versions have a transformer to connect the machine to the AC mains.
The picture above shows the wiring. To simplify the example, only four of each of the components are shown. In reality, there are 26 lamps, keys, plugboard sockets and wiring connections inside the rotors. The current flows from the battery  through the depressed bi-directional letter-switch  to the plugboard . The plugboard allows rewiring the connections between keyboard  and fixed entry wheel . Next, the current proceeds through the - unused, and therefore closed - socket  via the entry wheel  through the cross-wirings of the three (Wehrmacht Enigma) or four (Kriegmarine M4) rotors  and enters the reflector . The reflector returns the current, via a different path, back through the rotors  and entry wheel , and proceeds through the plugboard again and through the plug 'S' connected with a cable  to plug 'D', and another bi-directional switch  to light-up the lamp.
Note that depressing a key will first step the rotors and then the sent the current through the rotors en the light bulb. If the key is released the lamp will no longer light up. Therefore, when no key is depressed, the rotor position of the previous encrypted letter is visible!
The picture below shows the mechanical setup of the Enigma, seen from the right side, with more or less the same wiring diagram as above.
The rotors (Walzen in German) are the most important elements of the machine. These round disks , approximately 4 inch in diameter, are made from metal or bakelite and have a core with 26 spring-loaded contacts  on the right side, scramble wired  to 26 flat contacts  on the left side, with a hollow axle in the center . On the outside of the wiring core there's a movable ring  with 26 numbers or letters and a notch . This ring is rotatable and is locked with a sprinloaded pin (Wehrmacht)  or two springloaded arcs (Kriegmarine) into any of the 26 positions. Changing the position of the ring will change the position of the notch and alphabet, relative to the internal wiring. This setting is called the ring setting or Ringstellung and its position is visible by a dot marking . Each rotor has on its left a notch  and on its right a ratchet . These are used by the stepping mechanism to advance the rotors. The internal wiring is different for each rotor. This wiring represents a substitution encryption. The combination of several rotors, in ever-changing positions relative to each other, is what makes the encryption so complex.
The machine was introduced with three
rotors. In 1939 the set was extended to five rotors,
marked with Roman numerals I, II, III, IV and V, all with
a single notch. The Kriegmarine extended this set of
rotors with another three rotors called VI, VII and VIII,
each with two notches. In 1942, the Kriegsmarine M4
introduced a fourth rotor. To achieve this, the wide B
and C reflectors from the three rotor version were
replaced by thin B and C reflectors, leaving room for the
special fourth rotor. The fourth rotors were of two
configurations, named Beta and Gamma, with spring-loaded
contacts on both sides, making them incompatible with the
other eight rotors.
Important note on the Stepping Sequence
The rotors appear to work as a normal odometer, with the right-most rotor always stepping on each key stroke and the other rotors stepping after a complete cycle of the previous rotor, but there is an important difference due to the system of pawls and teeth. The middle rotor will advance on the next step of the first rotor a second time in a row, if the middle rotor is in its own turnover position. This is called the double-step. Below and example of such a sequence when the rotors III II - I are used:
KDO KDP, KDQ, KER, LFS, LFT, LFU
As you can observe, stepping from Q to R advances the middle rotor, and on the next step that middle rotor steps again, advancing the third rotor also. This is caused by the mechanical design of pawls and ratchets. There are three pawls that are all three activated on every key stroke. Each pawl is half positioned on the index ring (carrying a notch) of the rotor on its right, and half positioned above the 26 teeth of the rotor on its left (viewed from the point of the operator). A rotors ring prevents the pawl from pushing into the teeth of the next-left rotor. When a notch occurs in a ring, the pawl can drop into that notch and push into the teeth of the next-left rotor. Since the right-most pawl is not above an index ring it will continuously advance the right-most rotor.
Once the right-most rotor has stepped and the middle (spring-loaded) pawl can drop down in the right rotor's notch, it will engage the middle rotor's teeth, pushing the middle rotor one step. An identical event will take place when the middle rotor's notch enables the third pawl to drive the teeth of the left-most rotor. A rotor will not only advance if its teeth are catched, but also when a pawl pushes into its notch. This situation creates a double-step of the middle rotor: the right rotor steps and the middle pawl takes the middle rotor one step further. If the middle rotor has moved by this step into its own notch position, then, on the next step, the left-most pawl catches the teeth of the left-most rotor, but the same pawl also pushes in the middle rotor's notch, moving it a second time in a row. Note that a double notched rotor in the middle position will also have two double steps.
The stepping mechanism, as explained above, is used on the Wehrmacht and Kriegsmarine Enigma. The four-rotor Kriegsmarine M4 is derived from the three rotor version without changing the rotor advance mechanism or adding a fourth pawl. Therefore the fourth rotor doesn't move and can only be adjusted manually. The Enigma-G, used by the Abwehr (German Intelligence) has a different mechanism. The Enigma-G has a rotating reflector and three rotors with multiple notches, rotated by a gear box.
To calculate the mathematical security we have to find all possible different settings of the machine. Therefore, we need to look at the following properties of the machine: the selection and order of the rotors, their wiring, the ring setting on each of the rotors, the startposition of these rotors at the beginning of the message, the reflector and the plugboard settings. Now, there are different ways to calculate a grand total of this. In this NSA publication, all possible variations of wiring in each of the rotors and the reflector was included. This results in an astronomical 3 x 10114. However, these misleading figures represent all theoretically possible variations of the machine.
Unfortunately for the Germans, the Allied codebreakers knew the machine, the rotors and the internal wiring of these rotors. Therefore, they only had to take in account the actual possible ways you could set the machine, the actual key settings or key space. This is what we call the practical security, which is far less than the theoretical security in the case of Enigma. For the German cryptologists, a single rotor could be wired in 4 x 1026 different ways. Combining three rotors and a reflector quickly gives you astronomical figures. For the Allied codebreakers, who knew the wring of the rotors, there were only 26 different variations for a single rotor, that is, the 26 positions it could have in the machine. They didn't have to search through the immense number of possible wirings. The German cryptologists made a critical mistake by ignoring Auguste Kerckhoff's law that the security of a device may never depend on the secrecy of the system (i.e. rotor wiring, design), which will be compromised sooner or later anyhow, but only on the secrecy of the key (i.e. rotor selection and plugboard). In the interesting R.A. Ratcliff paper for Cryptologia you can read how dangerous it is to rely on theoritical security.
Let us look at all the things we can actually set in the machine and are unknown to the codebreaker. In our example, we take the three-rotor Wehrmacht Enigma with default B reflector and selection out of 5 rotors. We use 10 plug cables on the plugboard, the default number of cables, issued with the machine (don't ask me why they didn't provide 11 cables, which gave far more possible combinations)
To select 3 rotors out of a possible 5, there are 60 combinations (5 x 4 x 3). Each rotor, in other words its internal wiring, can be set in any of 26 positions. Therefore, with 3 rotors there are 17,576 different rotor positions (26 x 26 x 26). The ring on each rotor holds the rotor labeling (which doesn't matter here) and a notch that affects the stepping of the next-left rotor. Each ring can be set in any of 26 positions. As there is no rotor to the left of the third (most-left) rotor, only the rings of the most-right and middle rotor affect the calculation. This gives 676 ring combinations (26 x 26).
The plugboard provides the largest chunk of possible different settings. For the first cable, one side can have any of the 26 positions and its other side any of the 25 remaining positions. However, since a combination and its reverse are identical (A-B is the same as B-A) we have to ignore all doubles in all possible combinations for one cable, giving (26 x 25) / (1! x 21) or 325 unique ways to set one cable. For two cables, we have (26 x 25) for the first cable and, since two sockets are already used, (24 x 23) for the second cable. We now have to take in account the doubles for two cables, giving (26 x 25 x 24 x 23) / (2! x 22) = 44,850 unique ways to set two cables. For three cables we have (26 x 25 x 24 x 23 x 22 x 21) / (3! x 23) = 3,453,450 combinations, and so on. Thus, with the default 10 cables we have 150,738,274,937,250 different combinations. The formula, with n as the number of cables, is 26! / (26 - 2n)! · n! · 2n
In total, this gives: 60 x 17,576 x 676 x 150,738,274,937,250 = 107,458,687,327,250,619,360,000 or 1.07 x 1023
So, in real life, the Wehrmacht Enigma machine could be set in 1.07 x 1023 different ways, which is comparable with a 77 bit key.
There are some comments we should add to this number. In reality, the maximum period of the rotors - the number of steps before the machine repeats itself - is slightly less than 17,576. This is caused by the double-step feature of the stepping mechanism. The actual period depends on the type of rotor. The three double-notched Naval rotors will have an even smaller period than the Wehrmacht rotors as they produce more double steps of the middle rotor. The maximum period however is no part of the variables that can be set and therefore do not influence the key space. The Wehrmacht machine could be equipped with either the B or C reflector. In general, radio nets always used the same reflector, as the use of different reflectors created logistical, procedural and practical problems. If nonetheless taken in account, the choice between B and C reflector would only double the key space.
The adding of a fourth rotor for the Naval Enigma M4 to improve its security was a nice but useless addition. The non-moving fourth rotor complicated the machine only by a factor 26 and, together with the thin reflector, could be considered as a settable reflector with 26 positions, of which the Allies quickly found the wiring (after 10 months of panic). The introduction of 8 naval rotors on the Kriegsmarine M3 and later on the four-rotor M4 was a far better approach. They increased the rotor combinations from 60 to 336, and brought in additional complexity with 3 multiple notched naval rotors VI VII and VIII.
Let us now calculate the practical key size of the four-rotor Kriegsmarine Enigma M4. This machine uses 3 normal rotors, selected from a set of 8 (of which three with double notches). This gives 336 rotor combinations (8 x 7 x 6). The M4 also has a special fourth rotor called Beta or Gamma (without a ring), which gives us 2 choices. These are not compatible with the other rotors and are only suitable as fourth (most left) rotor. The 4 rotors can be set in any of 456,976 positions (26 x 26 x 26 x 26). The M4 had a smaller B or C reflector, to enable the placement of the fourth rotor. We don't include the choice of reflector as it was generally never changed. Again, only two rings were involved, as the third rotor didn't step the never moving fourth rotor. The M4 was also issued with 10 plug cables.
In total, this gives: 336 x 2 x 456,976 x 676 x 150,738,274,937,250 = 31,291,969,749,695,380,357,632,000 or 3.1 x 1025, comparable with a 84 bit key.
This is about 291 times stronger than the Wehrmacht machine. This is due to the increased choice of rotors (already available on the M3 before the war) and the possible initial positions for 4 rotors instead of 3. However, although the fourth rotor did increase the key size, it failed to add to the complexity of the encryption itself, since it couldn't move during the enciphering proccess. A better solution would have been to completely re-wire some of the rotors on a regular basis. A single variable rotor wiring would multiply the key space with no less than 4 x 1026, which is far more than a settable reflector with its 7.8 x 1012 possible variations. A single practical, daily changed, re-wireable rotor, which has 4 x 1026 possible settings, would have been much more effective than the overestimated daily not-moving plugboard setting with only 2 x 1014 variations (the plugboard was always in pairs). The use of such rotor, for instance in conjunction with a thin M4-like reflector and two out of four normal rotors, would be a true disaster for the codebreakers. However, introducing re-wireable rotors during wartime would be cumbersome and present a logistical and financial nightmare, just as the rewireable D reflector proved to be. Too little too late. The D reflector did scare the codebreakers initially, until they realized that the D reflector was used simultaniously with the default reflectors in the same radio nets, due to practical considerations. This dual use made it possible to break it even by hand. More about the D reflector and other attempts on the Enigma history page.
Any crypto-expert would also discard the 17,576 ring combinations. Even with completely wrong ring settings, you will initially start with a correct plain text. As soon as you get garbled text, you adjust the ring of the most-right rotor (a 1/26 chance you're right) and if you're lucky you have no more trouble for the next 676 characters. If less lucky, you had to adjust the ring of the middle rotor after 26 letters. All done on-the-fly. Unfortunately for the Germans, the ingenious Turing Bombe design, with mirrored identical rotor packs, avoided the need to search through the immense number of plugboard settings, taking a factor 2 x 1014 shortcut on the linking of their cribs (known piece of plain and ciphertext) to a given rotor setting.
Breaking the Enigma traffic was nonetheless an enormous challenge with a key setting that was extraordinary in the electro-mechanical era of those days. An exhaustive search on 1.07 x 1023 settings was impossible in the 1940s and its comparable 77 bit key is even huge for today's computer standards. To give you an idea of the size of that number, with 1.07 x 1023 sheets of paper (0.0039 inch each) you can build roughly 70,000,000 stacks of paper, each of them reaching from the Earth to the Sun. Also, 1.07 x 1023 inches equals 288,500 light-year. A pretty big number! The Germans were correct in assuming that the Enigma was theoretically unbreakable. However, codebreaking is more than keys sizes and numbers, theoretical security and searching for the right combination. More on the how the Allies broke Enigma on this page.