converter reference

Unit Conversion Cheat Sheet: Essential Conversions for Developers

UseEasyTool Team Developer Tools Experts
April 15, 2024 5 min read

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
FromToMultiply byCommon Example
1 inchcm2.548.5″ × 2.54 = 21.59 cm (A4 width)
1 cminches0.39370130 cm ≈ 11.81″
1 footmeters0.30486 ft = 1.83 m
1 meterfeet3.28084100 m ≈ 328 ft
1 milekm1.60934Marathon = 42.195 km ≈ 26.2 mi
1 kmmiles0.6213715 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:

ConversionFormulaNote
px → rempx / 16Assumes 1rem = 16px (browser default)
px → empx / parentFontSizeem is relative to the parent element
rem → pxrem × 161rem = root font size (usually 16px)
vw (viewport width)(px / viewportWidth) × 100e.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
FromToMultiply byCommon Example
1 kglb2.2046270 kg ≈ 154.3 lb
1 lbkg0.453592150 lb ≈ 68.0 kg
1 goz0.035274500 g ≈ 17.6 oz
1 ozg28.349516 oz (1 lb) = 453.6 g
1 kgstones (UK)0.15747370 kg ≈ 11.0 stones
1 metric tonkg10001 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°FKContext
-40-40233.15Only temperature where °C = °F
-180255.150°F — very cold day
032273.15Water freezes
2068293.15Room temperature
3798.6310.15Human body temperature
100212373.15Water 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)BytesUnit (decimal)Bytes
1 KiB1,0241 KB1,000
1 MiB1,048,5761 MB1,000,000
1 GiB1,073,741,8241 GB1,000,000,000
1 TiB1,099,511,627,7761 TB1,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
DurationIn SecondsIn Common Units
1 minute6060 s
1 hour3,60060 min
1 day86,40024 hr
1 week604,8007 days
1 month (avg)2,629,746~30.44 days
1 year (non-leap)31,536,000365 days
1 year (leap)31,622,400366 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
FromToFactorExample
1 m/skm/h× 3.610 m/s = 36 km/h
1 km/hmph× 0.621371100 km/h ≈ 62.1 mph
1 mphkm/h× 1.6093460 mph ≈ 96.6 km/h
1 knotkm/h× 1.8521 knot = 1.852 km/h
1 MbpsMB/s/ 8100 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.

Related Articles

Image Compression Tips

Reduce file sizes without losing quality — learn about formats, lossy vs lossless, and automation.

Regex Beginner Tutorial

Master regular expressions from scratch with practical examples and code snippets.

View All Articles

Browse our complete collection of developer tutorials, guides, and tips.