Gear design in machine design class usually means one long hand calculation per trial: pick a module, find the load, check bending, check pitting, and start again if it fails. In Python the same checks become a small function you can run for every standard module in one go. In this tutorial we build a spur gear design calculator in Python that finds the bending stress (Lewis equation) and the contact stress (Hertz) on the pinion, and then picks the smallest module that passes both.
Quick answer: Bending stress on a spur gear tooth is σb = KvFt / (b·m·Y) (Lewis), and contact stress is σc = Cp√[KvFt/(b·cos φ)·(1/r1 + 1/r2)] (Hertz), with Ft = P/v. In Python, write both as one function of the module and loop over standard modules. For a 10 kW, 1440 rpm, 20/60-tooth steel pair with 40 mm face width, a 4 mm module gives 64.0 MPa bending and 546.8 MPa contact stress.
The Problem
- Power P = 10 kW at pinion speed n1 = 1440 rpm
- Pinion z1 = 20 teeth, gear z2 = 60 teeth (ratio 3:1)
- 20° full-depth involute teeth, face width b = 40 mm, cut or milled profile
- Both gears in steel: E = 200 GPa, ν = 0.3
- Assumed allowable stresses for this example: 150 MPa bending, 600 MPa contact
We want the bending and contact stress on the pinion for a 4 mm module, and the smallest standard module that is safe on both counts.
Step 1: The Theory
The pitch diameter is d = m·z, so with m = 4 mm the pinion is 80 mm and the gear 240 mm. The pitch-line velocity is v = πd1n1/60 = 6.03 m/s, and the tangential load that transmits the power is Ft = P/v = 1658 N.
Bending (Lewis): the tooth is treated as a cantilever loaded at its tip. The Lewis form factor Y captures the tooth shape; for 20 teeth Y = 0.322. The velocity factor for cut teeth, Kv = (6.1 + v)/6.1 = 1.989, increases the load for dynamic effects. So σb = 1.989 × 1658 / (0.040 × 0.004 × 0.322) = 64.0 MPa.
Contact (Hertz): the two teeth touch like two cylinders whose radii are the radii of curvature at the pitch point, r = (d sin φ)/2. For two steel gears the elastic coefficient is Cp = √[1 / (π·2(1 − ν²)/E)] = 187 √MPa. Putting the numbers in gives σc = 546.8 MPa.
Step 2: The Python Code
You need Python with NumPy and Matplotlib (pip install numpy matplotlib). The Lewis form factor is taken from the standard table for 20° full-depth teeth and interpolated with np.interp, so any tooth count works. The function gear_stresses() does the full check for one module, and the loop at the end tries every standard module.
import numpy as np
import matplotlib.pyplot as plt
# ---- Input data ----
P = 10e3 # power, W
n1 = 1440 # pinion speed, rpm
z1, z2 = 20, 60 # teeth on pinion and gear (ratio 3:1)
b = 40e-3 # face width, m
phi = np.radians(20) # pressure angle (20 deg full depth)
E, nu = 200e9, 0.3 # steel pinion and gear
# Assumed allowable stresses for this example (through-hardened steel)
sigma_b_allow = 150e6 # bending, Pa
sigma_c_allow = 600e6 # contact, Pa
# Lewis form factor Y for 20 deg full-depth teeth (standard table values)
Z_TAB = [12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 26, 28, 30,
34, 38, 43, 50, 60, 75, 100, 150, 300, 400]
Y_TAB = [0.245, 0.261, 0.277, 0.290, 0.296, 0.303, 0.309, 0.314, 0.322,
0.328, 0.331, 0.337, 0.346, 0.353, 0.359, 0.371, 0.384, 0.397,
0.409, 0.422, 0.435, 0.447, 0.460, 0.472, 0.480]
def lewis_Y(z):
return np.interp(z, Z_TAB, Y_TAB)
# Elastic coefficient Cp for two steel gears, sqrt(Pa)
Cp = np.sqrt(1 / (np.pi * 2 * (1 - nu**2) / E))
def gear_stresses(m):
"""Bending (Lewis) and contact (Hertz) stress on the pinion for module m (m)."""
d1, d2 = m * z1, m * z2 # pitch diameters, m
v = np.pi * d1 * n1 / 60 # pitch-line velocity, m/s
Ft = P / v # tangential (transmitted) load, N
Kv = (6.1 + v) / 6.1 # velocity factor, cut or milled teeth
sigma_b = Kv * Ft / (b * m * lewis_Y(z1))
r1, r2 = d1 * np.sin(phi) / 2, d2 * np.sin(phi) / 2 # radii of curvature
sigma_c = Cp * np.sqrt(Kv * Ft / (b * np.cos(phi)) * (1 / r1 + 1 / r2))
return dict(d1=d1, v=v, Ft=Ft, Kv=Kv, sigma_b=sigma_b, sigma_c=sigma_c)
# ---- Single design check: module 4 mm ----
r = gear_stresses(4e-3)
print(f"Elastic coefficient Cp = {Cp/1e3:.1f} sqrt(MPa)")
print(f"Pitch diameter d1 = {r['d1']*1000:.0f} mm, velocity v = {r['v']:.2f} m/s")
print(f"Tangential load Ft = {r['Ft']:.0f} N, velocity factor Kv = {r['Kv']:.3f}")
print(f"Lewis form factor Y = {lewis_Y(z1):.3f}")
print(f"Bending stress = {r['sigma_b']/1e6:.1f} MPa (FoS = {sigma_b_allow/r['sigma_b']:.2f})")
print(f"Contact stress = {r['sigma_c']/1e6:.1f} MPa (FoS = {sigma_c_allow/r['sigma_c']:.2f})")
# ---- Design loop: smallest standard module that passes both checks ----
modules = np.array([2, 2.5, 3, 4, 5, 6]) # standard modules, mm
sb, sc = [], []
print("\nModule Bending Contact Result")
for m in modules:
s = gear_stresses(m / 1000)
sb.append(s["sigma_b"] / 1e6); sc.append(s["sigma_c"] / 1e6)
ok = s["sigma_b"] <= sigma_b_allow and s["sigma_c"] <= sigma_c_allow
print(f"{m:4.1f} mm {sb[-1]:7.1f} {sc[-1]:8.1f} {'OK' if ok else 'FAIL'}")
fig, ax = plt.subplots(figsize=(8, 5))
ax.plot(modules, sb, "o-", label="Bending stress (Lewis)")
ax.plot(modules, sc, "s-", label="Contact stress (Hertz)")
ax.axhline(sigma_b_allow / 1e6, ls="--", c="C0", label="Allowable bending 150 MPa")
ax.axhline(sigma_c_allow / 1e6, ls="--", c="C1", label="Allowable contact 600 MPa")
ax.set_xlabel("Module, m (mm)")
ax.set_ylabel("Stress (MPa)")
ax.set_title("Spur gear pinion: stress vs module (10 kW, 1440 rpm, b = 40 mm)")
ax.grid(True, alpha=0.3)
ax.legend()
plt.tight_layout()
plt.savefig("gear_stress_vs_module.png", dpi=150)
plt.show()
Step 3: The Results
Running the script prints:
Elastic coefficient Cp = 187.0 sqrt(MPa)
Pitch diameter d1 = 80 mm, velocity v = 6.03 m/s
Tangential load Ft = 1658 N, velocity factor Kv = 1.989
Lewis form factor Y = 0.322
Bending stress = 64.0 MPa (FoS = 2.34)
Contact stress = 546.8 MPa (FoS = 1.10)
Module Bending Contact Result
2.0 mm 192.4 948.1 FAIL
2.5 mm 133.3 789.2 FAIL
3.0 mm 99.6 682.3 FAIL
4.0 mm 64.0 546.8 OK
5.0 mm 46.1 463.9 OK
6.0 mm 35.5 407.4 OK
The 4 mm result matches the hand calculation in Step 1 exactly. The graph shows how both stresses fall as the module grows:

What the Graph Tells You
- Contact stress decides the size here. Bending alone would pass from 2.5 mm, but contact stress stays above 600 MPa until the module reaches 4 mm.
- Bending stress falls fast with module (192 → 36 MPa), because a bigger module gives a bigger pitch diameter (lower load) and a thicker tooth at the same time.
- Contact stress falls more slowly (948 → 407 MPa), because it varies with the square root of the load.
- The factor of safety at 4 mm is 2.34 in bending but only 1.10 in contact. To get more margin on pitting, use a harder material or a wider face rather than a bigger module.
Common Mistakes
- Module in mm inside SI formulas – keep the module in metres (0.004, not 4) when stress is in Pa.
- Using the gear’s form factor for the pinion – the pinion has fewer teeth, a smaller Y and higher bending stress, so check it first.
- Forgetting the velocity factor – without Kv the bending stress here would be about half the real value, and the contact stress about 30 % low.
- Checking only bending – as this example shows, a gear that is safe in bending can still fail by pitting.
Try It Yourself: Extend the Code
- Add a loop over face width and plot the lightest safe combination of module and face width.
- Check the gear as well as the pinion, and add a different material for each.
- Extend it to helical gears using the virtual number of teeth z/cos³ψ.
- Add the full set of rating factors from a gear design standard (overload, size, load distribution).
- Compare the Python stresses with an FEA model of one tooth under the same load.
Steps 3 to 5 together make a good Python-based machine design project. For more gear topics see our gear design projects, such as the high-speed helical gear design and analysis and the three-stage planetary gearbox. Preparing for a viva? Read our machine design viva questions.
More Python for Engineers tutorials: beam deflection in Python, Otto vs Diesel cycle in Python, heat exchanger design in Python (LMTD method) and how to plot CFD and FEA results with Python Matplotlib.
Also try: vibration analysis in Python with FFT.
Learn Python for Mechanical Engineering
This tutorial is part of how we teach Python to mechanical students – through machine design problems you already know, not abstract examples. In our Python for mechanical engineers classes you learn NumPy, Matplotlib and data handling step by step, in live screen-share sessions or recorded videos, and write the code yourself.
Frequently Asked Questions
What is the Lewis equation for gear tooth bending stress?
The Lewis equation treats a gear tooth as a cantilever beam: σ = Ft/(b·m·Y), where Ft is the tangential load, b the face width, m the module and Y the Lewis form factor, which depends on the number of teeth and the tooth profile. A velocity factor Kv is multiplied with Ft to allow for dynamic load.
Why is contact stress usually higher than bending stress in gears?
Contact stress comes from two curved surfaces pressed together over a very small area, so it is much higher than the bending stress at the tooth root. That is why surface pitting often decides the gear size, as in this example where the contact check needs a 4 mm module while bending alone would allow 2.5 mm.
How do I choose the module of a spur gear?
Start with the power, speed, number of teeth and material. Calculate bending and contact stress for a list of standard modules and pick the smallest module where both stresses are below the allowable values with a suitable factor of safety. The Python loop in this tutorial does exactly that.
What is the Lewis form factor for a 20-tooth gear?
For a 20° full-depth involute tooth, the Lewis form factor for 20 teeth is 0.322. It increases with the number of teeth, from 0.245 at 12 teeth to about 0.48 for very large gears, because the tooth becomes wider at the root.
Is a gear design calculator a good final year project?
A basic stress calculator is a small exercise. Extended to helical gears, full standard-based rating factors, automatic material selection and a check against an FEA model of the tooth, it becomes a strong Python-based machine design project.
Start Learning
Tell us your branch and what you want to build. Message us on WhatsApp or use the enquiry form on our home page.
Interested in this project? Get the details, files and guidance from our team.
Enquire on WhatsApp