Integer Types and Their Ranges
Understand Int, UInt, Int8..Int64 and their bounds.
Integer Types and Their Ranges is a free Swift Academy lesson on CoddyKit — lesson 1 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Swift Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Integer Types in Swift
Swift has several integer types. Int is the default and matches the platform word size (usually 64-bit). There are also fixed-width types like Int8, Int16, Int32, and Int64.
let count: Int = 42
print(count)
print(type(of: count))Signed vs Unsigned
Signed types (Int) can hold negative and positive values. Unsigned types (UInt) hold only zero and positive values, gaining a larger positive range.
let signed: Int = -10
let unsigned: UInt = 10
print(signed, unsigned)Fixed-Width Integer Sizes
The number in the type name is the bit width. Int8 uses 8 bits, Int16 uses 16, and so on. More bits means a wider range.
print(MemoryLayout<Int8>.size)
print(MemoryLayout<Int16>.size)
print(MemoryLayout<Int64>.size)The min and max Properties
Every integer type exposes .min and .max giving its smallest and largest representable value.
print(Int8.min, Int8.max)
print(UInt8.min, UInt8.max)Bounds of Int8
A signed Int8 ranges from -128 to 127. The asymmetry comes from reserving one value for zero on the non-negative side.
print("Int8 range:", Int8.min, "to", Int8.max)Bounds of UInt8
An unsigned UInt8 ranges from 0 to 255. With no sign bit needed, all 8 bits represent magnitude.
print("UInt8 range:", UInt8.min, "to", UInt8.max)Larger Integer Ranges
Int16, Int32, and Int64 grow exponentially in range. Int32 already exceeds two billion in magnitude.
print("Int16 max:", Int16.max)
print("Int32 max:", Int32.max)
print("Int64 max:", Int64.max)The Platform Int
On 64-bit platforms, Int is identical to Int64. Prefer plain Int for general code unless you specifically need a fixed width.
print("Int.max:", Int.max)
print("Same as Int64:", Int.max == Int64.max)Choosing an Integer Type
Use Int by default. Reach for fixed-width types when interfacing with binary formats, hardware, or memory-sensitive data.
let pixelChannel: UInt8 = 200
let fileOffset: Int64 = 5_000_000_000
print(pixelChannel, fileOffset)Detecting Range with min and max
You can use .min and .max at runtime to validate that a value fits a target type before converting.
let big = 300
let fits = big >= Int(UInt8.min) && big <= Int(UInt8.max)
print("Fits in UInt8:", fits)Integer Spacing Recap Example
Each extra bit roughly doubles the range. This program shows the maximum of progressively wider unsigned types.
print(UInt8.max)
print(UInt16.max)
print(UInt32.max)Quick Check
Recall the exact range of a signed 8-bit integer.
Recap: Integer Types and Ranges
You learned that Int is the platform-sized default, that signed types span negatives while unsigned (UInt) start at zero, and that fixed-width types Int8 to Int64 have specific .min/.max bounds growing with bit width.
print("Defaults and bounds:")
print(Int.max)
print(Int8.min, Int8.max)
print(UInt8.max)Frequently asked questions
Is the “Integer Types and Their Ranges” lesson free?
Yes — the full text of “Integer Types and Their Ranges” is free to read here on the web, and the Swift Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Swift Academy course, upgrade to CoddyKit PRO.
What will I learn in “Integer Types and Their Ranges”?
Understand Int, UInt, Int8..Int64 and their bounds. You practise Swift Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Swift Academy?
No prior experience is required. Swift Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 1 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Integer Types and Their Ranges” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Swift Academy lesson?
Yes. Every Swift Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Integer Types and Their Ranges
- Floating-Point: Double vs Float
- Explicit Numeric Conversions
- Numeric Literals and Underscores