Skip to article
Image Aspect Ratio

PIXEL MATH

Exact fractions vs rounded pixels: why 1366 × 768 isn't 16:9

1366 × 768 reduces to 683:384, not 16:9. Exact 16:9 at 1366 px wide would need a height of 768.375 px, and at 768 px tall a width of 1365⅓ px. Neither is a whole pixel, so the screen is close to 16:9 but not equal to it.

Updated

The distinction matters when you calculate sizes: the ratio can be exact even when the required dimension falls between whole pixels. The examples below assume positive whole-pixel dimensions and, where noted, a ratio reduced to lowest terms. Values marked ≈ are rounded for display.

Two orange rectangles that look identical: 1920 × 1080, labelled 16:9 exact, and 1366 × 768, labelled 683:384 near 16:9. Below them, 1366 ÷ 2 : 768 ÷ 2 = 683:384.
Schematic illustration: at this size the two shapes look the same, but only one is exactly 16:9. The table below gives the exact reductions. Open full-size image (opens in a new tab)

Reduce with the GCD

Divide width and height by their greatest common divisor (GCD). For the basics, see What is aspect ratio?.

// Assumes positive integers.
function gcd(a, b) {
  while (b !== 0) [a, b] = [b, a % b];
  return a;
}

function reduceRatio(width, height) {
  const g = gcd(width, height);
  return [width / g, height / g]; // exact: g divides both
}

reduceRatio(1920, 1080); // [16, 9]    (GCD 120)
reduceRatio(1366, 768);  // [683, 384] (GCD 2)
Screen sizes with their GCD, reduced ratio and decimal width-to-height value
SizeGCDReduced ratioWidth ÷ height
1920 × 108012016:9≈ 1.7778
1366 × 7682683:384≈ 1.7786
1360 × 7681685:48≈ 1.7708
1440 × 9001808:51.6
3440 × 14408043:18≈ 2.3889

The 1366 × 768 shape differs from 16:9 by about 0.05%. The difference is small, but the dimensions fail a ratio === 16 / 9 check or a preset lookup by reduced ratio. Ultrawide labels work the same way: 3440 × 1440 is sold as "21:9" but reduces to 43:18. The ultrawide calculator uses actual monitor resolutions instead of marketing labels.

Don't store a ratio as a rounded decimal. With 1.78 for 16:9, 1920 / 1.78 is ≈ 1078.65, which rounds to 1079 instead of 1080. 1920 * 9 / 16 gives 1080. Keep both integers and divide last.

Scaling to a target ratio

For a target ratio W:H, height = width × H ÷ W. The result is a whole number only when width × H is divisible by W. For a reduced ratio, that means the width must be a multiple of W.

Test that with integer arithmetic rather than by inspecting a floating-point quotient:

// Assumes positive integers and a reduced ratio. width, rh, rw and the
// product width * rh must all be <= Number.MAX_SAFE_INTEGER.
function heightFor(width, [rw, rh], mode = "round") {
  const product = width * rh;
  return {
    isWhole: product % rw === 0,   // exact integer test
    approx: product / rw,          // floating-point result
    px: Math[mode](product / rw),
  };
}

heightFor(1200, [16, 9]); // { isWhole: true,  approx: 675,      px: 675 }
heightFor(1001, [16, 9]); // { isWhole: false, approx: 563.0625, px: 563 }

If the inputs and every intermediate product stay within Number.MAX_SAFE_INTEGER, the multiplication and % are exact. The division may not be: 16000 ÷ 9 = 1777.777… has no finite binary form, so 16000 / 9 returns the nearest double. BigInt removes the size limit, but its division truncates (16000n / 9n is 1777n), so you still need to store a non-integer result as a numerator/denominator pair. The site's calculator does this.

In the table below, shape error = ((width ÷ rounded height) ÷ (W ÷ H) − 1) × 100%.

Widths scaled to a target ratio with exact height, rounded height, resulting ratio and shape error
WidthTargetExact heightRoundedResulting ratioShape error
120016:967567516:90
100116:99009/16 = 563.06255631001:563≈ +0.011%
10009:1616000/9 ≈ 1777.781778500:889≈ −0.012%
10814:55405/4 = 1351.2513511081:1351≈ +0.019%
344021:910320/7 ≈ 1474.2914741720:737≈ +0.019%

The errors are tiny, but a rounded size is no longer W:H: 1001 × 563 reduces to 1001:563. If you need sizes that are exactly W:H, use multiples of the reduced pair instead. Between 1000 and 1100 px wide, only 1008, 1024, 1040, 1056, 1072 and 1088 give a whole-pixel 16:9 height.

A number line from 563 to 564 marking 1001 × 9 ÷ 16 = 563.0625 just past 563, with an arrow rounding it down to 563. Side by side: the exact size 1001 × 563.0625 is 16:9; the whole-pixel size 1001 × 563 is 1001:563.
Schematic illustration of rounding one exact height to a whole pixel. The table above gives the exact heights and resulting ratios. Open full-size image (opens in a new tab)

Rounding also compounds. Scale 1920 × 1080 to 333 px wide and the height is 187.3125, which rounds to 187. Scale 333 × 187 back to 1920 wide and the height is ≈ 1078.2, which rounds to 1078. Always scale from the original dimensions or the reduced ratio.

Decimal ratios such as 2.39:1 and 1.85:1 are exact as written, but a JavaScript number usually can't store them exactly. Convert them to integer pairs (239:100, 37:20) and reduce those.

round, floor or ceil?

Choose the direction from the layout constraint:

When to use Math.round, Math.floor or Math.ceil, with examples
MethodUse whenExample
Math.roundYou want the closest shape16:9 at 1001 wide: 563.0625 → 563
Math.floorThe result must fit inside a source, container or maximum9:16 crop from 1920 × 1080: 607.5 → 607 wide
Math.ceilThe result must cover an area or meet a minimum4:5 at 1081 wide, minimum height: 1351.25 → 1352

Centring can leave half a pixel over. A 607 px crop centred in 1920 px needs an offset of (1920 − 607) ÷ 2 = 656.5. Flooring it puts the extra pixel on one side. Also note that Math.round(-2.5) is -2, because halves round toward +∞. That matters for offsets that can go negative.

Crops: 4:5 and 9:16

1080 × 1350 (4:5) and 1080 × 1920 (9:16) are common portrait export sizes. Check the destination's current requirements before exporting. Crops to those ratios from typical sources often aren't whole pixels:

Largest crops at 4:5 and 9:16 from common source sizes: exact, floored and largest whole-pixel exact crop
SourceTargetLargest crop (exact)After floorLargest whole-pixel crop at exact ratio
6000 × 40004:53200 × 40003200 × 40003200 × 4000
4032 × 30244:52419.2 × 30242419 × 30242416 × 3020
1920 × 10809:16607.5 × 1080607 × 1080603 × 1072

The last column uses the largest whole number k for which W × k by H × k fits in the source:

// Assumes positive integers and a reduced ratio.
function largestExactCrop(srcW, srcH, [rw, rh]) {
  const k = Math.min(Math.floor(srcW / rw), Math.floor(srcH / rh));
  return k > 0 ? [rw * k, rh * k] : null; // null: source smaller than rw × rh
}

largestExactCrop(1920, 1080, [9, 16]); // [603, 1072]
largestExactCrop(4032, 3024, [4, 5]);  // [2416, 3020]
largestExactCrop(400, 300, [683, 384]); // null

If the source is narrower than W or shorter than H, k is 0 and no positive whole-pixel crop at the exact ratio fits. A rounded crop is an option if a small ratio difference is acceptable. For a 12 MP photo, 2419 × 3024 is slightly off 4:5, while 2416 × 3020 is exact. If you resize to 1080 × 1350 afterwards, either works. If later code checks the ratio exactly, use the exact crop.

The same fractions show how much of a 16:9 image survives in a portrait or square frame. With Fit, the image covers 9/16 = 56.25% of a 1:1 frame, 9/20 = 45% of a 4:5 frame and 81/256 ≈ 31.64% of a 9:16 frame. With Fill, the same share of the image remains visible. In both cases the share is the smaller ratio divided by the larger.

A 16:9 landscape scene shown three ways: the source; Fit in a 9:16 frame, with the whole scene in a band across the middle and empty space above and below; and Fill in a 9:16 frame, with the scene enlarged to cover the frame and its sides cropped.
Schematic illustration of Fit and Fill in a 9:16 frame; proportions are approximate. The exact share is 81/256 ≈ 31.64%, as calculated above. Open full-size image (opens in a new tab)

CSS: let the browser keep the fraction

CSS aspect-ratio sets a preferred ratio. It applies only when at least one dimension is automatic, so if you set both width and height, those win. Content size and minimum-size constraints can also make the box differ from the preferred ratio.

It accepts unreduced pairs, so you can use real dimensions:

.video { width: 100%; aspect-ratio: 16 / 9; }
.panel { width: 100%; aspect-ratio: 1366 / 768; } /* the real shape */
.thumb { width: 270px; aspect-ratio: 4 / 5; }     /* 337.5px tall */

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;   /* Fill: cover the box, crop the overflow */
}
.preview img { object-fit: contain; } /* Fit: whole image, with bars */

The browser lays out fractional sizes such as 337.5px and snaps to device pixels when it paints. Rounding in JavaScript first throws that precision away.

Give each <img> width and height attributes equal to its actual pixel dimensions, for example width="4032" height="3024". If CSS leaves the height automatic (height: auto), the browser reserves space at the right ratio before the image loads. The video page shows how contain produces letterboxing or pillarboxing.

Checking dimensions with the calculator

The aspect ratio calculator uses exact fractions:

  • Calculate size finds the missing dimension and says whether the result is whole pixels or rounded to the nearest pixel (halves round up). Precision detail shows the exact value.
  • Aspect ratio reduces a width and height. A "Near" label means the size is close to a common ratio, not an exact match.
  • Resize keeps the original ratio for a new width or height.

The image aspect ratio checker reads a local JPG, PNG, WebP, GIF or AVIF file in your browser and shows its reduced ratio. It previews Fit and Fill in 1:1, 4:5, 9:16 and 16:9 frames. These are visual previews; the tool doesn't crop, resize or export files.

Check your own dimensions.