From the Magnification Wikipedia page, I have the following equality:
M = di/do = f/(do – f) = (di – f)/f
with M the magnification, f the focal length, do the distance from the subject to the lens, and di the distance from the lens to the sensor.
So, when the magnification is 1 we should have di = do = 2f.
With my macro lens (EF 100mm f/2.8 L IS USM Macro), the minimum working distance (from subject to sensor) is 30cm, at this distance the magnification is 1. From what I unsderstand from the formula, this distance should be di + do = 4f = 40cm.
So I think I missing something, can someone explain where I'm wrong?
first of all, kudos on your effort to break a photography problem down to first principles.
The discrepancy you've observed stems from a common oversimplification. Your 100mm Lens is actually what optical engineers refer to as a "lens assembly" As you likely know, it is comprised of multiple lens elements in groups working in tandem to form, refine, and transmit the image seen by your imaging sensor.
If your 100mm lens assembly consisted of a single 100mm lens element you would have massive distortions and only red, green, or blue could be in focus at a time but the thin lens magnification equation you'd linked would hold true. Magnification of 1 would be achieved when the subject is 200mm from the nodal point and the lens assembly would need to be physically greater than 200mm in length. Even then, this would only be strictly accurate to the extent which the thin lens equation is appropriate (and it is not particularly appropriate here.) A proper answer would come from a derivation of the lensmaker's equation
A corollary of the difference between an assembly and a thin lens is bilocated nodal points. A thin lens has a single location for both the front and rear nodal points; Both are collocated with the entrance pupil. If this were true of your lens assembly you would be able to free-lens by rotation around your lens' aperture without any parallax to the subject or sensor. I'm sure if you tried this with the 100mm macro you would find that its not true. A thick lens has two nodal points which are only collocated if its net index is 0, I.E. it has no focal length. A lens assembly can be approximated by a virtual thick lens with two idealized indices such that the virtual lens has the same vertices, relative focal lengths, entrance pupil, and (saliently) nodal points as the lens assembly.
For extra credit, you could check the description of a compound lens and try to guess which combinations of lens focal lengths would create the situation you've described. NB the "telescope magnification." This is essentially what a lens designer does.
For additional reading you can check out the different types of photographic lens designs
The equation assumes a simple single element lens that is bilaterally symmetrical. The camera lens, to mitigate the 7 major aberrations (shortcomings that degrade) is constructed using several individual glass lens elements. Some are positive in power, some with negative power. Some are air-spaced apart and some are cemented together. Because this array becomes quite complex, the point from which we measure focal length will likely be shifted away from the physical center of the lens barrel.
In a true telephoto design, the rear nodal (measuring point) is shifted forward. This action shortens the length of the lens barrel making the camera plus lens less awkward to hold, use, and store. In some designs, the rear nodal can actually fall in the air ahead of the lens barrel.
As the equation states: at unity (magnification 1), the subject distance is 2 focal length lengths forward and the back focus is 2 focal lengths behind the rear nodal. The problem is --- you can’t easily locate the rear nodal. However, once magnification 1 has been achieved, you can now measure the distance subject–to-image. Many cameras provide a symbol (circle bisected with a line) on the camera frame; to locate the position of the image plane.
In any event, measure distance subject-to-image and divide by 4. This division reveals the focal length. Divide by 2 and this division locates the rear nodal point. Now you are better equipped to utilize the “lens maker’s formula”.
Most fixed focal length lens focus by changing their focal length in addition to moving the lens's nodal point(s). To focus on an object close to the camera, the lens reduces its focal length. A lens specified as "100 mm" is usually "100 mm when focused at infinity", but not necessarily so when focused on a close object.
Working distance is measured from the front of the lens to the subject. For your EF 100mm f/2.8 L IS USM Macro lens the working distance at minimum focus distance (MFD)/full magnification is approximately 133mm.
Focus distance is measured from the subject to the imaging plane (film or sensor). For your EF 100mm f/2.8 L IS USM Macro lens the focus distance at full magnification/MFD is 300mm.
Most lenses' focal lengths are measured when the lens is focused at infinity (and then rounded to the nearest "standard" focal length). As focus distance is reduced, the angle of view provided by the lens often changes. This is what is know as focus breathing. The 300mm MFD of your EF 100mm f/2.8 L IS USM Macro reveals to us that the effective focal length at 1:1 magnification is about 75mm. This is fairly common for a Macro lens with focal length in the 90-105mm range. The Tamron 90mm f/2.8 Di VC USD Macro (F017), for instance, also has an MFD of 300mm at 1:1 magnification.
Additionally, focal length for a compound lens is approximated from the focal length a single lens would need to be to provide the same amount of magnification. A compound lens is a system of several lenses, usually arranged in groups, that together act as a single lens. Pretty much every commercially available lens for interchangeable lens camera systems are compound lenses. Your EF 100mm f/2.8 L IS Macro has 15 lens elements arranged in 12 groups.
For most wide angle lenses which have a retrofocus design, this theoretical simple single lens point is well behind the front of the lens. For telephoto lenses this point is, by definition, in front of the front of the lens.
When focused at the 300mm minimum focus distance (MFD), the front of your EF 100mm f/2.8 L IS USM Macro is about 168mm in front of the sensor. But the field of view and magnification provided by the lens at MFD makes it effectively a 75mm lens at that focus distance. This means a simple 75mm lens would need to be at 150mm in front of the sensor (which also places it at 150mm away from the subject) for 1:1 magnification. This places the effective center point of your EF 100mm f/2.8 Macro about 18mm behind the front of the lens when focused at the MFD.
So I think I missing something, can someone explain where I'm wrong?
When applying formulae such as those in your question, you need to use 75mm for the lens' focal length when it is focused at MFD.
There are two reasons why the subject-to-image distance is not 40 cm at unit magnification:
Which of these reasons is the most important is impossible to tell without detailed information on the optical design of the lens.
The value “100 mm” written on the lens itself is a nominal focal distance, which is normally a rounded value of the real focal distance when the lens is focused at infinity.
Some lenses, usually called “unit focusing” lenses, achieve focus by moving the optical assembly as a whole. These lenses have a focal distance which does not vary with focusing. However, many complex lenses, including virtually any modern macro lens, have some sort of “close range correction” (in Nikon parlance): their optical formula changes as you focus, which enables better correction of aberrations. These lenses have a focal distance which varies as you focus.
These two facts: the rounding of the nominal focal length and the fact that it varies when you focus, mean you do not know what the actual focal length of the lens is at unit magnification.
The Wikipedia page you cite defines do and di as the distance from the lens to the object (resp. image), but note that these definitions appear in a section that is specifically about thin lenses. Your lens being a thick compound lens, this begs the question of the applicability of the formula.
It turns out that the thin lens approximation is not applicable in this situation. However, the formula is still valid if interpreted in the context of the thick lens model. In this model, the plane of the thin lens is replaced by two planes, which are called “principal planes”:
These are conjugate planes with unit magnification. In the figure below (source), they are the vertical planes that go through H1, N1 and H2, N2:
Note that this way of describing an optical system in terms of its cardinal points (the Fi, Hi and Ni above) is also applicable to compound lenses. See for example this old drawing of a telephoto lens (source) where both principal planes (the vertical planes through Ni and No) are on the left side of the leftmost element:
Thus, your formula is still valid provided you define:
This gives the subject-to-image distance as
do + e + di = 4f + e
at unit magnification, where e is the (possibly negative) distance between the principal planes. Note that the thin lens approximation essentially says that the principal planes are coincident (e = 0), but it is not applicable to your case.
For more info about this topic, you can take a look at:
I wrote this answer mostly to help clear a popular misconception, which appears in some of the answers here, including the one you accepted: that a photographic lens is equivalent to a thin lens.
It turns out that in most photographic situations (basically all non-macro situations), the subject-to-lens distance is much larger than any characteristic distance of the lens itself. In such situations it doesn't really matter which reference point you use for measuring the distance to the subject. It is then convenient to forget about the distance that separates the principal planes and consider that the rear principal plane is the only one that matters. This is equivalent to setting e = 0, which is basically the thin lens approximation.
Sticking to this approximation makes learning optics a lot simpler, as you don't need to understand notions such as principal planes, principal or nodal points, object space, image space, and so on. Considering that:
it is understandable that the thin lens is the model most commonly taught to photographers. And yet the approximation breaks when dealing with a complex thick lens at macro distances. The answers that tell you that the focal distance is one quarter of the subject-to-image distance illustrate how this misconception leads to people posting wrong answers.