Why Every Developer Needs a Conversion Reference
Unit conversions come up constantly in software development — from calculating viewport dimensions and API rate limits to converting data storage sizes and handling internationalization. Memorizing every formula is impractical. This cheat sheet gives you the exact formulas and reference tables you need, organized by category, so you can look them up in seconds.
Each section includes the exact conversion formula and a quick-reference table for the most common values. Bookmark this page — or better yet, use our online tools linked at the end of the article for instant, accurate conversions.
Length and Distance
Length conversions are among the most frequent in web development (CSS units, responsive breakpoints) and backend work (geolocation, mapping APIs).
Metric ↔ Imperial
# Core formulas
inches = centimeters / 2.54
cm = inches × 2.54
feet = meters × 3.28084
meters = feet / 3.28084
miles = kilometers / 1.60934
km = miles × 1.60934
| From | To | Multiply by | Common Example |
|---|---|---|---|
| 1 inch | cm | 2.54 | 8.5″ × 2.54 = 21.59 cm (A4 width) |
| 1 cm | inches | 0.393701 | 30 cm ≈ 11.81″ |
| 1 foot | meters | 0.3048 | 6 ft = 1.83 m |
| 1 meter | feet | 3.28084 | 100 m ≈ 328 ft |
| 1 mile | km | 1.60934 | Marathon = 42.195 km ≈ 26.2 mi |
| 1 km | miles | 0.621371 | 5 km ≈ 3.11 mi |
CSS / Screen Units
For web development, these conversions are especially handy when working with design handoffs from Figma or Sketch (which use pixels) and translating them to responsive units:
| Conversion | Formula | Note |
|---|---|---|
| px → rem | px / 16 | Assumes 1rem = 16px (browser default) |
| px → em | px / parentFontSize | em is relative to the parent element |
| rem → px | rem × 16 | 1rem = root font size (usually 16px) |
| vw (viewport width) | (px / viewportWidth) × 100 | e.g. 1200px viewport: 600px = 50vw |
Weight and Mass
Weight conversions matter in e-commerce (product specs), health/fitness APIs, and scientific computing. Note the distinction: mass (kg, lb) measures matter; weight is mass × gravity.
# Core formulas
pounds = kilograms × 2.20462
kg = pounds / 2.20462
ounces = grams / 28.3495
grams = ounces × 28.3495
| From | To | Multiply by | Common Example |
|---|---|---|---|
| 1 kg | lb | 2.20462 | 70 kg ≈ 154.3 lb |
| 1 lb | kg | 0.453592 | 150 lb ≈ 68.0 kg |
| 1 g | oz | 0.035274 | 500 g ≈ 17.6 oz |
| 1 oz | g | 28.3495 | 16 oz (1 lb) = 453.6 g |
| 1 kg | stones (UK) | 0.157473 | 70 kg ≈ 11.0 stones |
| 1 metric ton | kg | 1000 | 1 t = 1000 kg |
Temperature
Temperature is the one category where the formula is not a simple multiplication — it involves both scaling and offset. This trips up many developers.
# Exact formulas
celsius = (fahrenheit - 32) × 5/9
fahrenheit = celsius × 9/5 + 32
celsius = kelvin - 273.15
kelvin = celsius + 273.15
# JavaScript quick functions
const fToC = (f) => Math.round(((f - 32) * 5/9) * 10) / 10;
const cToF = (c) => Math.round((c * 9/5 + 32) * 10) / 10;
| °C | °F | K | Context |
|---|---|---|---|
| -40 | -40 | 233.15 | Only temperature where °C = °F |
| -18 | 0 | 255.15 | 0°F — very cold day |
| 0 | 32 | 273.15 | Water freezes |
| 20 | 68 | 293.15 | Room temperature |
| 37 | 98.6 | 310.15 | Human body temperature |
| 100 | 212 | 373.15 | Water boils |
Data Storage Units
Data storage is measured in powers of 2 (binary) in some contexts and powers of 10 (decimal) in others. This distinction is a common source of confusion — hard drive manufacturers use decimal (1 GB = 10⁹ bytes), while operating systems and RAM use binary (1 GiB = 2³⁰ bytes).
# Binary (IEC standard, used by OS/memory)
1 KiB = 1,024 bytes (kibibyte)
1 MiB = 1,024 KiB (mebibyte)
1 GiB = 1,024 MiB (gibibyte)
1 TiB = 1,024 GiB (tebibyte)
# Decimal (SI standard, used by drive manufacturers)
1 KB = 1,000 bytes (kilobyte)
1 MB = 1,000 KB (megabyte)
1 GB = 1,000 MB (gigabyte)
1 TB = 1,000 GB (terabyte)
# Why your 500 GB drive shows ~465 GiB in Windows:
500 × 10⁹ / 2³⁰ ≈ 465.66 GiB
| Unit (binary) | Bytes | Unit (decimal) | Bytes |
|---|---|---|---|
| 1 KiB | 1,024 | 1 KB | 1,000 |
| 1 MiB | 1,048,576 | 1 MB | 1,000,000 |
| 1 GiB | 1,073,741,824 | 1 GB | 1,000,000,000 |
| 1 TiB | 1,099,511,627,776 | 1 TB | 1,000,000,000,000 |
Time Units
Time conversions are straightforward in principle, but watch out for months (variable length) and leap years when doing date arithmetic in code. Always prefer built-in libraries (like dayjs, date-fns, or Python's datetime) over hand-rolled formulas.
# Exact relationships
1 minute = 60 seconds
1 hour = 3,600 seconds = 60 minutes
1 day = 86,400 seconds = 24 hours
1 week = 604,800 seconds = 7 days
1 year = 31,536,000 seconds (365 days)
1 year = 31,622,400 seconds (366 days, leap year)
# Unix timestamp (seconds since Jan 1 1970)
timestamp = Date.now() / 1000 # JavaScript: ms → seconds
datetime.fromtimestamp(ts) # Python: seconds → datetime
| Duration | In Seconds | In Common Units |
|---|---|---|
| 1 minute | 60 | 60 s |
| 1 hour | 3,600 | 60 min |
| 1 day | 86,400 | 24 hr |
| 1 week | 604,800 | 7 days |
| 1 month (avg) | 2,629,746 | ~30.44 days |
| 1 year (non-leap) | 31,536,000 | 365 days |
| 1 year (leap) | 31,622,400 | 366 days |
Speed and Rate Conversions
Speed conversions are common in performance monitoring (requests per second), networking (Mbps), and geospatial applications (km/h, mph, knots).
# Common speed conversions
mps = kmph / 3.6 # meters per second ← km per hour
kmph = mps × 3.6 # km per hour ← meters per second
mph = kmph / 1.60934 # miles per hour ← km per hour
knots = kmph / 1.852 # nautical miles per hour
# Network speed: bits vs bytes
1 Mbps = 1,000,000 bits/s (decimal, network marketing)
1 MB/s = 8,000,000 bits/s (8 bits per byte)
# So a "100 Mbps" connection downloads at ~12.5 MB/s in theory
| From | To | Factor | Example |
|---|---|---|---|
| 1 m/s | km/h | × 3.6 | 10 m/s = 36 km/h |
| 1 km/h | mph | × 0.621371 | 100 km/h ≈ 62.1 mph |
| 1 mph | km/h | × 1.60934 | 60 mph ≈ 96.6 km/h |
| 1 knot | km/h | × 1.852 | 1 knot = 1.852 km/h |
| 1 Mbps | MB/s | / 8 | 100 Mbps ≈ 12.5 MB/s |
Conclusion
Unit conversions are a fact of life in software development. Whether you are building a responsive layout, processing sensor data, calculating file sizes, or working with international users, having these formulas at your fingertips saves time and prevents bugs. Bookmark this cheat sheet for quick reference, and for instant, accurate conversions without manual math, try our universal unit converter and number base converter — both support all the categories covered in this guide and more.