The photographic lenses, and the human eye itself, can be modeled after a very simple device: the pinhole camera.
A pinhole camera is a "camera obscura" with internal walls painted matte black. In the front, there is a small hole (the smaller, the better) and the inner bottom wall is covered by some sort of sensitive material, like a film or a sensor.
The pinhole must exist so every point of the sensitive layer receives light from a single point of the scene. Bigger holes mix more points of the scene, reducing sharpness, until the extreme situation of an exposed film without any enclosure — it registers just a continuous smear.
Accordingly to the depth and the width of the pinhole camera, the film will reproduce a different angle of view: wider or narrower.
The depth of the pinhole camera is called focal length. The bigger the focal length, the bigger the magnification and the narrower is the angle of view of the captured scene.
The absolute angle covered by a given focal length also depends of the dimensions of the film. For the traditional 135 ("35mm") film, a 50mm lens covers 40 horizontal degrees, and 50 diagonal degrees.
Cameras use glass lenses with multiple elements, not pinholes. But a 43mm lens offers a magnification equivalent to a pinhole with physical depth of 43mm. The lens does not need to have exactly 43mm of length. It is a theoretical equivalence.
In the photographic jargon, a lens or a pinhole whose focal length is similar to the diagonal width of the film is called "normal", since the projection of the scene looks the most natural. Higher magnifications are called "teles" and smaller ones are called "wide angle".
The pinhole camera is extremely simple but offers a very good scene projection, called rectilinear. In this projection, all straight lines of the scene are represented as straight lines on the picture, regardless of direction. Almost all lenses are also rectilinear, that is, they follow the pinhole projection.
The rectilinear projection is normally the most pleasant and natural to the viewer. Its distortion decreases as the focal length increases. The distortion is still small for "normal" angles of view, around 50 degrees.
But, for wider angles of view, the rectilinear distortion becomes more and more apparent.
In the figure above, two objects are equally distant from the pinhole, but the object at the left is distorted and will look bigger on the picture.
Why this happens? Well, every projection presents some sort of distortion. The rectilinear distortion is analog to the distortion found in Mercator charts, where Greenland looks bigger than Brazil just because the first is nearer the Pole.
In the case of Figure 4 the effective focal length is much bigger for objects at the side than for objects exactly in front of the camera. So, the diagonal magnification is bigger, and increases with angle of view.
In the extreme limit, an object seen from 90 degrees left or right of the pinhole would have infinite size on the picture! Of course, this is not possible since the width of the camera is finite. The angle of view of a pinhole is always much smaller than 180 degrees (90 degrees for each side).
The rectilinear distortion can be a boon. In the case of Figure 3 objects left or right of the pinhole are also more distant. The increase in distance is compensated by increased magnification, and the result is a pleasant picture with all objects having the same size.
An important limitation of rectilinear projection is being uncapable of registering ultra wide-angle landscapes. A possible solution is to use a pinhole camera with a curved bottom, that generates a cylindrical projection:
In this case, the focal length is the same for the whole angle of view. Such "landscape" or "panorama" cameras have been built, some could even reproduce 360 degrees of view without distortion (horizontal distortion, that is). Many digital cameras simulate this feature by panning, there is software that stitches together a series of narrow-angle pictures, etc.
Of course, the rectilinear distortion still exists in the "panorama" camera, but only in vertical axis. Typical pictures have a narrow vertical angle of view, so this distortion is seldom an issue.
There is another method to increase the angle of view of a camera: bend the light rays as they enter the pinhole, as if the camera were full of water:
In the above model, objects seen 90 degrees left or right of the pinhole are projected on the film. The position of each object on the film is linearly proportional to the angle. This is the "fisheye" projecton. It was believed that fish eyes worked that way, hence the name.
Fisheye lenses are very good to capture the "whole" of a scene, but its projection is generally deemed unpleasant. In a scene like Figure 3 the objects more distant from the pinhole would be "compressed" on film, since the difference of angle between objects gets smaller and smaller as we look farther to the left or to the right.
At the picture center, the rectilinear and fisheye projections are similar, and magnification is proportional to focal length in either case. The focal length of the fisheye refers to the center of the projection where it can be directly compared to a rectilinear lens. At the corners, focal length does not mean much, since a rectilinear lens would have to have a null focal length to shoot a 180-degree picture.
The ideal pinhole camera would have an infinitely small hole. The smaller the hole, the bigger the sharpness, until the limit of light diffraction (that also affects glass lenses). Such a small hoje poses a problem: too little light enters the camera, and the picture takes forever to be shot.
Sometime around the Middle Ages, someone found a solution: use a glass lens instead of a pinhole.
The lens has the same role as the pinhole: each point of the scene is projected onto a single point of the film. The difference is the lens admits much more light (and suffers less with diffraction, as we will see).
The pinhole does not need to be focused, since (ideally) it only admits a single ray of light for each point of the scene. A lens needs to be focused because the angle of light rays emanating from a point will change accordingly to the distance. (Light rays from very distant points, "at infinity", are parallel, with zero angle.)
The majority of lenses is spherical, since spherical glass elements are easier to manufacture. The ideal glass element that replaces a pinhole has a more complex surface, and the best lenses indeed have one or more non-spherical ("aspherical") elements.
Naturally, the quantity of light admitted by a lens bears some sort of proportion with its diameter. The bigger the diameter, the bigger the aperture area, and more light can enter the camera. But luminosity also depends (inversely) on magnification. A lens with high magnification/big focal length projects a smaller angle on film; the rest is projected on the blackened side walls and (ideally) absorbed.
For the same reason, the convention is to represent aperture as a fraction, e.g. f/2, f/4, etc. because this allows to compare luminosity of lenses with dissimilar focal lengths.
For example, a lens with 25mm diameter and 50mm focal length is called f/2, since the first figure is half of the second. If this lens had 50mm diameter, it would be f/1, and it would be four times as bright since the area of the lens aperture goes 4x when diameter doubles.
On the other hand, if the 25mm diameter lens had a 200mm focal length, it would be f/8, and it would be 16x darker than the f/2 lens. The magnification was increased only four times (from 50mm to 200mm) but since the magnification affects two dimensions (width and height) the dillution of light is quadratic (4x4=16).
The "f-number" aperture is only a practical rule, it is not a fundamental physics law. The light power emanating from a scene is finite, and an f/0 lens won't change that.
As said before, the advantage of a pinhole camera is to be permanently on-focus. Leaving out the diffraction problem for a moment, the only limit of sharpness of a pinhole camera is the diameter of the hole.
On the other hand, a lens has perfect sharpness only at the distance for which it is focused. Points that are out-of-focus are projected on film as circles — called "circles of confusion".
The bigger the absolute diameter of the lens (regardless of "f-number") and/or the bigger the focus error, the more blurred will be the picture. (The circle of confusion of a pinhole camera has a fixed size: it is the diameter of the hole multiplied by the magnification of the focal length.)
By the way, this is a practical measure for people that like to take portraits, or pictures with a very blurred background: calculate the absolute aperture size. For example, a 50mm f/1.4 fixed lens and a 55-200mm f3.5-5.6 zoom. Both have the same absolute aperture: 35.7mm (50/1.4 or 200/5.6). Both lenses have the same capability of "blurring" the out-of-focus parts of a scene. The zoom has some advantages: more versatile and cheaper, but the subject must be further away to be projected with the same size on film, since 200mm is almost a telescope.
Since the resolution of film or sensor is not infinite, and the lens is not perfect even when on-focus, circles of confusion below a certain threshold are not seen as blur. There is a tolerance margin called depth of field: a range of distances around the focus plane, in which the scene looks "perfectly" sharp, given the sharpness limits of a system (lens + camera + sensor).
The depth of field depends on many factors, including the print size. In practice, the "pixel" is often estimated as 0.025mm on film for the usual film, sensor and print sizes. Any circle of confusion smaller than that is nil for all practical purposes. Some photographers argue for a more stringent estimation of depth of field for modern digital cameras.
Cameras with smaller sensors (pocketables, cell phones, "superzooms", camcorders) use lenses with shorter focal lengths, and achieve an acceptable aperture with a small absolute diameter. Due do this, such cameras have a deeper depth of field given the same angle of view. This can be an advantage (more of the scene looks sharply focused) or a disvantage (less artistic freedom).
In order to squeeze the highest sharpness, the recipe would be to imitate the pinhole camera, using the tightest aperture possible (biggest f-number), increasing the depth of field. But then we bump on diffraction.
The sharpness of a pinhole camera is limited in two ways. On the one hand, the hole must be the smallest possible, reducing the "circle of confusion". On the other hand, the smaller the hole, the stronger is the effect of diffraction.
For each focal length, there is an "optimum hole" that achieves the maximum resolution possible. Pinholes wider or narrower than the optimum will rob sharpness.
Likewise, the diffaction affects lenses, creating "diffraction circles" for each point of the scene, even if focus is perfect.
The difference is, a lens can reduce the effects of diffraction by using wider apertures (smaller f-numbers). This is the second big advantage of a lens over a pinhole.
The sharpness of a lens is limited in three ways:
The optimum for the present formats (35mm/full-frame and APS-C) and current lenses lies between f/5.6 and f/8, even though images good for print can be generated by lenses closed down to f/16 or f/22. The photographer should not hesitate to "stop down" a lens if she needs more depth of field.
It is important to note that diffraction is proportional to the f-number, and does not depend on focal length. Two dissimilar lenses (e.g. 50mm and 400mm) have the same diffraction performance if they are in the same aperture (e.g. f/4).
Diffaction is the biggest "villain" of small-sensor cameras. It is the limiting factor of resolution. To mitigate the problem, good phone cameras have fixed and wide apertures (e.g. iPhone 6 is f/2.2, iPhone 11 is f/1.8). Compact cameras may have variable aperture but rarely close down beyond f/8.
In the old days, diffraction was not an issue because very big formats were employed. Lenses available back then were very, very limited in sharpness, well below the theoretical limits. Even today, large-format photography (4x5in or bigger) employs apertures as tight as f/64. Print paper (8x10in or bigger) is used in science-fair shoebox pinhole cameras, whose aperture is around f/300.
Diffraction was taken note of as 35mm film became popular, and better and better lenses were manufactured. Digital photography promoted diffraction to a staple topic of conversation, due to the proliferation of small sensors and the easy magnification of pixels on a computer screen.