Stirling cycle
The Stirling cycle is a thermodynamic cycle that describes the general class of Stirling devices.  This includes the original Stirling engine that was invented, developed and patented in 1816 by Reverend Dr. Robert Stirling with help from his brother, an engineer .
The cycle is reversible, meaning that if supplied with mechanical power, it can function as a heat pump for heating or refrigeration cooling, and even for cryogenic cooling.  The cycle is defined as a closed-cycle regenerative cycle with a gaseous working fluid.  "Closed-cycle" means the working fluid is permanently contained within the thermodynamic system.  This also categorizes the engine device as an external heat engine. "Regenerative" refers to the use of an internal heat exchanger called a regenerator which increases the device's thermal efficiency.
The cycle is the same as most other heat cycles in that there are four main processes: 1.Compression, 2. heat-addition, 3. expansion and 4. heat removal.  However, these processes are not discrete, but rather the transitions overlap.

# Idealized Stirling cycle thermodynamics
The idealized Stirling cycle consists of four thermodynamic processes acting on the working fluid ( See diagram to right):
- Points 1 to 2, Isothermal Expansion.  The expansion-space is heated externally, and the gas undergoes near-isothermal expansion.
- Points 2 to 3, Constant-Volume (known as isovolumetric or isochoric) heat-removal.  The gas is passed through the regenerator, thus cooling the gas, and transferring heat to the regenerator for use in the next cycle.
- Points 3 to 4, Isothermal Compression.  The compression space is intercooled, so the gas undergoes near-isothermal compression.
- Points 4 to 1, Constant-Volume (known as isovolumetric or isochoric) heat-addition.  The compressed air flows back through the regenerator and picks-up heat on the way to the heated expansion space.

# Technical complexity of topic
The Stirling cycle is a highly advanced subject that has defied analysis by many experts for over 190 years.  Highly advanced thermodynamics are required to describe the cycle.  Professor Israel Urieli writes: "...the various 'ideal' cycles (such as the Schmidt cycle) are neither physically realizable nor representative of the Stirling cycle" 
The analytical problem of the regenerator (the central heat exchanger in the Stirling cycle) is judged by Jakob to rank 'among the most difficult and involved that are encountered in engineering '.  

# Piston motion variations
Most thermodynamic textbooks use a highly-simplified form of a Stirling cycle consisting of 4-processes.  This is known as an "ideal Stirling cycle", because it is an "idealized" model, and not necessarily an optimized cycle.  Theoretically, the "ideal cycle" does have high net work output per cycle.   However, it is rarely used in practice, for practical reasons, in part because other cycles are simpler or reduce peak stresses on bearings and/or other components.  For convenience, the designer may elect to use piston motions dictated by system dynamics, such as the mechanical linkage mechanisms.  At any rate, the efficiency and cycle power are nearly as good as an actual implementation of the idealized case.  A typical piston-crank or linkage in a so named "kinematic" design, often results in a near-sinusoidal piston motion.  Some designs will cause the piston to "dwell" at either extreme of travel.
Many kinematic linkages, such as the well known "Ross yoke", will exhibit near-sinusoidal motion.  However, other linkages, such as the "rhombic drive", will exhibit more non-sinusoidal motion.  To a lesser extent, the ideal cycle introduces complications, since to implement the cycle in a real engine would require somewhat higher accelerations of the pistons and higher viscous pumping-losses of the working fluid, although the material stresses and pumping-losses in an optimized engine, would only be intolerable when approaching the "ideal cycle" and/or at high cycle rates.  Other issues include the time required for heat transfer, particularly for the isothermal processes.  In an engine with a cycle approaching the "ideal cycle", the cycle rate might have to be slowed down to address these issues.
In the most basic model of a free piston device, the kinematics will result in simple harmonic motion.

# Volume variations
In beta and gamma engines, generally the phase angle difference between the piston motions is not the same as the phase angle of the volume variations.  However, in the alpha Stirling, they are the same.   The rest of the article assumes sinusoidal volume variations, as in an alpha Stirling with co-linear pistons, so named an "opposed piston" alpha device.

# Pressure-versus-volume graph
This type of plot is used to characterize almost all thermodynamic cycles.  The result of sinusoidal volume variations is the quasi-elliptical shaped cycle shown in Figure 1.  Compared to the idealized cycle, this cycle is a more realistic representation of a most real Stirling engines.  The four points in the graph, label the crank-angle in degrees. 
The real Stirling cycle is similar to the idealized Stirling cycle; however, the four thermodynamic processes are slightly different. ( See graph below ):
- 180 to 270, pseudo-Isothermal Expansion.  The expansion-space is heated externally, and the gas undergoes near-isothermal expansion.
- 270 to 0, near-constant-Volume (or near-isometric or isochoric) heat-removal.  The gas is passed through the regenerator, thus cooling the gas, and transferring heat to the regenerator for use in the next cycle.
- 0 to 90, pseudo-Isothermal Compression.  The compression space is intercooled, so the gas undergoes near-isothermal compression.
- 90 to 180, near-constant-Volume (near-isometric or isochoric) heat-addition.  The compressed air flows back through the regenerator and picks-up heat on the way to the heated expansion space.
With the exception of a Stirling thermoacoustic engine, none of the gas particles actually flows through the complete cycle.  So this approach is not amenable to further analysis of the cycle.  However, it provides an overview and indicates the cycle work.
Figure 1: Pressure vs Volume plot, with four points labeled in crank-angle degrees

# Particle/mass motion
Figure 2, shows the streaklines which indicate how gas flows through a real Stirling engine.  The vertical colored lines, delineate the volume spaces of the engine.  From left-to-right they are: the volume swept by the expansion (power) piston, the clearance volume (which prevents the piston from contacting the hot heat-exchanger), the heater, the regenerator, the cooler, the cooler clearance volume, and the compression volume swept by the compression piston.

# Heat-exchanger pressure-drop
Also referred to as "pumping losses", the pressure drops shown in Figure 3, are caused by viscous flow through the heat exchangers.  The red line represents the heater, green is the regenerator, and blue is the cooler.  To properly design the heat exchangers, multivariate optimization is required to obtain sufficient heat transfer with acceptable flow losses.  The flow losses shown here are relatively low, and they are barely visible in the following image, which will show the overall pressure variations in the cycle.
Figure 3: Heat-exchanger pressure-drop

# Pressure versus crank-angle
Figure 4 shows results from an "adiabatic simulation" with non-ideal heat exchangers.  Note that the pressure-drop across the regenerator is very low compared to the overall pressure variation in the cycle.
Figure 4: Pressure vs crank-angle plot

# Temperature versus crank-angle
Figure 5 illustrates the adiabatic properties of a real heat exchanger.  The straight lines represent the temperatures of the solid portion of the heat exchanger, and the curves are the gas temperatures of the respective spaces.  The gas temperature fluctuations are caused by the effects of compression and expansion in the engine, together with non-ideal heat exchangers which have a limited rate of heat transfer.  When the gas temperature deviates above and below the heat exchanger temperature, it causes thermodynamic losses known as "heat transfer losses" or "hysteresis losses".  However, the heat exchangers still work well enough to allow the real cycle to be effective, even if the actual thermal efficiency of the overall system is only about half of the theoretical limit.
Figure 5: Temperature vs crank-angle plot

# Cumulative heat and work energy
Consider the alpha-type Stirling engine data graphed in figure 6.  The blue dotted-line shows the work output of the compression space.  The trace dips down, and work is done on the gas as it is compressed.  During the expansion process of the cycle, some work is actually done on the compression piston, as reflected by the upward movement of the trace.  At the end of the cycle, this value is negative, indicating that compression requires a net input of work.  The blue solid line shows the heat flowing out of the cooler heat-exchanger.  Notice that the heat from the cooler, and the work from the compression piston both have the same cycle energy!  This is consistent with the zero net heat transfer of the regenerator (solid green line).  As would be expected, the heater and the expansion space both have positive energy flow.  The black dotted-line shows the net work output of the cycle.  This trace ends the cycle higher that it started, indicating that the heat engine converts energy from heat into work.
Figure 6: Heat and work energy vs crank angle